diff --git a/apps/api/src/common/static.ts b/apps/api/src/common/static.ts new file mode 100644 index 00000000..e43cd059 --- /dev/null +++ b/apps/api/src/common/static.ts @@ -0,0 +1,3 @@ +export const invalidAuthenticationResponse = { + description: 'Invalid authentication header or API key' +} diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index fc96cfe4..049dedbf 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -97,7 +97,7 @@ async function initializeNestApp() { .setTitle('keyshade') .setDescription('The keyshade API description') .setVersion('1.0') - .addBearerAuth() + .addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }) .addSecurity('api_key', { type: 'apiKey', in: 'header', diff --git a/apps/api/src/user/controller/user.controller.ts b/apps/api/src/user/controller/user.controller.ts index 57503b46..5b3c9c98 100644 --- a/apps/api/src/user/controller/user.controller.ts +++ b/apps/api/src/user/controller/user.controller.ts @@ -23,13 +23,13 @@ import { ApiNoContentResponse, ApiOkResponse, ApiOperation, - ApiResponse, ApiSecurity, ApiTags } from '@nestjs/swagger' import { BypassOnboarding } from '../../decorators/bypass-onboarding.decorator' import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-authorities.decorator' import { ForbidApiKey } from '../../decorators/forbid-api-key.decorator' +import { invalidAuthenticationResponse } from '../../common/static' const userSchema = { type: 'object', @@ -63,9 +63,7 @@ export class UserController { description: 'User details', schema: userSchema }) - @ApiForbiddenResponse({ - description: 'Invalid authentication token or API key' - }) + @ApiForbiddenResponse(invalidAuthenticationResponse) async getCurrentUser(@CurrentUser() user: User) { return this.userService.getSelf(user) } @@ -82,9 +80,7 @@ export class UserController { description: 'Updated user details', schema: userSchema }) - @ApiForbiddenResponse({ - description: 'Invalid authentication token or API key' - }) + @ApiForbiddenResponse(invalidAuthenticationResponse) async updateSelf(@CurrentUser() user: User, @Body() dto: UpdateUserDto) { return await this.userService.updateSelf(user, dto) } @@ -98,11 +94,8 @@ export class UserController { description: 'This endpoint deletes the details of the currently logged in user' }) - @ApiForbiddenResponse({ - description: 'Invalid authentication token' - }) - @ApiResponse({ - status: 204, + @ApiForbiddenResponse(invalidAuthenticationResponse) + @ApiNoContentResponse({ description: 'User deleted successfully' }) async deleteSelf(@CurrentUser() user: User) { diff --git a/apps/api/src/user/dto/create.user/create.user.ts b/apps/api/src/user/dto/create.user/create.user.ts index a1df8137..2b063b34 100644 --- a/apps/api/src/user/dto/create.user/create.user.ts +++ b/apps/api/src/user/dto/create.user/create.user.ts @@ -1,5 +1,5 @@ import { ApiProperty } from '@nestjs/swagger' -import { IsBoolean, IsOptional, IsString } from 'class-validator' +import { IsBoolean, IsEmail, IsOptional, IsString } from 'class-validator' export class CreateUserDto { @IsString() @@ -15,6 +15,7 @@ export class CreateUserDto { name: string @IsString() + @IsEmail() @ApiProperty({ name: 'email', description: 'Email of the user',