Configure swagger api docs

This commit is contained in:
Thom Werring 2023-10-21 10:27:20 +02:00
parent f9acd67d99
commit 9fa7224303
3 changed files with 29 additions and 9 deletions

View file

@ -16,7 +16,7 @@ describe('AppController', () => {
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
expect(appController.sayHello()).toBe('Hello World!');
});
});
});

View file

@ -6,7 +6,8 @@ export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
sayHello(): string {
return this.appService.getHello();
}
}

View file

@ -1,8 +1,27 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle("Thom Werring - CV")
.setDescription("Westerstraat 83<br/>1521ZB, Wormerveer<br/><a href='tel:+31637650849'>+31 6 37 65 08 49</a>")
.addApiKey({
type: "apiKey",
name: "Authorization",
bearerFormat: "bearer",
}, "Credentials")
.setVersion("1.0.0a")
.build();
const document = SwaggerModule.createDocument(app, config, {
operationIdFactory: (controllerKey: string, methodKey: string) => (`${methodKey[0].toUpperCase()}${methodKey.substring(1)}`)
});
SwaggerModule.setup("/api", app, document);
await app.listen(3000);
}
bootstrap();