feat: configured swagger
This commit is contained in:
+4
-4
@@ -20,10 +20,10 @@
|
|||||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nestjs/common": "^11.0.1",
|
"@nestjs/common": "^11.1.28",
|
||||||
"@nestjs/config": "^4.0.4",
|
"@nestjs/config": "^4.0.4",
|
||||||
"@nestjs/core": "^11.0.1",
|
"@nestjs/core": "^11.1.28",
|
||||||
"@nestjs/platform-express": "^11.0.1",
|
"@nestjs/platform-express": "^11.1.28",
|
||||||
"@nestjs/swagger": "^11.4.6",
|
"@nestjs/swagger": "^11.4.6",
|
||||||
"@nestjs/typeorm": "^11.0.3",
|
"@nestjs/typeorm": "^11.0.3",
|
||||||
"bcrypt": "^6.0.0",
|
"bcrypt": "^6.0.0",
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
"@eslint/js": "^9.18.0",
|
"@eslint/js": "^9.18.0",
|
||||||
"@nestjs/cli": "^11.0.0",
|
"@nestjs/cli": "^11.0.0",
|
||||||
"@nestjs/schematics": "^11.0.0",
|
"@nestjs/schematics": "^11.0.0",
|
||||||
"@nestjs/testing": "^11.0.1",
|
"@nestjs/testing": "^11.1.28",
|
||||||
"@types/bcrypt": "^6.0.0",
|
"@types/bcrypt": "^6.0.0",
|
||||||
"@types/express": "^5.0.0",
|
"@types/express": "^5.0.0",
|
||||||
"@types/jest": "^30.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
|
|||||||
Generated
+4
-4
@@ -9,16 +9,16 @@ importers:
|
|||||||
.:
|
.:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@nestjs/common':
|
'@nestjs/common':
|
||||||
specifier: ^11.0.1
|
specifier: ^11.1.28
|
||||||
version: 11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
version: 11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||||
'@nestjs/config':
|
'@nestjs/config':
|
||||||
specifier: ^4.0.4
|
specifier: ^4.0.4
|
||||||
version: 4.0.4(@nestjs/common@11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(rxjs@7.8.2)
|
version: 4.0.4(@nestjs/common@11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(rxjs@7.8.2)
|
||||||
'@nestjs/core':
|
'@nestjs/core':
|
||||||
specifier: ^11.0.1
|
specifier: ^11.1.28
|
||||||
version: 11.1.28(@nestjs/common@11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.28)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
version: 11.1.28(@nestjs/common@11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/platform-express@11.1.28)(reflect-metadata@0.2.2)(rxjs@7.8.2)
|
||||||
'@nestjs/platform-express':
|
'@nestjs/platform-express':
|
||||||
specifier: ^11.0.1
|
specifier: ^11.1.28
|
||||||
version: 11.1.28(@nestjs/common@11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.28)
|
version: 11.1.28(@nestjs/common@11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.28)
|
||||||
'@nestjs/swagger':
|
'@nestjs/swagger':
|
||||||
specifier: ^11.4.6
|
specifier: ^11.4.6
|
||||||
@@ -64,7 +64,7 @@ importers:
|
|||||||
specifier: ^11.0.0
|
specifier: ^11.0.0
|
||||||
version: 11.1.0(chokidar@4.0.3)(prettier@3.9.5)(typescript@5.9.3)
|
version: 11.1.0(chokidar@4.0.3)(prettier@3.9.5)(typescript@5.9.3)
|
||||||
'@nestjs/testing':
|
'@nestjs/testing':
|
||||||
specifier: ^11.0.1
|
specifier: ^11.1.28
|
||||||
version: 11.1.28(@nestjs/common@11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.28)(@nestjs/platform-express@11.1.28)
|
version: 11.1.28(@nestjs/common@11.1.28(class-transformer@0.5.1)(class-validator@0.15.1)(reflect-metadata@0.2.2)(rxjs@7.8.2))(@nestjs/core@11.1.28)(@nestjs/platform-express@11.1.28)
|
||||||
'@types/bcrypt':
|
'@types/bcrypt':
|
||||||
specifier: ^6.0.0
|
specifier: ^6.0.0
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
allowBuilds:
|
allowBuilds:
|
||||||
'@scarf/scarf': set this to true or false
|
'@scarf/scarf': false
|
||||||
bcrypt: set this to true or false
|
bcrypt: false
|
||||||
unrs-resolver: false
|
unrs-resolver: false
|
||||||
|
|||||||
@@ -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 { NestFactory, Reflector } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import { ClassSerializerInterceptor, ValidationPipe } from '@nestjs/common';
|
import { ClassSerializerInterceptor, ValidationPipe } from '@nestjs/common';
|
||||||
|
import { setupSwagger } from './config/swagger.config';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
@@ -17,7 +18,9 @@ async function bootstrap() {
|
|||||||
|
|
||||||
app.useGlobalInterceptors(
|
app.useGlobalInterceptors(
|
||||||
new ClassSerializerInterceptor(app.get(Reflector))
|
new ClassSerializerInterceptor(app.get(Reflector))
|
||||||
)
|
);
|
||||||
|
|
||||||
|
setupSwagger(app);
|
||||||
|
|
||||||
await app.listen(process.env.PORT ?? 3000);
|
await app.listen(process.env.PORT ?? 3000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Exclude } from 'class-transformer';
|
import { Exclude } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
IsEmail,
|
IsEmail,
|
||||||
@@ -9,25 +10,30 @@ import {
|
|||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
|
|
||||||
export class CreateUserDto {
|
export class CreateUserDto {
|
||||||
|
@ApiProperty({ example: 'Mahdi' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@MaxLength(20)
|
@MaxLength(20)
|
||||||
firstName: string;
|
firstName: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'Rafie' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
lastName: string;
|
lastName: string;
|
||||||
@MaxLength(20)
|
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'mahdirafie@gmail.com' })
|
||||||
|
@MaxLength(20)
|
||||||
@IsEmail()
|
@IsEmail()
|
||||||
@MaxLength(100)
|
@MaxLength(100)
|
||||||
email: string;
|
email: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: '09123456789' })
|
||||||
@Matches(/^09\d{9}$/, {
|
@Matches(/^09\d{9}$/, {
|
||||||
message: 'Phone number must be a valid Iranian mobile number.',
|
message: 'Phone number must be a valid Iranian mobile number.',
|
||||||
})
|
})
|
||||||
phone: string;
|
phone: string;
|
||||||
|
|
||||||
|
@ApiProperty({ example: 'MahdiPassword@5!' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@MinLength(8)
|
@MinLength(8)
|
||||||
@Exclude()
|
@Exclude()
|
||||||
|
|||||||
Reference in New Issue
Block a user