import { FilterKeys, PathsWithMethod } from 'openapi-typescript-helpers'; import { MethodType } from '../const/methods.js'; import { FilterKeyOrNever, IsFieldOptional } from './utils.js'; /** * @description Define possible field types in OpenAPI schema */ export type FieldType = 'parameters' | 'requestBody' | 'responses'; type MediaType = `${string}/${string}`; /** * @description Type definition for the OpenAPI schema */ export type SchemaType = { [route in keyof object]: { [method in MethodType]?: { parameters: { query?: object; path?: object; }; requestBody?: { content: { [content in MediaType]: unknown; }; }; responses?: { [code in number]: { content: { [content in MediaType]: unknown; }; }; }; }; }; }; /** * @description Checks for the existence of an internal route. If it exists, it retrieves it */ export type SchemeRoute> = FilterKeys, Method>; /** * @description Checks for the existence of an internal field. If it exists, it retrieves it */ export type SchemeRouteField, Field extends FieldType> = FilterKeys, Field>; /** * @description Extracts all path parameters for a given route and method in the schema */ export type RoutePath> = FilterKeyOrNever, 'path'>; /** * @description Extracts all query parameters for a given route and method in the schema */ export type RouteQuery> = FilterKeyOrNever, 'query'>; /** * @description Extracts all routes from the OpenAPI schema interface */ export type RoutesForMethod = PathsWithMethod; type TargetMimeTypes = `${string}/json` | `multipart/form-data`; /** * @description Retrieves the request body */ export type RouteRequestBody> = IsFieldOptional, 'requestBody'> extends true ? FilterKeys>, 'requestBody'>, 'content'>, TargetMimeTypes> | undefined : FilterKeys, Method>, 'requestBody'>, 'content'>, TargetMimeTypes>; /** * @example * { * 200: data, * 400: data * } */ export type RouteResponsesByStatusCode, Responses = SchemeRouteField> = { [k in keyof Responses]: FilterKeys, TargetMimeTypes>; }; export {};