Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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',
);
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',
);
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',
);
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',
);
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)),
}),
]),
);
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';
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 =>
record(string, codec, name);
export const reportIfFailed = </a><a>(validation: Validation</a><a>): Either =>
pipe(
validation,
either.mapLeft(e =>
pipe(
array.last(e),
option.fold(
() => new Error('Validation failure should contain at least one error'),
e => new Error(getMessage(e)),
),</a>
export const ItemsObject: Codec = recursion('ItemsObject', ItemsObject => {
const ArrayItemsObject = type({
...BaseItemsObjectProps,
type: literal('array'),
items: optionFromNullable(array(ItemsObject)),
});
return union([ArrayItemsObject, StringItemsObject, NumberItemsObject, IntegerItemsObject, BooleanItemsObject]);
});
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',
);
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',
);