How to use the io-ts-types/lib/optionFromNullable.optionFromNullable function in io-ts-types

To help you get started, we’ve selected a few io-ts-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devexperts / swagger-codegen-ts / src / schema / asyncapi-2.0.0 / websockets-channel-binding-object.ts View on Github external
import { literal, string, type, union } from 'io-ts';
import { optionFromNullable } from 'io-ts-types/lib/optionFromNullable';

export interface WebsocketsChannelBindingObject {
	readonly method: Option<'GET' | 'POST'>;
	readonly query: Option;
	readonly headers: Option;
	readonly bindingVersion: Option;
}

export const WebsocketsChannelBindingObjectCodec: Codec = type(
	{
		method: optionFromNullable(union([literal('GET'), literal('POST')])),
		query: optionFromNullable(ObjectSchemaObjectCodec),
		headers: optionFromNullable(ObjectSchemaObjectCodec),
		bindingVersion: optionFromNullable(string),
	},
	'WebsocketsChannelBindingObject',
);
github devexperts / swagger-codegen-ts / src / schema / 2.0 / path-item-object.ts View on Github external
readonly $ref: Option;
	readonly get: Option;
	readonly put: Option;
	readonly post: Option;
	readonly delete: Option;
	readonly options: Option;
	readonly head: Option;
	readonly patch: Option;
	readonly parameters: Option>;
}

export const PathItemObjectCodec = type(
	{
		$ref: stringOption,
		get: optionFromNullable(OperationObject),
		put: optionFromNullable(OperationObject),
		post: optionFromNullable(OperationObject),
		delete: optionFromNullable(OperationObject),
		options: optionFromNullable(OperationObject),
		head: optionFromNullable(OperationObject),
		patch: optionFromNullable(OperationObject),
		parameters: optionFromNullable(array(union([ReferenceObjectCodec, ParameterObjectCodec]))),
	},
	'PathItemObject',
);
github devexperts / swagger-codegen-ts / src / schema / 2.0 / path-item-object.ts View on Github external
readonly options: Option;
	readonly head: Option;
	readonly patch: Option;
	readonly parameters: Option>;
}

export const PathItemObjectCodec = type(
	{
		$ref: stringOption,
		get: optionFromNullable(OperationObject),
		put: optionFromNullable(OperationObject),
		post: optionFromNullable(OperationObject),
		delete: optionFromNullable(OperationObject),
		options: optionFromNullable(OperationObject),
		head: optionFromNullable(OperationObject),
		patch: optionFromNullable(OperationObject),
		parameters: optionFromNullable(array(union([ReferenceObjectCodec, ParameterObjectCodec]))),
	},
	'PathItemObject',
);
github devexperts / swagger-codegen-ts / src / schema / 3.0 / parameter-object.ts View on Github external
in: literal('query'),
		required: optionFromNullable(boolean),
	},
	'QueryParameterObject',
);

export interface CookieParameterObject extends BaseParameterObject {
	readonly in: 'cookie';
	readonly required: Option;
}

const CookieParameterObjectCodec: Codec = type(
	{
		...BaseParameterObjectCodecProps,
		in: literal('cookie'),
		required: optionFromNullable(boolean),
	},
	'CookieParameterObject',
);

export type ParameterObject =
	| PathParameterObject
	| HeaderParameterObject
	| QueryParameterObject
	| CookieParameterObject;

export const ParameterObjectCodec: Codec = union(
	[PathParameterObjectCodec, HeaderParameterObjectCodec, QueryParameterObjectCodec, CookieParameterObjectCodec],
	'ParameterObject',
);
github devexperts / swagger-codegen-ts / src / schema / 3.0 / schema-object.ts View on Github external
export const ObjectSchemaObjectCodec: Codec = recursion('ObjectSchemaObject', () =>
	intersection([
		BaseSchemaObjectCodec,
		type({
			type: literal('object'),
			properties: optionFromNullable(record(string, union([ReferenceObjectCodec, SchemaObjectCodec]))),
			additionalProperties: optionFromNullable(union([boolean, ReferenceObjectCodec, SchemaObjectCodec])),
			required: optionFromNullable(array(string)),
		}),
	]),
);
github devexperts / swagger-codegen-ts / src / schema / 2.0 / parameter-object.ts View on Github external
required: optionFromNullable(boolean),
	name: string,
	description: optionFromNullable(string),
};

export type ArrayParameterObjectCollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi';
export interface BaseArrayParameterObject {
	readonly type: 'array';
	readonly items: ItemsObject;
	readonly collectionFormat: Option;
}

const BaseArrayParameterObjectProps = {
	type: literal('array'),
	items: ItemsObjectCodec,
	collectionFormat: optionFromNullable(
		union([literal('csv'), literal('ssv'), literal('tsv'), literal('pipes'), literal('multi')]),
	),
};

export interface BaseNonArrayParameterObject {
	readonly type: 'string' | 'number' | 'integer' | 'boolean';
	readonly format: Option;
}

const BaseNonArrayParameterObjectProps = {
	type: union([literal('string'), literal('number'), literal('integer'), literal('boolean')]),
	format: optionFromNullable(string),
};

export interface BodyParameterObject extends BaseParameterObject {
	readonly in: 'body';
github devexperts / swagger-codegen-ts / src / utils / io-ts.ts View on Github external
TypeOf,
	union,
	Validation,
	ValidationError,
} from 'io-ts';
import { pipe } from 'fp-ts/lib/pipeable';
import { array, either, option } from 'fp-ts';
import { Either } from 'fp-ts/lib/Either';
import { setFromArray } from 'io-ts-types/lib/setFromArray';
import { Ord } from 'fp-ts/lib/Ord';

export interface Codec<a> extends Type {}

export const stringOption = optionFromNullable(t.string);
export const booleanOption = optionFromNullable(t.boolean);
export const numberOption = optionFromNullable(t.number);
export const stringArrayOption = optionFromNullable(t.array(t.string));
export const primitiveArrayOption = optionFromNullable(t.array(t.union([t.string, t.boolean, t.number])));

export const dictionary = (codec: C, name?: string): RecordC =&gt;
	record(string, codec, name);

export const reportIfFailed = </a><a>(validation: Validation</a><a>): Either =&gt;
	pipe(
		validation,
		either.mapLeft(e =&gt;
			pipe(
				array.last(e),
				option.fold(
					() =&gt; new Error('Validation failure should contain at least one error'),
					e =&gt; new Error(getMessage(e)),
				),</a>
github devexperts / swagger-codegen-ts / src / schema / 2.0 / items-object / items-object.ts View on Github external
export const ItemsObject: Codec = recursion('ItemsObject', ItemsObject =&gt; {
	const ArrayItemsObject = type({
		...BaseItemsObjectProps,
		type: literal('array'),
		items: optionFromNullable(array(ItemsObject)),
	});
	return union([ArrayItemsObject, StringItemsObject, NumberItemsObject, IntegerItemsObject, BooleanItemsObject]);
});
github devexperts / swagger-codegen-ts / src / schema / asyncapi-2.0.0 / schema-object.ts View on Github external
import { Option } from 'fp-ts/lib/Option';
import { optionFromNullable } from 'io-ts-types/lib/optionFromNullable';
import { ReferenceObject, ReferenceObjectCodec } from './reference-object';
import { ordString } from 'fp-ts/lib/Ord';
import { NonEmptyArray } from 'fp-ts/lib/NonEmptyArray';
import { nonEmptyArray } from 'io-ts-types/lib/nonEmptyArray';
import { ExternalDocumentationObject, ExternalDocumentationObjectCodec } from './external-documentation-object';

export interface BaseSchemaObject {
	externalDocs: Option;
	deprecated: Option;
}
export const BaseSchemaObjectCodec: Codec = type(
	{
		externalDocs: optionFromNullable(ExternalDocumentationObjectCodec),
		deprecated: optionFromNullable(boolean),
	},
	'BaseSchemaObject',
);

export interface EnumSchemaObject extends BaseSchemaObject {
	readonly enum: NonEmptyArray;
}
export const EnumSchemaObjectCodec: Codec = intersection(
	[
		BaseSchemaObjectCodec,
		type({
			enum: nonEmptyArray(JSONPrimitiveCodec),
		}),
	],
	'EnumSchemaObject',
);
github devexperts / swagger-codegen-ts / src / schema / 2.0 / path-item-object.ts View on Github external
readonly get: Option;
	readonly put: Option;
	readonly post: Option;
	readonly delete: Option;
	readonly options: Option;
	readonly head: Option;
	readonly patch: Option;
	readonly parameters: Option&gt;;
}

export const PathItemObjectCodec = type(
	{
		$ref: stringOption,
		get: optionFromNullable(OperationObject),
		put: optionFromNullable(OperationObject),
		post: optionFromNullable(OperationObject),
		delete: optionFromNullable(OperationObject),
		options: optionFromNullable(OperationObject),
		head: optionFromNullable(OperationObject),
		patch: optionFromNullable(OperationObject),
		parameters: optionFromNullable(array(union([ReferenceObjectCodec, ParameterObjectCodec]))),
	},
	'PathItemObject',
);