From 2c3c9a053278b495d2712b52c0df76a01fe94544 Mon Sep 17 00:00:00 2001 From: Anthony Mineo Date: Sat, 29 Aug 2020 19:20:44 -0400 Subject: [PATCH] Setup Swagger --- app/api/src/app.controller.spec.ts | 26 +++++++++++------------ app/api/src/app.service.ts | 6 +++--- app/api/src/game/game.controller.ts | 2 +- app/api/src/games/games.controller.ts | 9 +++----- app/api/src/games/games.service.ts | 8 ------- app/api/src/main.ts | 3 ++- app/api/src/player/player.controller.ts | 3 ++- app/api/src/players/players.controller.ts | 8 ++----- app/api/test/app.e2e-spec.ts | 25 ++++++++++------------ 9 files changed, 37 insertions(+), 53 deletions(-) diff --git a/app/api/src/app.controller.spec.ts b/app/api/src/app.controller.spec.ts index d22f389..bd5216d 100644 --- a/app/api/src/app.controller.spec.ts +++ b/app/api/src/app.controller.spec.ts @@ -3,20 +3,20 @@ import { AppController } from './app.controller'; import { AppService } from './app.service'; describe('AppController', () => { - let appController: AppController; + let appController: AppController; - beforeEach(async () => { - const app: TestingModule = await Test.createTestingModule({ - controllers: [AppController], - providers: [AppService], - }).compile(); + beforeEach(async () => { + const app: TestingModule = await Test.createTestingModule({ + controllers: [ AppController ], + providers: [ AppService ] + }).compile(); - appController = app.get(AppController); - }); + appController = app.get(AppController); + }); - describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); - }); - }); + describe('root', () => { + it('should return "Healthy!"', () => { + expect(appController.getHello()).toBe('Healthy!'); + }); + }); }); diff --git a/app/api/src/app.service.ts b/app/api/src/app.service.ts index 927d7cc..4e26c97 100644 --- a/app/api/src/app.service.ts +++ b/app/api/src/app.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; @Injectable() export class AppService { - getHello(): string { - return 'Hello World!'; - } + getHello(): string { + return 'Healthy!'; + } } diff --git a/app/api/src/game/game.controller.ts b/app/api/src/game/game.controller.ts index da680d3..bc69b64 100644 --- a/app/api/src/game/game.controller.ts +++ b/app/api/src/game/game.controller.ts @@ -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); } diff --git a/app/api/src/games/games.controller.ts b/app/api/src/games/games.controller.ts index 66614b1..f85014d 100644 --- a/app/api/src/games/games.controller.ts +++ b/app/api/src/games/games.controller.ts @@ -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); - } } diff --git a/app/api/src/games/games.service.ts b/app/api/src/games/games.service.ts index cc16933..aae86f5 100644 --- a/app/api/src/games/games.service.ts +++ b/app/api/src/games/games.service.ts @@ -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; - } } diff --git a/app/api/src/main.ts b/app/api/src/main.ts index 47df213..03b1245 100644 --- a/app/api/src/main.ts +++ b/app/api/src/main.ts @@ -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); diff --git a/app/api/src/player/player.controller.ts b/app/api/src/player/player.controller.ts index 7713ec3..c31a89c 100644 --- a/app/api/src/player/player.controller.ts +++ b/app/api/src/player/player.controller.ts @@ -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); } diff --git a/app/api/src/players/players.controller.ts b/app/api/src/players/players.controller.ts index 6b4dea9..62df7e9 100644 --- a/app/api/src/players/players.controller.ts +++ b/app/api/src/players/players.controller.ts @@ -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); - } } diff --git a/app/api/test/app.e2e-spec.ts b/app/api/test/app.e2e-spec.ts index 50cda62..be73422 100644 --- a/app/api/test/app.e2e-spec.ts +++ b/app/api/test/app.e2e-spec.ts @@ -4,21 +4,18 @@ import * as request from 'supertest'; import { AppModule } from './../src/app.module'; describe('AppController (e2e)', () => { - let app: INestApplication; + let app: INestApplication; - beforeEach(async () => { - const moduleFixture: TestingModule = await Test.createTestingModule({ - imports: [AppModule], - }).compile(); + beforeEach(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [ AppModule ] + }).compile(); - app = moduleFixture.createNestApplication(); - await app.init(); - }); + app = moduleFixture.createNestApplication(); + await app.init(); + }); - it('/ (GET)', () => { - return request(app.getHttpServer()) - .get('/') - .expect(200) - .expect('Hello World!'); - }); + it('/ (GET)', () => { + return request(app.getHttpServer()).get('/').expect(200).expect('Healthy!'); + }); });