mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-04-19 00:45:20 +00:00
NestJS can automatically generate an OpenAPI spec by analyzing controllers and used DTOs. This commit enables this feature. The API docs are served under /apidoc. Signed-off-by: David Mehren <git@herrmehren.de>
26 lines
710 B
TypeScript
26 lines
710 B
TypeScript
import { ValidationPipe } from '@nestjs/common';
|
|
import { NestFactory } from '@nestjs/core';
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
import { AppModule } from './app.module';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
const swaggerOptions = new DocumentBuilder()
|
|
.setTitle('HedgeDoc')
|
|
.setVersion('2.0-dev')
|
|
.build();
|
|
const document = SwaggerModule.createDocument(app, swaggerOptions);
|
|
SwaggerModule.setup('apidoc', app, document);
|
|
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
forbidUnknownValues: true,
|
|
skipMissingProperties: false,
|
|
transform: true,
|
|
}),
|
|
);
|
|
await app.listen(3000);
|
|
}
|
|
|
|
bootstrap();
|