feat: configured swagger
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
|
||||
export function setupSwagger(app: INestApplication) {
|
||||
const swaggerConfig = new DocumentBuilder()
|
||||
.setTitle('Governorate API Document')
|
||||
.setDescription('The Governorate API description')
|
||||
.addBearerAuth(
|
||||
{
|
||||
type: 'http',
|
||||
scheme: 'bearer',
|
||||
bearerFormat: 'JWT',
|
||||
name: 'authorization',
|
||||
in: 'header',
|
||||
},
|
||||
'authorization',
|
||||
)
|
||||
.setVersion('1.0.0')
|
||||
.build();
|
||||
|
||||
const swaggerDocument = SwaggerModule.createDocument(app, swaggerConfig);
|
||||
SwaggerModule.setup('api-docs', app, swaggerDocument, {
|
||||
customSiteTitle: 'Governorate API Doc',
|
||||
swaggerOptions: {
|
||||
persistAuthorization: true,
|
||||
displayRequestDuration: true,
|
||||
filter: true,
|
||||
showExtensions: true,
|
||||
docExpansion: 'none',
|
||||
defaultModelsExpandDepth: -1,
|
||||
defaultModelExpandDepth: -1,
|
||||
},
|
||||
});
|
||||
}
|
||||
+4
-1
@@ -1,6 +1,7 @@
|
||||
import { NestFactory, Reflector } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { ClassSerializerInterceptor, ValidationPipe } from '@nestjs/common';
|
||||
import { setupSwagger } from './config/swagger.config';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
@@ -17,7 +18,9 @@ async function bootstrap() {
|
||||
|
||||
app.useGlobalInterceptors(
|
||||
new ClassSerializerInterceptor(app.get(Reflector))
|
||||
)
|
||||
);
|
||||
|
||||
setupSwagger(app);
|
||||
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import {
|
||||
IsEmail,
|
||||
@@ -9,25 +10,30 @@ import {
|
||||
} from 'class-validator';
|
||||
|
||||
export class CreateUserDto {
|
||||
@ApiProperty({ example: 'Mahdi' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@MaxLength(20)
|
||||
firstName: string;
|
||||
|
||||
@ApiProperty({ example: 'Rafie' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
lastName: string;
|
||||
@MaxLength(20)
|
||||
|
||||
@ApiProperty({ example: 'mahdirafie@gmail.com' })
|
||||
@MaxLength(20)
|
||||
@IsEmail()
|
||||
@MaxLength(100)
|
||||
email: string;
|
||||
|
||||
@ApiProperty({ example: '09123456789' })
|
||||
@Matches(/^09\d{9}$/, {
|
||||
message: 'Phone number must be a valid Iranian mobile number.',
|
||||
})
|
||||
phone: string;
|
||||
|
||||
@ApiProperty({ example: 'MahdiPassword@5!' })
|
||||
@IsString()
|
||||
@MinLength(8)
|
||||
@Exclude()
|
||||
|
||||
Reference in New Issue
Block a user