swagger
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { applyDecorators } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||
import { SWAGGER_JWT_AUTH } from '../swagger.setup';
|
||||
|
||||
export function ApiPublicEndpoint(summary?: string) {
|
||||
return applyDecorators(
|
||||
ApiOperation({
|
||||
summary,
|
||||
security: [],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function ApiProtectedEndpoint(summary?: string) {
|
||||
return applyDecorators(
|
||||
ApiBearerAuth(SWAGGER_JWT_AUTH),
|
||||
...(summary ? [ApiOperation({ summary })] : []),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
|
||||
export const SWAGGER_JWT_AUTH = 'access-token';
|
||||
|
||||
export function setupSwagger(app: INestApplication): void {
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('Grow API')
|
||||
.setDescription('BeautyBook Grow API documentation')
|
||||
.setVersion('1.0')
|
||||
.addBearerAuth(
|
||||
{
|
||||
type: 'http',
|
||||
scheme: 'bearer',
|
||||
bearerFormat: 'JWT',
|
||||
description: 'JWT access token obtained from POST /api/auth/otp/verify',
|
||||
},
|
||||
SWAGGER_JWT_AUTH,
|
||||
)
|
||||
.build();
|
||||
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
|
||||
SwaggerModule.setup('docs', app, document, {
|
||||
jsonDocumentUrl: 'docs-json',
|
||||
yamlDocumentUrl: 'docs-yaml',
|
||||
swaggerOptions: {
|
||||
persistAuthorization: true,
|
||||
tagsSorter: 'alpha',
|
||||
operationsSorter: 'alpha',
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user