23 lines
844 B
TypeScript
23 lines
844 B
TypeScript
import { INestApplication } from '@nestjs/common';
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
|
|
export const API_PREFIX = 'api/v1';
|
|
|
|
// Nest Swagger cannot express additionalProperties on a class, so closed request
|
|
// bodies are restored here after generation; the runtime allowlist stays in the controller.
|
|
const CLOSED_SCHEMAS = ['StockScreenerCriteriaDto'];
|
|
|
|
export function createOpenApiDocument(app: INestApplication) {
|
|
const document = SwaggerModule.createDocument(
|
|
app,
|
|
new DocumentBuilder().setTitle('WealthLedger API').setVersion('v1').build(),
|
|
);
|
|
const schemas = document.components?.schemas ?? {};
|
|
for (const [name, schema] of Object.entries(schemas)) {
|
|
if (CLOSED_SCHEMAS.includes(name) && 'properties' in schema) {
|
|
schema.additionalProperties = false;
|
|
}
|
|
}
|
|
return document;
|
|
}
|