docs: improved auto-generated openapi docs

With these additional annotations the openapi docs under `/apidoc` and `/private/apidoc` will be improved by adding errors that the requests can return

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2022-01-17 11:35:57 +01:00
parent 2bc8c0d6da
commit 796b8294cf
10 changed files with 183 additions and 34 deletions

View file

@ -14,7 +14,11 @@ import {
UnauthorizedException,
UseGuards,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import {
ApiNotFoundResponse,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { AuthTokenWithSecretDto } from '../../../auth/auth-token-with-secret.dto';
import { AuthTokenDto } from '../../../auth/auth-token.dto';
@ -23,6 +27,10 @@ import { SessionGuard } from '../../../identity/session.guard';
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
import { User } from '../../../users/user.entity';
import { TimestampMillis } from '../../../utils/timestamp';
import {
notFoundDescription,
unauthorizedDescription,
} from '../../utils/descriptions';
import { RequestUser } from '../../utils/request-user.decorator';
@UseGuards(SessionGuard)
@ -37,6 +45,7 @@ export class TokensController {
}
@Get()
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
async getUserTokens(@RequestUser() user: User): Promise<AuthTokenDto[]> {
return (await this.authService.getTokensByUser(user)).map((token) =>
this.authService.toAuthTokenDto(token),
@ -44,6 +53,7 @@ export class TokensController {
}
@Post()
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
async postTokenRequest(
@Body('label') label: string,
@Body('validUntil') validUntil: TimestampMillis,
@ -54,6 +64,8 @@ export class TokensController {
@Delete('/:keyId')
@HttpCode(204)
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
@ApiNotFoundResponse({ description: notFoundDescription })
async deleteToken(
@RequestUser() user: User,
@Param('keyId') keyId: string,