import { Environment } from '../models/environment.model'; /** * Convert to and from Swagger/OpenAPI formats * * OpenAPI specifications: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md * Swagger specifications: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md * */ export declare class OpenApiConverter { /** * Import Swagger or OpenAPI format * Receives a raw specification string and tries to parse it * Loading of the file or URL should be done by the caller even if scalar/openapi-parser * can also load files and URLs. * $ref URLs will be fetched. * File loading is not done here to keep this library compatible with browser usage. * * @param spec - raw specification string * @throws {Error} */ convertFromOpenAPI(spec: string, port?: number): Promise; /** * Convert environment to OpenAPI JSON object * * * @param environment * @throws {Error} */ convertToOpenAPIV3(environment: Environment, format: 'json' | 'yaml', prettify?: boolean): Promise; /** * Dereference all $ref in an OpenAPI specification * Handles both internal (#/components/schemas/...) and external (URL) references * Includes circular dependency detection and caching * * @param parsedSpec - The parsed OpenAPI specification * @returns Promise - The dereferenced schema */ dereference(parsedSpec: any): Promise; /** * Convert Swagger 2.0 format * * @param parsedAPI */ private convertFromSwagger; /** * Convert OpenAPI 3.0 format * * @param parsedAPI */ private convertFromOpenAPIV3; /** * Creates routes from imported swagger/OpenAPI document * * @param parsedAPI * @param version */ private createRoutes; /** * Build route response headers from 'content' (v3) or 'produces' (v2), and 'headers' objects * * @param contentTypes * @param responseHeaders */ private buildResponseHeaders; /** * Build route response from label, status code, headers and unformatted body. * @param body * @param label * @param statusCode * @param headers * @private */ private buildResponse; /** * Replace parameters in `str`: * - {parameter-name} => :parametername (Express does * not support hyphens in parameter names) * - {param} => :param * * @param str */ private routeParametersReplace; /** * Replace parameters in `str` with server variables * * @param str * @param parameters * @returns */ private v3ParametersReplace; /** * Swagger specification type guard * * @param parsedAPI */ private isSwagger; /** * OpenAPI v3 specification type guard * * @param parsedAPI */ private isOpenAPIV3; /** * Merge multiple schemas from allOf into a single schema * Combines properties, required fields, and other schema attributes * * @param schemas - Array of schemas to merge * @returns Merged schema */ private mergeAllOfSchemas; /** * Generate a JSON object from a schema * * @scalar/openapi-parser handles circular references differently than the previous * library we used (@apidevtools/swagger-parser) * Instead of ignoring them, it reuses the object references and creates * circular structures in the parsed object. * * We need to keep track of the schemas we've already parsed in `parentSchemas` * but delete them when going out of a branch (i.e. when going to the next sibling). * */ private generateSchema; /** * Parses a JSON or YAML specification string. * * @param spec - raw specification string * @returns */ private parseJsonOrYaml; /** * After generating example bodies, remove the quotes around some * primitive helpers * * @param jsonSchema */ private convertJSONSchemaPrimitives; /** * Extract bodies and labels from OpenAPI examples * @param examples * @param version * @private */ private parseOpenAPIExamples; }