Enable automatic OpenAPI spec generation.

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>
This commit is contained in:
David Mehren 2020-07-26 16:53:43 +02:00
parent 06c62cc422
commit 1906f44e74
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
4 changed files with 61 additions and 4 deletions

View file

@ -1,9 +1,18 @@
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,