fix: restore screener OpenAPI constraints (WealthLedger/backend#70) (#95)
This commit was merged in pull request #95.
This commit is contained in:
+12
-1
@@ -3,9 +3,20 @@ 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) {
|
||||
return SwaggerModule.createDocument(
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user