Skip to content

Commit

Permalink
feat: improve swagger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
guesant committed Feb 24, 2024
1 parent be803c4 commit 09f83ba
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
28 changes: 28 additions & 0 deletions luna-backend/src/application/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
import { Controller, Get } from '@nestjs/common';
import { ApiResponse, ApiTags } from '@nestjs/swagger';
import { AppService } from './app.service';

@ApiTags('SISGEA - API')
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
@ApiResponse({
status: 200,
description: 'Olá, Mundo!',
schema: {
type: 'object',
properties: {
service: {
type: 'string',
enum: ['sisgea-luna-backend'],
description: 'O nome desta aplicação.',
},
status: {
type: 'string',
enum: ['up'],
description: 'Status desta aplicação.',
},
egg: {
type: 'string',
default: null,
description: 'Mensagem secreta que aparece em ocasiões específicas.',
nullable: true,
},
},
required: ['service', 'status'],
},
})
getHello() {
return this.appService.getHello();
}
Expand Down
1 change: 1 addition & 0 deletions luna-backend/src/application/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class AppService {
return {
service: 'sisgea-luna-backend',
status: 'up',
egg: null,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ export const DtoOperationFindAll = (options: IDtoOperationOptions) => {

ApiResponse({
status: 200,

type: options.swagger.returnType,

description: options.description ?? 'Lista os recursos cadastrados no sistema.',
}),
);
Expand Down
23 changes: 14 additions & 9 deletions luna-backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function bootstrap() {
//

const isProduction = environmentConfigService.getRuntimeIsProduction();
const isDevelopment = environmentConfigService.getRuntimeIsDevelopment();

//

Expand All @@ -33,16 +34,20 @@ async function bootstrap() {

//

const config = new DocumentBuilder()
.setTitle('SISGEA - Luna - API')
.setDescription('API para a consulta e manipulação de dados e procedimentos relacionados ao Sistema de Gestão Acadêmico.')
.setVersion('0.0')
.addServer('https://luna.sisgha.com/api/')
.addServer('http://localhost:3000/')
.addBearerAuth()
.build();
const config = new DocumentBuilder();

const document = SwaggerModule.createDocument(app, config);
config.setTitle('SISGEA - Luna - API');
config.setDescription('API para a consulta e manipulação de dados e procedimentos relacionados ao Sistema de Gestão Acadêmico.');
config.setVersion('0.0');

if (isDevelopment) {
config.addServer('http://localhost:3000/');
}

config.addServer('https://luna.sisgha.com/api/');
config.addBearerAuth();

const document = SwaggerModule.createDocument(app, config.build());
SwaggerModule.setup('doc-api', app, document);

//
Expand Down

0 comments on commit 09f83ba

Please sign in to comment.