@samchon/openapi
Version:
OpenAPI definitions and converters for 'typia' and 'nestia'.
1 lines • 12 kB
Source Map (JSON)
{"version":3,"file":"OpenApiV3_1.mjs","sources":["../src/OpenApiV3_1.ts"],"sourcesContent":["import { IJsonSchemaAttribute } from \"./structures/IJsonSchemaAttribute\";\n\n/**\n * OpenAPI v3.1 definition.\n *\n * @author Jeongho Nam - https://github.com/samchon\n */\nexport namespace OpenApiV3_1 {\n /**\n * @internal\n */\n export const is = (input: any): input is IDocument =>\n typeof input === \"object\" &&\n input !== null &&\n typeof input.openapi === \"string\" &&\n input.openapi.startsWith(\"3.1\");\n\n export type Method =\n | \"get\"\n | \"post\"\n | \"put\"\n | \"delete\"\n | \"options\"\n | \"head\"\n | \"patch\"\n | \"trace\";\n\n /* -----------------------------------------------------------\n DOCUMENTS\n ----------------------------------------------------------- */\n export interface IDocument {\n openapi: `3.1.${number}`;\n servers?: IServer[];\n info?: IDocument.IInfo;\n components?: IComponents;\n paths?: Record<string, IPath>;\n webhooks?: Record<\n string,\n IJsonSchema.IReference<`#/components/pathItems/${string}`> | IPath\n >;\n security?: Record<string, string[]>[];\n tags?: IDocument.ITag[];\n }\n export namespace IDocument {\n export interface IInfo {\n title: string;\n summary?: string;\n description?: string;\n termsOfService?: string;\n contact?: IContact;\n license?: ILicense;\n version: string;\n }\n export interface ITag {\n name: string;\n description?: string;\n }\n export interface IContact {\n name?: string;\n url?: string;\n email?: string;\n }\n export interface ILicense {\n name: string;\n identifier?: string;\n url?: string;\n }\n }\n\n export interface IServer {\n url: string;\n description?: string;\n variables?: Record<string, IServer.IVariable>;\n }\n export namespace IServer {\n export interface IVariable {\n default: string;\n /** @minItems 1 */ enum?: string[];\n description?: string;\n }\n }\n\n /* -----------------------------------------------------------\n OPERATORS\n ----------------------------------------------------------- */\n export interface IPath extends Partial<Record<Method, IOperation>> {\n parameters?: Array<\n | IOperation.IParameter\n | IJsonSchema.IReference<`#/components/headers/${string}`>\n | IJsonSchema.IReference<`#/components/parameters/${string}`>\n >;\n servers?: IServer[];\n summary?: string;\n description?: string;\n }\n\n export interface IOperation {\n operationId?: string;\n parameters?: Array<\n | IOperation.IParameter\n | IJsonSchema.IReference<`#/components/headers/${string}`>\n | IJsonSchema.IReference<`#/components/parameters/${string}`>\n >;\n requestBody?:\n | IOperation.IRequestBody\n | IJsonSchema.IReference<`#/components/requestBodies/${string}`>;\n responses?: Record<\n string,\n | IOperation.IResponse\n | IJsonSchema.IReference<`#/components/responses/${string}`>\n >;\n servers?: IServer[];\n summary?: string;\n description?: string;\n security?: Record<string, string[]>[];\n tags?: string[];\n deprecated?: boolean;\n }\n export namespace IOperation {\n export interface IParameter {\n name?: string;\n in: \"path\" | \"query\" | \"header\" | \"cookie\";\n schema: IJsonSchema;\n required?: boolean;\n description?: string;\n example?: any;\n examples?: Record<\n string,\n IExample | IJsonSchema.IReference<`#/components/examples/${string}`>\n >;\n }\n export interface IRequestBody {\n description?: string;\n required?: boolean;\n content?: Record<string, IMediaType>;\n }\n export interface IResponse {\n content?: Record<string, IMediaType>;\n headers?: Record<\n string,\n | Omit<IOperation.IParameter, \"in\">\n | IJsonSchema.IReference<`#/components/headers/${string}`>\n >;\n description?: string;\n }\n export interface IMediaType {\n schema?: IJsonSchema;\n example?: any;\n examples?: Record<\n string,\n IExample | IJsonSchema.IReference<`#/components/examples/${string}`>\n >;\n }\n }\n\n export interface IExample {\n summary?: string;\n description?: string;\n value?: any;\n externalValue?: string;\n }\n\n /* -----------------------------------------------------------\n SCHEMA DEFINITIONS\n ----------------------------------------------------------- */\n export interface IComponents {\n schemas?: Record<string, IJsonSchema>;\n pathItems?: Record<string, IPath>;\n responses?: Record<string, IOperation.IResponse>;\n parameters?: Record<string, IOperation.IParameter>;\n requestBodies?: Record<string, IOperation.IRequestBody>;\n securitySchemes?: Record<string, ISecurityScheme>;\n headers?: Record<string, Omit<IOperation.IParameter, \"in\">>;\n examples?: Record<string, IExample>;\n }\n\n export type IJsonSchema =\n | IJsonSchema.IMixed\n | IJsonSchema.IConstant\n | IJsonSchema.IBoolean\n | IJsonSchema.IInteger\n | IJsonSchema.INumber\n | IJsonSchema.IString\n | IJsonSchema.IArray\n | IJsonSchema.IObject\n | IJsonSchema.IReference\n | IJsonSchema.IRecursiveReference\n | IJsonSchema.IAllOf\n | IJsonSchema.IAnyOf\n | IJsonSchema.IOneOf\n | IJsonSchema.INull\n | IJsonSchema.IUnknown;\n export namespace IJsonSchema {\n export interface IMixed\n extends IConstant,\n Omit<IBoolean, \"type\" | \"default\" | \"enum\">,\n Omit<INumber, \"type\" | \"default\" | \"enum\">,\n Omit<IString, \"type\" | \"default\" | \"enum\">,\n Omit<IArray, \"type\">,\n Omit<IObject, \"type\">,\n IOneOf,\n IAnyOf,\n IAllOf,\n IReference {\n type: Array<\n | \"boolean\"\n | \"integer\"\n | \"number\"\n | \"string\"\n | \"array\"\n | \"object\"\n | \"null\"\n >;\n default?: any[] | null;\n enum?: any[];\n }\n\n export interface IConstant extends __IAttribute {\n const: boolean | number | string;\n nullable?: boolean;\n }\n export interface IBoolean\n extends Omit<IJsonSchemaAttribute.IBoolean, \"examples\">,\n __IAttribute {\n nullable?: boolean;\n default?: boolean | null;\n enum?: Array<boolean | null>;\n }\n export interface IInteger\n extends Omit<IJsonSchemaAttribute.IInteger, \"examples\">,\n __IAttribute {\n nullable?: boolean;\n /** @type int64 */ default?: number | null;\n /** @type int64 */ enum?: Array<number | null>;\n /** @type int64 */ minimum?: number;\n /** @type int64 */ maximum?: number;\n /** @type int64 */ exclusiveMinimum?: number | boolean;\n /** @type int64 */ exclusiveMaximum?: number | boolean;\n /**\n * @type uint64\n * @exclusiveMinimum 0\n */\n multipleOf?: number;\n }\n export interface INumber\n extends Omit<IJsonSchemaAttribute.INumber, \"examples\">,\n __IAttribute {\n nullable?: boolean;\n default?: number | null;\n enum?: Array<number | null>;\n minimum?: number;\n maximum?: number;\n exclusiveMinimum?: number | boolean;\n exclusiveMaximum?: number | boolean;\n /** @exclusiveMinimum 0 */ multipleOf?: number;\n }\n export interface IString\n extends Omit<IJsonSchemaAttribute.IString, \"examples\">,\n __IAttribute {\n nullable?: boolean;\n default?: string | null;\n enum?: Array<string | null>;\n format?:\n | \"binary\"\n | \"byte\"\n | \"password\"\n | \"regex\"\n | \"uuid\"\n | \"email\"\n | \"hostname\"\n | \"idn-email\"\n | \"idn-hostname\"\n | \"iri\"\n | \"iri-reference\"\n | \"ipv4\"\n | \"ipv6\"\n | \"uri\"\n | \"uri-reference\"\n | \"uri-template\"\n | \"url\"\n | \"date-time\"\n | \"date\"\n | \"time\"\n | \"duration\"\n | \"json-pointer\"\n | \"relative-json-pointer\"\n | (string & {});\n pattern?: string;\n contentMediaType?: string;\n /** @type uint64 */ minLength?: number;\n /** @type uint64 */ maxLength?: number;\n }\n\n export interface IObject\n extends Omit<IJsonSchemaAttribute.IObject, \"examples\">,\n __IAttribute {\n nullable?: boolean;\n properties?: Record<string, IJsonSchema>;\n required?: string[];\n additionalProperties?: boolean | IJsonSchema;\n maxProperties?: number;\n minProperties?: number;\n }\n export interface IArray\n extends Omit<IJsonSchemaAttribute.IArray, \"examples\">,\n __IAttribute {\n nullable?: boolean;\n items?: IJsonSchema | IJsonSchema[];\n prefixItems?: IJsonSchema[];\n uniqueItems?: boolean;\n additionalItems?: boolean | IJsonSchema;\n /** @type uint64 */ minItems?: number;\n /** @type uint64 */ maxItems?: number;\n }\n export interface IReference<Key = string> extends __IAttribute {\n $ref: Key;\n }\n export interface IRecursiveReference extends __IAttribute {\n $recursiveRef: string;\n }\n\n export interface IAllOf extends __IAttribute {\n allOf: IJsonSchema[];\n }\n export interface IAnyOf extends __IAttribute {\n anyOf: IJsonSchema[];\n }\n export interface IOneOf extends __IAttribute {\n oneOf: IJsonSchema[];\n discriminator?: IOneOf.IDiscriminator;\n }\n export namespace IOneOf {\n export interface IDiscriminator {\n propertyName: string;\n mapping?: Record<string, string>;\n }\n }\n\n export interface INull\n extends Omit<IJsonSchemaAttribute.INull, \"examples\">,\n __IAttribute {\n default?: null;\n }\n export interface IUnknown\n extends Omit<IJsonSchemaAttribute.IUnknown, \"examples\">,\n __IAttribute {\n type?: undefined;\n default?: any;\n }\n\n export interface __IAttribute\n extends Omit<IJsonSchemaAttribute, \"examples\"> {\n examples?: any[] | Record<string, any>;\n }\n }\n\n export type ISecurityScheme =\n | ISecurityScheme.IApiKey\n | ISecurityScheme.IHttpBasic\n | ISecurityScheme.IHttpBearer\n | ISecurityScheme.IOAuth2\n | ISecurityScheme.IOpenId;\n export namespace ISecurityScheme {\n export interface IApiKey {\n type: \"apiKey\";\n in?: \"header\" | \"query\" | \"cookie\";\n name?: string;\n description?: string;\n }\n export interface IHttpBasic {\n type: \"http\";\n scheme: \"basic\";\n description?: string;\n }\n export interface IHttpBearer {\n type: \"http\";\n scheme: \"bearer\";\n bearerFormat?: string;\n description?: string;\n }\n export interface IOAuth2 {\n type: \"oauth2\";\n flows: IOAuth2.IFlowSet;\n description?: string;\n }\n export interface IOpenId {\n type: \"openIdConnect\";\n openIdConnectUrl: string;\n description?: string;\n }\n export namespace IOAuth2 {\n export interface IFlowSet {\n authorizationCode?: IFlow;\n implicit?: Omit<IFlow, \"tokenUrl\">;\n password?: Omit<IFlow, \"authorizationUrl\">;\n clientCredentials?: Omit<IFlow, \"authorizationUrl\">;\n }\n export interface IFlow {\n authorizationUrl?: string;\n tokenUrl?: string;\n refreshUrl?: string;\n scopes?: Record<string, string>;\n }\n }\n }\n}\n"],"names":["OpenApiV3_1","is","input","openapi","startsWith"],"mappings":"AAOM,IAAWA;;CAAjB,SAAiBA;IAIFA,YAAEC,KAAIC,gBACVA,UAAU,YACjBA,UAAU,eACHA,MAAMC,YAAY,YACzBD,MAAMC,QAAQC,WAAW;AAsY5B,EA9YD,CAAiBJ,gBAAAA,cA8YhB,CAAA;;"}