Setup Swagger

This commit is contained in:
Anthony Mineo 2020-08-29 19:20:44 -04:00
parent a1b2f2cd78
commit 2c3c9a0532
9 changed files with 37 additions and 53 deletions

View file

@ -7,16 +7,16 @@ describe('AppController', () => {
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
controllers: [ AppController ],
providers: [ AppService ]
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
it('should return "Healthy!"', () => {
expect(appController.getHello()).toBe('Healthy!');
});
});
});

View file

@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
return 'Healthy!';
}
}

View file

@ -9,7 +9,7 @@ export class GameController {
// /games/:gameId
@Get(':gameId')
@ApiOperation({ summary: 'Find game by Id' })
@ApiOperation({ tags: [ 'Game' ], summary: 'Find game by Id' })
findOne(@Param('gameId') gameId: string) {
return this.gameService.findOne(gameId);
}

View file

@ -1,4 +1,5 @@
import { Controller, Get, Param, Query } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { GamesService } from './games.service';
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
@ -9,6 +10,7 @@ export class GamesController {
// /games
@Get()
@ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games' })
findAll(@Query() paginationQuery: PaginationQueryDto) {
const { limit = 10, offset = 0 } = paginationQuery;
return this.gameService.findAll({ limit, offset });
@ -16,13 +18,8 @@ export class GamesController {
// /gametype/:gametype
@Get('gametype/:gametype')
@ApiOperation({ tags: [ 'Game' ], summary: 'Return the latest games by game type' })
findByType(@Param('gametype') gametype: string) {
return this.gameService.findByType(gametype);
}
// /games/:gameId
@Get(':gameId')
findOne(@Param('gameId') gameId: string) {
return this.gameService.findOne(gameId);
}
}

View file

@ -41,12 +41,4 @@ export class GamesService {
}
return game;
}
async findOne(gameId: string) {
const game = await this.gamesRepository.findOne(gameId);
if (!game) {
throw new NotFoundException(`Game ID: ${gameId} not found`);
}
return game;
}
}

View file

@ -22,7 +22,8 @@ async function bootstrap() {
.setTitle('Tribes 2 Stats API')
.setDescription('Powering stats.playt2.com')
.setVersion('1.0')
.addTag('task')
.addTag('Game')
.addTag('Player')
.build();
const document = SwaggerModule.createDocument(app, swaggerOptions);

View file

@ -1,7 +1,7 @@
import { Controller, Get, Param } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { PlayerService } from './player.service';
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
@Controller('player')
export class PlayerController {
@ -9,6 +9,7 @@ export class PlayerController {
// /player/:playerGuid
@Get(':playerGuid')
@ApiOperation({ tags: [ 'Player' ], summary: 'Return player stats by guid' })
findOne(@Param('playerGuid') playerGuid: string) {
return this.playerService.findOne(playerGuid);
}

View file

@ -1,4 +1,5 @@
import { Controller, Get, Query, Param } from '@nestjs/common';
import { ApiOperation } from '@nestjs/swagger';
import { PlayersService } from './players.service';
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
@ -9,14 +10,9 @@ export class PlayersController {
// /players
@Get()
@ApiOperation({ tags: [ 'Player' ], summary: 'Return a list of players' })
findAll(@Query() paginationQuery: PaginationQueryDto) {
const { limit = 10, offset = 0 } = paginationQuery;
return this.playerService.findAll({ limit, offset });
}
// /players/:playerGuid
@Get(':playerGuid')
findOne(@Param('playerGuid') playerGuid: string) {
return this.playerService.findOne(playerGuid);
}
}

View file

@ -8,7 +8,7 @@ describe('AppController (e2e)', () => {
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
imports: [ AppModule ]
}).compile();
app = moduleFixture.createNestApplication();
@ -16,9 +16,6 @@ describe('AppController (e2e)', () => {
});
it('/ (GET)', () => {
return request(app.getHttpServer())
.get('/')
.expect(200)
.expect('Hello World!');
return request(app.getHttpServer()).get('/').expect(200).expect('Healthy!');
});
});