UNPKG

edge-master

Version:
150 lines (149 loc) 4.14 kB
/** * Basic OpenAPI 3.0 schema generation utilities * This is a simplified implementation - for advanced features, consider using a dedicated OpenAPI library */ export interface OpenAPIInfo { title: string; version: string; description?: string; contact?: { name?: string; email?: string; url?: string; }; license?: { name: string; url?: string; }; } export interface OpenAPIServer { url: string; description?: string; } export interface OpenAPIParameter { name: string; in: 'query' | 'header' | 'path' | 'cookie'; description?: string; required?: boolean; schema: any; } export interface OpenAPIRequestBody { description?: string; required?: boolean; content: { [mediaType: string]: { schema: any; }; }; } export interface OpenAPIResponse { description: string; content?: { [mediaType: string]: { schema: any; }; }; } export interface OpenAPIOperation { summary?: string; description?: string; operationId?: string; tags?: string[]; parameters?: OpenAPIParameter[]; requestBody?: OpenAPIRequestBody; responses: { [statusCode: string]: OpenAPIResponse; }; security?: Array<{ [securityScheme: string]: string[]; }>; } export interface OpenAPIPath { get?: OpenAPIOperation; post?: OpenAPIOperation; put?: OpenAPIOperation; delete?: OpenAPIOperation; patch?: OpenAPIOperation; options?: OpenAPIOperation; head?: OpenAPIOperation; } export interface OpenAPISecurityScheme { type: 'apiKey' | 'http' | 'oauth2' | 'openIdConnect'; description?: string; name?: string; in?: 'query' | 'header' | 'cookie'; scheme?: string; bearerFormat?: string; } export interface OpenAPISpec { openapi: string; info: OpenAPIInfo; servers?: OpenAPIServer[]; paths: { [path: string]: OpenAPIPath; }; components?: { schemas?: { [name: string]: any; }; securitySchemes?: { [name: string]: OpenAPISecurityScheme; }; }; tags?: Array<{ name: string; description?: string; }>; } /** * Creates a basic OpenAPI specification */ export declare function createOpenAPISpec(info: OpenAPIInfo): OpenAPISpec; /** * Adds a server to the OpenAPI spec */ export declare function addServer(spec: OpenAPISpec, server: OpenAPIServer): OpenAPISpec; /** * Adds a path to the OpenAPI spec */ export declare function addPath(spec: OpenAPISpec, path: string, method: 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head', operation: OpenAPIOperation): OpenAPISpec; /** * Adds a schema to the components section */ export declare function addSchema(spec: OpenAPISpec, name: string, schema: any): OpenAPISpec; /** * Adds a security scheme to the components section */ export declare function addSecurityScheme(spec: OpenAPISpec, name: string, scheme: OpenAPISecurityScheme): OpenAPISpec; /** * Adds a tag to the OpenAPI spec */ export declare function addTag(spec: OpenAPISpec, name: string, description?: string): OpenAPISpec; /** * Helper to create a JSON response schema */ export declare function jsonResponse(description: string, schema: any): OpenAPIResponse; /** * Helper to create a JSON request body */ export declare function jsonRequestBody(schema: any, required?: boolean): OpenAPIRequestBody; /** * Helper to create common response schemas */ export declare const commonResponses: { success: (schema?: any) => OpenAPIResponse; created: (schema?: any) => OpenAPIResponse; noContent: () => OpenAPIResponse; badRequest: () => OpenAPIResponse; unauthorized: () => OpenAPIResponse; forbidden: () => OpenAPIResponse; notFound: () => OpenAPIResponse; serverError: () => OpenAPIResponse; }; /** * Helper to create common security schemes */ export declare const commonSecuritySchemes: { bearerAuth: () => OpenAPISecurityScheme; apiKey: (name?: string, inLocation?: 'header' | 'query') => OpenAPISecurityScheme; };