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', () => { describe('root', () => {
it('should return "Hello World!"', () => { it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!'); expect(appController.sayHello()).toBe('Hello World!');
}); });
}); });
}); });

View file

@ -5,8 +5,9 @@ import { AppService } from './app.service';
export class AppController { export class AppController {
constructor(private readonly appService: AppService) {} constructor(private readonly appService: AppService) {}
@Get() @Get()
getHello(): string { sayHello(): string {
return this.appService.getHello(); return this.appService.getHello();
} }
} }

View file

@ -1,8 +1,27 @@
import { NestFactory } from '@nestjs/core'; import { NestFactory } from "@nestjs/core";
import { AppModule } from './app.module'; import { AppModule } from "./app.module";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);
await app.listen(3000);
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(); bootstrap();