feat(openapi): Add OpenAPI module: decorators, spec generator, runtime validation and Swagger UI
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
||||
compressResponse,
|
||||
type ICompressionConfig,
|
||||
} from '../compression/index.js';
|
||||
import { createOpenApiHandler, createSwaggerUiHandler } from '../openapi/openapi.handlers.js';
|
||||
|
||||
/**
|
||||
* SmartServe - Cross-platform HTTP server
|
||||
@@ -122,6 +123,11 @@ export class SmartServe {
|
||||
throw new ServerAlreadyRunningError();
|
||||
}
|
||||
|
||||
// Register OpenAPI endpoints if configured
|
||||
if (this.options.openapi && this.options.openapi.enabled !== false) {
|
||||
this.setupOpenApi();
|
||||
}
|
||||
|
||||
// Prepare options with internal callbacks if typedRouter is configured
|
||||
let adapterOptions = this.options;
|
||||
|
||||
@@ -252,6 +258,29 @@ export class SmartServe {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup OpenAPI documentation endpoints
|
||||
*/
|
||||
private setupOpenApi(): void {
|
||||
const openapi = this.options.openapi!;
|
||||
const specPath = openapi.specPath ?? '/openapi.json';
|
||||
const docsPath = openapi.docsPath ?? '/docs';
|
||||
|
||||
// Create generator options
|
||||
const generatorOptions = {
|
||||
info: openapi.info,
|
||||
servers: openapi.servers,
|
||||
securitySchemes: openapi.securitySchemes,
|
||||
tags: openapi.tags,
|
||||
};
|
||||
|
||||
// Register OpenAPI spec endpoint
|
||||
ControllerRegistry.addRoute(specPath, 'GET', createOpenApiHandler(generatorOptions));
|
||||
|
||||
// Register Swagger UI endpoint
|
||||
ControllerRegistry.addRoute(docsPath, 'GET', createSwaggerUiHandler(specPath, openapi.info.title));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the main request handler
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user