UNPKG

digitaltwin-core

Version:

Minimalist framework to collect and handle data in a Digital Twin project

93 lines 3.07 kB
/** * @fileoverview OpenAPI specification generator for Digital Twin components * * This module provides utilities to automatically generate OpenAPI 3.0 * documentation from Digital Twin components that implement OpenAPIDocumentable. */ import type { OpenAPIDocument, OpenAPIGeneratorOptions, OpenAPISchema } from './types.js'; /** * Generates OpenAPI 3.0 specifications from Digital Twin components. * * The generator aggregates OpenAPI specs from all components that implement * the OpenAPIDocumentable interface and produces a complete OpenAPI document. * * @example * ```typescript * import { OpenAPIGenerator } from 'digitaltwin-core' * import * as components from './src/components' * * const spec = OpenAPIGenerator.generate({ * info: { * title: 'My Digital Twin API', * version: '1.0.0', * description: 'API documentation' * }, * components: Object.values(components), * servers: [{ url: 'http://localhost:3000' }] * }) * * // Write to file * OpenAPIGenerator.writeYAML(spec, './openapi.yaml') * ``` */ export declare class OpenAPIGenerator { /** * Generates an OpenAPI document from the provided components. * * @param options - Generation options including components and metadata * @returns Complete OpenAPI document */ static generate(options: OpenAPIGeneratorOptions): OpenAPIDocument; /** * Returns default security schemes for APISIX/Keycloak authentication. */ private static getDefaultSecuritySchemes; /** * Converts an OpenAPI document to YAML string. * * @param document - OpenAPI document to convert * @returns YAML string representation */ static toYAML(document: OpenAPIDocument): string; /** * Converts an OpenAPI document to JSON string. * * @param document - OpenAPI document to convert * @param pretty - Whether to format with indentation (default: true) * @returns JSON string representation */ static toJSON(document: OpenAPIDocument, pretty?: boolean): string; /** * Recursively converts an object to YAML format. * Simple implementation without external dependencies. */ private static objectToYAML; /** * Helper to create a simple schema reference. */ static schemaRef(name: string): OpenAPISchema; /** * Helper to create a common response for 200 OK with content. */ static successResponse(contentType: string, schema: OpenAPISchema, description?: string): { '200': { description: string; content: { [contentType]: { schema: OpenAPISchema; }; }; }; }; /** * Helper to create common error responses. */ static errorResponses(codes?: Array<400 | 401 | 403 | 404 | 500>): Record<string, { description: string; }>; /** * Common schemas used across components. */ static commonSchemas: Record<string, OpenAPISchema>; } //# sourceMappingURL=generator.d.ts.map