UNPKG

@affinidi/tools-openapi

Version:
107 lines (106 loc) 4.25 kB
declare type RefSpec<TRefName extends string> = { '$ref': `#/components/schemas/${TRefName}`; }; export declare type FieldSpecStringType = { type: 'string'; enum?: undefined; pattern?: string; }; export declare type FieldSpecEnumType<TEnum extends string> = { type: 'string'; enum: readonly TEnum[]; }; export declare type FieldSpecBooleanType = { type: 'boolean'; }; export declare type FieldSpecDoubleType = { type: 'number'; format: 'double'; }; export declare type FieldSpecRecordType = { type: 'object'; additionalProperties: true; properties?: Record<string, never>; }; export declare type FieldSpecRefType<TRefName extends string> = RefSpec<TRefName>; export declare type FieldSpecPrimitiveType = FieldSpecStringType | FieldSpecEnumType<string> | FieldSpecDoubleType | FieldSpecBooleanType | FieldSpecRecordType | FieldSpecRefType<string>; export declare type FieldSpecArrayType<TElementType extends ObjectSpecType> = { items: TElementType; type: 'array'; }; declare type SimpleObjectSpecOptionAdditionalProperties<TIsAdditionalPropertiesAllowed extends boolean> = TIsAdditionalPropertiesAllowed extends true ? { additionalProperties: true | Record<string, never> | { additionalProperties: true; type: 'object'; }; } : TIsAdditionalPropertiesAllowed extends false ? { additionalProperties?: false; } : never; declare type SimpleObjectPropertiesType<TKeys extends string, TProperty extends ObjectSpec> = Record<TKeys, TProperty>; export declare type SimpleObjectSpec<TKeys extends string, TRequiredKeysArray extends readonly TKeys[], TIsAdditionalPropertiesAllowed extends boolean> = { properties: SimpleObjectPropertiesType<TKeys, any>; type: 'object'; required?: TRequiredKeysArray; } & SimpleObjectSpecOptionAdditionalProperties<TIsAdditionalPropertiesAllowed>; export declare type AllOfObjectSpec<TObjectSpecTypes extends readonly ObjectSpecType[]> = { allOf: TObjectSpecTypes; }; export declare type AnyOfObjectSpec<TObjectSpecTypes extends readonly ObjectSpecType[]> = { anyOf: TObjectSpecTypes; }; export declare type OneOfObjectSpec<TObjectSpecTypes extends readonly ObjectSpecType[]> = { oneOf: TObjectSpecTypes; }; export declare type ObjectSpecType = FieldSpecPrimitiveType | FieldSpecArrayType<any> | SimpleObjectSpec<string, readonly string[], boolean> | AllOfObjectSpec<any> | AnyOfObjectSpec<any> | OneOfObjectSpec<any>; export declare type ObjectSpecOptionNullable = { nullable: true; }; export declare type ObjectSpec = ObjectSpecType & Partial<ObjectSpecOptionNullable>; export declare type ObjectSpecs<TKeys extends string> = Record<TKeys, ObjectSpec>; export declare type ContentSpec = { content: { 'application/json': { schema: ObjectSpec; }; }; }; export declare type RequestSpecWithData = ContentSpec; export declare type RequestSpecWithoutData = undefined; export declare type RequestSpec = RequestSpecWithData | RequestSpecWithoutData; declare type ResponseSuccessCode = '200' | '201' | '204'; export declare type ResponseSpecWithData = Partial<Record<ResponseSuccessCode, ContentSpec>>; declare type ResponseSpecWithoutData = Partial<Record<ResponseSuccessCode, { content?: { 'application/json': { schema?: Record<string, never>; }; }; description?: string; }>>; export declare type ResponseSpec = ResponseSpecWithData | ResponseSpecWithoutData; export declare type ParameterType = 'header' | 'query' | 'path'; export declare type ParameterSpec = { in: ParameterType; name: string; schema: ObjectSpec; required: boolean; }; export declare type OperationSpec = { operationId: string; responses: ResponseSpec; requestBody?: RequestSpec; parameters?: readonly ParameterSpec[]; }; export declare type HttpMethod = 'get' | 'post' | 'put' | 'delete'; export declare type PathSpec = Partial<Record<HttpMethod, OperationSpec>>; export declare type PathSpecs<TPaths extends string> = Record<TPaths, PathSpec>; export declare type GenericApiSpec = { components: { schemas: ObjectSpecs<string>; }; paths: PathSpecs<string>; servers: readonly [{ url: string; }]; }; export {};