Swagger
Swagger — это набор инструментов и спецификация для описания, разработки и тестирования RESTful API.
Подключение:
12345678910111213141516171819202122// main.tsimport { NestFactory } from "@nestjs/core";import { AppModule } from "./app.module";import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger";async function bootstrap() {const app = await NestFactory.create(AppModule);const config = new DocumentBuilder().setTitle("Online Store").setDescription("Online Store Documentation").setVersion("1.0.0").addTag("online-store").build();const document = SwaggerModule.createDocument(app, config);SwaggerModule.setup("/docs", app, document);await app.listen(process.env.PORT ?? 3000);}bootstrap();
1234567891011121314151617181920212223242526272829303132// create-user.dto.tsimport { ApiProperty } from '@nestjs/swagger';import { IsEmail, IsString, MaxLength, MinLength } from 'class-validator';export class CreateUserDto {@ApiProperty({example: 'user@gmail.ru',description: 'Email',})@IsEmail({},{message: 'Wrong email',},)readonly email: string;@ApiProperty({example: '123456',description: 'Password',})@IsString({message: 'Must be string',})@MinLength(6, {message: 'Min length must be more or equl 6',})@MaxLength(12, {message: 'Max length must be less 12',})readonly password: string;}