From 1e9d5bb5f2d2c4612e077fdd59a9654197d99c93 Mon Sep 17 00:00:00 2001 From: Ratnesh Mishra Date: Wed, 15 May 2024 17:04:10 +0530 Subject: [PATCH 1/2] chore: Remove swagger docs --- .../api-key/controller/api-key.controller.ts | 120 ------------------ .../dto/create.api-key/create.api-key.ts | 24 ---- apps/api/src/app/app.controller.ts | 2 - .../src/auth/controller/auth.controller.ts | 108 ---------------- .../controller/environment.controller.ts | 2 - .../src/event/controller/event.controller.ts | 2 - .../controller/feedback.controller.ts | 22 ---- .../controller/integration.controller.ts | 2 - apps/api/src/main.ts | 14 -- .../project/controller/project.controller.ts | 2 - .../secret/controller/secret.controller.ts | 2 - .../controller/variable.controller.ts | 2 - 12 files changed, 302 deletions(-) diff --git a/apps/api/src/api-key/controller/api-key.controller.ts b/apps/api/src/api-key/controller/api-key.controller.ts index f26d1b91..f30fd940 100644 --- a/apps/api/src/api-key/controller/api-key.controller.ts +++ b/apps/api/src/api-key/controller/api-key.controller.ts @@ -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' const baseProperties = { @@ -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, @@ -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, diff --git a/apps/api/src/api-key/dto/create.api-key/create.api-key.ts b/apps/api/src/api-key/dto/create.api-key/create.api-key.ts index b1537848..c256390b 100644 --- a/apps/api/src/api-key/dto/create.api-key/create.api-key.ts +++ b/apps/api/src/api-key/dto/create.api-key/create.api-key.ts @@ -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[] = [] } diff --git a/apps/api/src/app/app.controller.ts b/apps/api/src/app/app.controller.ts index 17d71021..bef73e44 100644 --- a/apps/api/src/app/app.controller.ts +++ b/apps/api/src/app/app.controller.ts @@ -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') diff --git a/apps/api/src/auth/controller/auth.controller.ts b/apps/api/src/auth/controller/auth.controller.ts index d57df72c..262c2b49 100644 --- a/apps/api/src/auth/controller/auth.controller.ts +++ b/apps/api/src/auth/controller/auth.controller.ts @@ -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' @@ -33,7 +26,6 @@ import { sendOAuthSuccessRedirect } from '../../common/redirect' -@ApiTags('Auth Controller') @Controller('auth') export class AuthController { private readonly logger = new Logger(AuthController.name) @@ -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 @@ -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, @@ -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( @@ -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 @@ -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( @@ -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 @@ -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( @@ -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 diff --git a/apps/api/src/environment/controller/environment.controller.ts b/apps/api/src/environment/controller/environment.controller.ts index ad2f6b7d..57e894ab 100644 --- a/apps/api/src/environment/controller/environment.controller.ts +++ b/apps/api/src/environment/controller/environment.controller.ts @@ -13,11 +13,9 @@ import { CurrentUser } from '../../decorators/user.decorator' import { CreateEnvironment } from '../dto/create.environment/create.environment' import { Authority, User } from '@prisma/client' import { UpdateEnvironment } from '../dto/update.environment/update.environment' -import { ApiTags } from '@nestjs/swagger' import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-authorities.decorator' import { AlphanumericReasonValidationPipe } from '../../common/alphanumeric-reason-pipe' -@ApiTags('Environment Controller') @Controller('environment') export class EnvironmentController { constructor(private readonly environmentService: EnvironmentService) {} diff --git a/apps/api/src/event/controller/event.controller.ts b/apps/api/src/event/controller/event.controller.ts index ac05401b..71e895f4 100644 --- a/apps/api/src/event/controller/event.controller.ts +++ b/apps/api/src/event/controller/event.controller.ts @@ -3,9 +3,7 @@ import { EventService } from '../service/event.service' import { Authority, EventSeverity, EventSource, User } from '@prisma/client' import { CurrentUser } from '../../decorators/user.decorator' import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-authorities.decorator' -import { ApiTags } from '@nestjs/swagger' -@ApiTags('event') @Controller('event') export class EventController { constructor(private readonly eventService: EventService) {} diff --git a/apps/api/src/feedback/controller/feedback.controller.ts b/apps/api/src/feedback/controller/feedback.controller.ts index ed448e96..2b587975 100644 --- a/apps/api/src/feedback/controller/feedback.controller.ts +++ b/apps/api/src/feedback/controller/feedback.controller.ts @@ -1,35 +1,13 @@ import { Controller, Post, Body, HttpStatus } from '@nestjs/common' import { Public } from '../../decorators/public.decorator' import { FeedbackService } from '../service/feedback.service' -import { ApiTags, ApiBody, ApiResponse, ApiOperation } from '@nestjs/swagger' -@ApiTags('Feedback Controller') @Controller('feedback') export class FeedbackController { constructor(private readonly feedbackService: FeedbackService) {} @Public() @Post() - @ApiOperation({ - summary: 'Send Feedback message to Admin', - description: 'This endpoint sends a feedback message to the Admin email.' - }) - @ApiBody({ - schema: { - type: 'object', - properties: { - feedback: { - type: 'string', - example: 'Your feedback message here' - } - } - } - }) - @ApiResponse({ - status: HttpStatus.CREATED, - description: 'Feedback registered successfully' - }) - @ApiResponse({ status: HttpStatus.BAD_REQUEST, description: 'Bad Request' }) async registerFeedback( @Body() feedbackData: { feedback: string } ): Promise { diff --git a/apps/api/src/integration/controller/integration.controller.ts b/apps/api/src/integration/controller/integration.controller.ts index c29fc40c..ef6abd6e 100644 --- a/apps/api/src/integration/controller/integration.controller.ts +++ b/apps/api/src/integration/controller/integration.controller.ts @@ -9,7 +9,6 @@ import { Query } from '@nestjs/common' import { IntegrationService } from '../service/integration.service' -import { ApiTags } from '@nestjs/swagger' import { CurrentUser } from '../../decorators/user.decorator' import { CreateIntegration } from '../dto/create.integration/create.integration' import { Authority, User } from '@prisma/client' @@ -17,7 +16,6 @@ import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-aut import { UpdateIntegration } from '../dto/update.integration/update.integration' @Controller('integration') -@ApiTags('Integration Controller') export class IntegrationController { constructor(private readonly integrationService: IntegrationService) {} diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index a9f22172..22b95df9 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -8,7 +8,6 @@ import { NestFactory } from '@nestjs/core' import { AppModule } from './app/app.module' import { QueryTransformPipe } from './common/query.transform.pipe' -import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger' import * as Sentry from '@sentry/node' import { ProfilingIntegration } from '@sentry/profiling-node' import { RedisIoAdapter } from './socket/redis.adapter' @@ -85,19 +84,6 @@ async function initializeNestApp() { }) app.use(cookieParser()) const port = process.env.API_PORT || 4200 - const swaggerConfig = new DocumentBuilder() - .setTitle('keyshade') - .setDescription('The keyshade API description') - .setVersion('1.0') - .addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }) - .addSecurity('api_key', { - type: 'apiKey', - in: 'header', - name: 'x-keyshade-token' - }) - .build() - const document = SwaggerModule.createDocument(app, swaggerConfig) - SwaggerModule.setup('docs', app, document) app.use(Sentry.Handlers.errorHandler()) await app.listen(port) logger.log( diff --git a/apps/api/src/project/controller/project.controller.ts b/apps/api/src/project/controller/project.controller.ts index eb1b3044..4cb271e5 100644 --- a/apps/api/src/project/controller/project.controller.ts +++ b/apps/api/src/project/controller/project.controller.ts @@ -13,11 +13,9 @@ import { CurrentUser } from '../../decorators/user.decorator' import { Authority, Project, User, Workspace } from '@prisma/client' import { CreateProject } from '../dto/create.project/create.project' import { UpdateProject } from '../dto/update.project/update.project' -import { ApiTags } from '@nestjs/swagger' import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-authorities.decorator' import { AlphanumericReasonValidationPipe } from '../../common/alphanumeric-reason-pipe' -@ApiTags('Project Controller') @Controller('project') export class ProjectController { constructor(private readonly service: ProjectService) {} diff --git a/apps/api/src/secret/controller/secret.controller.ts b/apps/api/src/secret/controller/secret.controller.ts index 0f71e330..3fa82476 100644 --- a/apps/api/src/secret/controller/secret.controller.ts +++ b/apps/api/src/secret/controller/secret.controller.ts @@ -13,11 +13,9 @@ import { CurrentUser } from '../../decorators/user.decorator' import { Authority, User } from '@prisma/client' import { CreateSecret } from '../dto/create.secret/create.secret' import { UpdateSecret } from '../dto/update.secret/update.secret' -import { ApiTags } from '@nestjs/swagger' import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-authorities.decorator' import { AlphanumericReasonValidationPipe } from '../../common/alphanumeric-reason-pipe' -@ApiTags('Secret Controller') @Controller('secret') export class SecretController { constructor(private readonly secretService: SecretService) {} diff --git a/apps/api/src/variable/controller/variable.controller.ts b/apps/api/src/variable/controller/variable.controller.ts index 3bd8ca90..895145f6 100644 --- a/apps/api/src/variable/controller/variable.controller.ts +++ b/apps/api/src/variable/controller/variable.controller.ts @@ -8,7 +8,6 @@ import { Put, Query } from '@nestjs/common' -import { ApiTags } from '@nestjs/swagger' import { VariableService } from '../service/variable.service' import { RequiredApiKeyAuthorities } from '../../decorators/required-api-key-authorities.decorator' import { Authority, User } from '@prisma/client' @@ -16,7 +15,6 @@ import { AlphanumericReasonValidationPipe } from '../../common/alphanumeric-reas import { CurrentUser } from '../../decorators/user.decorator' import { CreateVariable } from '../dto/create.variable/create.variable' -@ApiTags('Variable Controller') @Controller('variable') export class VariableController { constructor(private readonly variableService: VariableService) {} From 0f694b4eeb326312e6fc73542f02ca63bb678c49 Mon Sep 17 00:00:00 2001 From: Ratnesh Mishra Date: Wed, 15 May 2024 21:27:07 +0530 Subject: [PATCH 2/2] chore: Remove unused imports --- apps/api/src/api-key/controller/api-key.controller.ts | 1 - apps/api/src/feedback/controller/feedback.controller.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/api/src/api-key/controller/api-key.controller.ts b/apps/api/src/api-key/controller/api-key.controller.ts index f30fd940..e9d2d40c 100644 --- a/apps/api/src/api-key/controller/api-key.controller.ts +++ b/apps/api/src/api-key/controller/api-key.controller.ts @@ -15,7 +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 { invalidAuthenticationResponse } from '../../common/static' const baseProperties = { id: { type: 'string' }, diff --git a/apps/api/src/feedback/controller/feedback.controller.ts b/apps/api/src/feedback/controller/feedback.controller.ts index 2b587975..bac648da 100644 --- a/apps/api/src/feedback/controller/feedback.controller.ts +++ b/apps/api/src/feedback/controller/feedback.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Post, Body, HttpStatus } from '@nestjs/common' +import { Controller, Post, Body } from '@nestjs/common' import { Public } from '../../decorators/public.decorator' import { FeedbackService } from '../service/feedback.service'