This commit is contained in:
2026-07-02 20:11:44 +03:30
parent d20e5be9c8
commit 6b3327ee16
21 changed files with 262 additions and 7 deletions
@@ -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 })] : []),
);
}
+33
View File
@@ -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',
},
});
}