Skip to content

Commit

Permalink
chore: Remove swagger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratnesh2003 committed May 15, 2024
1 parent 90be033 commit 1e9d5bb
Show file tree
Hide file tree
Showing 12 changed files with 0 additions and 302 deletions.
120 changes: 0 additions & 120 deletions apps/api/src/api-key/controller/api-key.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ import { CreateApiKey } from '../dto/create.api-key/create.api-key'
import { UpdateApiKey } from '../dto/update.api-key/update.api-key'
import { Authority, User } from '@prisma/client'
import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-authorities.decorator'
import {
ApiBearerAuth,
ApiCreatedResponse,
ApiForbiddenResponse,
ApiNoContentResponse,
ApiOkResponse,
ApiOperation,
ApiParam,
ApiQuery,
ApiSecurity,
ApiTags
} from '@nestjs/swagger'
import { invalidAuthenticationResponse } from '../../common/static'

Check warning on line 18 in apps/api/src/api-key/controller/api-key.controller.ts

View workflow job for this annotation

GitHub Actions / Validate API

'invalidAuthenticationResponse' is defined but never used

const baseProperties = {
Expand All @@ -52,44 +40,17 @@ const apiKeySchema = {
}

@Controller('api-key')
@ApiBearerAuth()
@ApiSecurity('api_key')
@ApiTags('API Key Controller')
export class ApiKeyController {
constructor(private readonly apiKeyService: ApiKeyService) {}

@Post()
@RequiredApiKeyAuthorities(Authority.CREATE_API_KEY)
@ApiOperation({
summary: 'Create API key',
description: 'This endpoint creates a new API key'
})
@ApiCreatedResponse({
schema: apiKeySchemaWithValue,
description: 'API key created successfully'
})
@ApiForbiddenResponse(invalidAuthenticationResponse)
async createApiKey(@CurrentUser() user: User, @Body() dto: CreateApiKey) {
return this.apiKeyService.createApiKey(user, dto)
}

@Put(':id')
@RequiredApiKeyAuthorities(Authority.UPDATE_API_KEY)
@ApiOperation({
summary: 'Update API key',
description: 'This endpoint updates an existing API key'
})
@ApiParam({
name: 'id',
description: 'API key ID',
required: true,
schema: { type: 'string' }
})
@ApiOkResponse({
schema: apiKeySchema,
description: 'API key updated successfully'
})
@ApiForbiddenResponse(invalidAuthenticationResponse)
async updateApiKey(
@CurrentUser() user: User,
@Body() dto: UpdateApiKey,
Expand All @@ -101,99 +62,18 @@ export class ApiKeyController {
@Delete(':id')
@RequiredApiKeyAuthorities(Authority.DELETE_API_KEY)
@HttpCode(204)
@ApiOperation({
summary: 'Delete API key',
description: 'This endpoint deletes an existing API key'
})
@ApiParam({
name: 'id',
description: 'API key ID',
required: true,
schema: { type: 'string' }
})
@ApiNoContentResponse({
description: 'API key deleted successfully'
})
@ApiForbiddenResponse(invalidAuthenticationResponse)
async deleteApiKey(@CurrentUser() user: User, @Param('id') id: string) {
return this.apiKeyService.deleteApiKey(user, id)
}

@Get(':id')
@RequiredApiKeyAuthorities(Authority.READ_API_KEY)
@ApiOperation({
summary: 'Get API key',
description: 'This endpoint returns the details of an API key'
})
@ApiParam({
name: 'id',
description: 'API key ID',
required: true,
schema: { type: 'string' }
})
@ApiOkResponse({
schema: apiKeySchemaWithValue,
description: 'API key details'
})
@ApiForbiddenResponse(invalidAuthenticationResponse)
async getApiKey(@CurrentUser() user: User, @Param('id') id: string) {
return this.apiKeyService.getApiKeyById(user, id)
}

@Get('all')
@RequiredApiKeyAuthorities(Authority.READ_API_KEY)
@ApiOperation({
summary: 'Get all API keys',
description: 'This endpoint returns all API keys of the user'
})
@ApiQuery({
name: 'page',
description: 'Page number',
required: false,
type: Number,
example: 1,
allowEmptyValue: false
})
@ApiQuery({
name: 'limit',
description: 'Number of items per page',
required: false,
type: Number,
example: 10,
allowEmptyValue: false
})
@ApiQuery({
name: 'sort',
description: 'Sort by field',
required: false,
type: String,
example: 'name',
allowEmptyValue: false
})
@ApiQuery({
name: 'order',
description: 'Sort order',
required: false,
type: String,
example: 'asc',
allowEmptyValue: false
})
@ApiQuery({
name: 'search',
description: 'Search by name',
required: false,
type: String,
example: 'My API Key',
allowEmptyValue: false
})
@ApiOkResponse({
schema: {
type: 'array',
items: apiKeySchema
},
description: 'API keys'
})
@ApiForbiddenResponse(invalidAuthenticationResponse)
async getApiKeysOfUser(
@CurrentUser() user: User,
@Query('page') page: number = 0,
Expand Down
24 changes: 0 additions & 24 deletions apps/api/src/api-key/dto/create.api-key/create.api-key.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,15 @@
import { ApiProperty } from '@nestjs/swagger'
import { ApiKey, Authority } from '@prisma/client'
import { IsArray, IsOptional, IsString } from 'class-validator'

export class CreateApiKey {
@IsString()
@ApiProperty({
name: 'name',
description: 'Name of the API key',
required: true,
type: String,
example: 'My API Key'
})
name: ApiKey['name']

@IsString()
@IsOptional()
@ApiProperty({
name: 'expiresAfter',
description: 'API key expiration time in hours',
required: false,
type: String,
example: '24',
default: 'never'
})
expiresAfter?: '24' | '168' | '720' | '8760' | 'never' = 'never'

@IsArray()
@IsOptional()
@ApiProperty({
name: 'authorities',
description: 'API key authorities',
required: false,
type: [String],
example: ['READ_SELF', 'UPDATE_SELF'],
default: []
})
authorities?: Authority[] = []
}
2 changes: 0 additions & 2 deletions apps/api/src/app/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Controller, Get } from '@nestjs/common'
import { Public } from '../decorators/public.decorator'
import { ApiTags } from '@nestjs/swagger'

@ApiTags('App Controller')
@Controller()
export class AppController {
@Get('health')
Expand Down
108 changes: 0 additions & 108 deletions apps/api/src/auth/controller/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import {
} from '@nestjs/common'
import { AuthService } from '../service/auth.service'
import { Public } from '../../decorators/public.decorator'
import {
ApiOperation,
ApiParam,
ApiQuery,
ApiResponse,
ApiTags
} from '@nestjs/swagger'
import { AuthGuard } from '@nestjs/passport'
import { GithubOAuthStrategyFactory } from '../../config/factory/github/github-strategy.factory'
import { GoogleOAuthStrategyFactory } from '../../config/factory/google/google-strategy.factory'
Expand All @@ -33,7 +26,6 @@ import {
sendOAuthSuccessRedirect
} from '../../common/redirect'

@ApiTags('Auth Controller')
@Controller('auth')
export class AuthController {
private readonly logger = new Logger(AuthController.name)
Expand All @@ -47,24 +39,6 @@ export class AuthController {

@Public()
@Post('send-otp/:email')
@ApiOperation({
summary: 'Send OTP',
description:
'This endpoint sends OTPs to an email address. The OTP can then be used to generate valid tokens'
})
@ApiParam({
name: 'email',
description: 'Email to send OTP',
required: true
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Send OTP successfully'
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Email is invalid'
})
async sendOtp(
@Param('email')
email: string
Expand All @@ -75,33 +49,6 @@ export class AuthController {
/* istanbul ignore next */
@Public()
@Post('validate-otp')
@ApiOperation({
summary: 'Validate OTP',
description:
'This endpoint validates OTPs. If the OTP is valid, it returns a valid token along with the user details'
})
@ApiQuery({
name: 'email',
description: 'Email to send OTP',
required: true
})
@ApiQuery({
name: 'otp',
description: 'OTP to validate',
required: true
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Validate OTP successfully'
})
@ApiResponse({
status: HttpStatus.NOT_FOUND,
description: 'Email not found'
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: 'OTP is invalid'
})
async validateOtp(
@Query('email') email: string,
@Query('otp') otp: string,
Expand All @@ -113,11 +60,6 @@ export class AuthController {
/* istanbul ignore next */
@Public()
@Get('github')
@ApiOperation({
summary: 'Github OAuth',
description:
'This endpoint validates Github OAuth. If the OAuth is valid, it returns a valid token along with the user details'
})
async githubOAuthLogin(@Res() res: Response) {
if (!this.githubOAuthStrategyFactory.isOAuthEnabled()) {
throw new HttpException(
Expand All @@ -133,20 +75,6 @@ export class AuthController {
@Public()
@Get('github/callback')
@UseGuards(AuthGuard('github'))
@ApiOperation({
summary: 'Github OAuth Callback',
description:
'This endpoint validates Github OAuth. If the OAuth is valid, it returns a valid token along with the user details'
})
@ApiParam({
name: 'code',
description: 'Code for the Callback',
required: true
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Logged in successfully'
})
async githubOAuthCallback(@Req() req: any) {
const { emails, displayName: name, photos } = req.user

Expand All @@ -169,11 +97,6 @@ export class AuthController {
/* istanbul ignore next */
@Public()
@Get('gitlab')
@ApiOperation({
summary: 'Gitlab OAuth',
description:
'This endpoint validates Gitlab OAuth. If the OAuth is valid, it returns a valid token along with the user details'
})
async gitlabOAuthLogin(@Res() res: Response) {
if (!this.gitlabOAuthStrategyFactory.isOAuthEnabled()) {
throw new HttpException(
Expand All @@ -189,20 +112,6 @@ export class AuthController {
@Public()
@Get('gitlab/callback')
@UseGuards(AuthGuard('gitlab'))
@ApiOperation({
summary: 'Gitlab OAuth Callback',
description:
'This endpoint validates Gitlab OAuth. If the OAuth is valid, it returns a valid token along with the user details'
})
@ApiParam({
name: 'code',
description: 'Code for the Callback',
required: true
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Logged in successfully'
})
async gitlabOAuthCallback(@Req() req: any, @Res() res: Response) {
const { emails, displayName: name, avatarUrl: profilePictureUrl } = req.user

Expand All @@ -225,10 +134,6 @@ export class AuthController {
/* istanbul ignore next */
@Public()
@Get('google')
@ApiOperation({
summary: 'Google OAuth',
description: 'Initiates Google OAuth'
})
async googleOAuthLogin(@Res() res: Response) {
if (!this.googleOAuthStrategyFactory.isOAuthEnabled()) {
throw new HttpException(
Expand All @@ -244,19 +149,6 @@ export class AuthController {
@Public()
@Get('google/callback')
@UseGuards(AuthGuard('google'))
@ApiOperation({
summary: 'Google OAuth Callback',
description: 'Handles Google OAuth callback'
})
@ApiParam({
name: 'code',
description: 'Code for the Callback',
required: true
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Logged in successfully'
})
async googleOAuthCallback(@Req() req: any, @Res() res: Response) {
const { emails, displayName: name, photos } = req.user

Expand Down
Loading

0 comments on commit 1e9d5bb

Please sign in to comment.