From a1b2f2cd7850f3f744c147260b0a55d26659cfd6 Mon Sep 17 00:00:00 2001 From: Anthony Mineo Date: Sat, 29 Aug 2020 19:10:50 -0400 Subject: [PATCH] Enable swagger --- app/api/package.json | 12 ++++++++---- app/api/src/game/game.controller.ts | 3 +++ app/api/src/game/game.service.ts | 3 ++- app/api/src/main.ts | 12 ++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/api/package.json b/app/api/package.json index fe7a641..8bd3f33 100644 --- a/app/api/package.json +++ b/app/api/package.json @@ -1,8 +1,12 @@ { - "name": "api", + "name": "playt2-stats-api", "version": "0.0.1", - "description": "", - "author": "", + "description": "Open-API powering stats.playt2.com", + "authors": { + "name": "Anthony Mineo", + "email": "anthonymineo@gmail.com", + "url": "https://anthonymineo.com" + }, "private": true, "license": "UNLICENSED", "scripts": { @@ -75,4 +79,4 @@ "coverageDirectory": "../coverage", "testEnvironment": "node" } -} +} \ No newline at end of file diff --git a/app/api/src/game/game.controller.ts b/app/api/src/game/game.controller.ts index cd06242..da680d3 100644 --- a/app/api/src/game/game.controller.ts +++ b/app/api/src/game/game.controller.ts @@ -1,4 +1,6 @@ import { Controller, Get, Param } from '@nestjs/common'; +import { ApiOperation } from '@nestjs/swagger'; + import { GameService } from './game.service'; @Controller('game') @@ -7,6 +9,7 @@ export class GameController { // /games/:gameId @Get(':gameId') + @ApiOperation({ summary: 'Find game by Id' }) findOne(@Param('gameId') gameId: string) { return this.gameService.findOne(gameId); } diff --git a/app/api/src/game/game.service.ts b/app/api/src/game/game.service.ts index b9948a9..aa981ef 100644 --- a/app/api/src/game/game.service.ts +++ b/app/api/src/game/game.service.ts @@ -20,7 +20,8 @@ export class GameService { relations: [ 'game', 'playerGuid' ], where: [ { game: { gameId: gameId } } ] }); - if (!query) { + + if (!query.length) { throw new NotFoundException(`Game ID: ${gameId} not found`); } diff --git a/app/api/src/main.ts b/app/api/src/main.ts index c2cd8b5..47df213 100644 --- a/app/api/src/main.ts +++ b/app/api/src/main.ts @@ -1,5 +1,7 @@ import { NestFactory } from '@nestjs/core'; import { ValidationPipe } from '@nestjs/common'; +import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; + import { AppModule } from './app.module'; async function bootstrap() { @@ -16,6 +18,16 @@ async function bootstrap() { }) ); + const swaggerOptions = new DocumentBuilder() + .setTitle('Tribes 2 Stats API') + .setDescription('Powering stats.playt2.com') + .setVersion('1.0') + .addTag('task') + .build(); + + const document = SwaggerModule.createDocument(app, swaggerOptions); + SwaggerModule.setup('api', app, document); + await app.listen(3000); } bootstrap();