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