UNPKG

@zodios/openapi

Version:
75 lines (72 loc) 3.28 kB
import { OpenAPIV3 } from 'openapi-types'; import { ZodiosEndpointDefinitions } from '@zodios/core'; declare function bearerAuthScheme(description?: string): OpenAPIV3.SecuritySchemeObject; declare function basicAuthScheme(description?: string): OpenAPIV3.SecuritySchemeObject; declare function apiKeyAuthScheme(options: Omit<OpenAPIV3.ApiKeySecurityScheme, "type" | "description">, description?: string): OpenAPIV3.SecuritySchemeObject; declare function oauth2Scheme(flows: OpenAPIV3.OAuth2SecurityScheme["flows"], description?: string): OpenAPIV3.SecuritySchemeObject; /** * Create a simple openapi V3 document from a list of endpoints * @param definitions - the list of endpoints * @param options - additional information to add to the document * @returns - the openapi V3 document * @deprecated - use openApiBuilder instead */ declare function toOpenApi(definitions: ZodiosEndpointDefinitions, options?: { info?: OpenAPIV3.InfoObject; servers?: OpenAPIV3.ServerObject[]; securityScheme?: OpenAPIV3.SecuritySchemeObject; tagsFromPathFn?: (path: string) => string[]; }): OpenAPIV3.Document; declare class OpenApiBuilder { apis: Array<{ definitions: ZodiosEndpointDefinitions; } | { scheme: string; securityRequirement?: string[]; definitions: ZodiosEndpointDefinitions; }>; options: { info: OpenAPIV3.InfoObject; servers?: OpenAPIV3.ServerObject[]; securitySchemes?: Record<string, OpenAPIV3.SecuritySchemeObject>; tagsFromPathFn?: (path: string) => string[]; }; constructor(info: OpenAPIV3.InfoObject); /** * add a security scheme to proctect the apis * @param name - the name of the security scheme * @param securityScheme - the security scheme object */ addSecurityScheme(name: string, securityScheme: OpenAPIV3.SecuritySchemeObject): this; /** * add an api with public endpoints * @param definitions - the endpoint definitions * @returns */ addPublicApi(definitions: ZodiosEndpointDefinitions): this; /** * add an api protected by a security scheme * @param scheme - the name of the security scheme to use * @param definitions - the endpoints API * @param securityRequirement - optional security requirement to use for this API (oauth2 scopes for example) */ addProtectedApi(scheme: string, definitions: ZodiosEndpointDefinitions, securityRequirement?: string[]): this; /** * add a server to the openapi document * @param server - the server to add */ addServer(server: OpenAPIV3.ServerObject): this; /** * ovveride the default tagsFromPathFn * @param tagsFromPathFn - a function that takes a path and returns the tags to use for this path */ setCustomTagsFn(tagsFromPathFn: (path: string) => string[]): this; build(): OpenAPIV3.Document<{}>; } /** * Builder to easily create an openapi V3 document from zodios api definitions * @param info - the info object to add to the document * @returns - the openapi V3 builder */ declare function openApiBuilder(info: OpenAPIV3.InfoObject): OpenApiBuilder; export { OpenApiBuilder, apiKeyAuthScheme, basicAuthScheme, bearerAuthScheme, oauth2Scheme, openApiBuilder, toOpenApi };