Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created April 1, 2021 10:18
Show Gist options
  • Save MohammedALREAI/b88c984a9efefb9e7dc553633d24956b to your computer and use it in GitHub Desktop.
Save MohammedALREAI/b88c984a9efefb9e7dc553633d24956b to your computer and use it in GitHub Desktop.
swiger setup and make in the controller
import { INestApplication } from '@nestjs/common';
import { DocumentBuilder, OpenAPIObject, SwaggerModule } from '@nestjs/swagger';
import { SWAGGER_CONFIG } from './swagger.config';
export function createDocument(app: INestApplication): OpenAPIObject {
const builder = new DocumentBuilder()
.setTitle(SWAGGER_CONFIG.title)
.setDescription(SWAGGER_CONFIG.description)
.addBearerAuth({ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' }, 'access-token')
.setVersion(SWAGGER_CONFIG.version);
for (const tag of SWAGGER_CONFIG.tags) {
builder.addTag(tag);
}
const options = builder.build();
return SwaggerModule.createDocument(app, options);
}
//controller
@ApiTags("Auth")
@HttpCode(HttpStatus.ACCEPTED)
@ApiOperation({description:"get getUserMainData "})
@ApiResponse({description:"Ok"})
@ApiBadRequestResponse({description:"bad Request with verification "})
@ApiInternalServerErrorResponse({description:"data has been send but there is issiue in server so try later "})
@Get('user-main-data')
@UseGuards(AuthGuard('jwt'), AcceptedAuthGuard)
@Roles([Role.USER, Role.ADMIN])
getUserData(@GetAuthenticatedUser() user: User) {
return this.authService.getUserMainData(user);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment