Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

435
Views
Cómo evitar escribir `@ApiProperty()` en cada dto para NestJs-swagger

Estoy investigando la forma de evitar especificar @ApiProperty() en cada dto.

Sé que existe una manera de crear el archivo nest-cli.json , y si especifica Promise<DTO> en su controlador en nest-swagger, producirá la salida dto de la ruta.

La estructura se ve así:

nest-cli.json

 { "collection": "@nestjs/schematics", "sourceRoot": "src", "compilerOptions": { "plugins": [ { "name": "@nestjs/swagger", "options": { "introspectComments": true } } ] } }

controller.ts

 @Get() async getMonitors (): Promise<OutputMonitorsDto> { // <-- Here is my outputDto return this.monitorsService.getMonitors() }

Y en swagger muestra algo como esto: ingrese la descripción de la imagen aquí

Sin embargo, ¿hay alguna forma de configurar NestJs para tener las mismas cosas con inputDTO y no escribir en cada dto @ApiProperty ?

Como en el ejemplo a continuación:

ExampleDto.ts

 export class GetListUsersDto { @ApiProperty() @IsString() name: string @ApiProperty() @IsString() email: string @ApiProperty() @IsString() publicApiKey: string @ApiProperty() @IsBoolean() isAdmin: boolean @ApiProperty() @IsBoolean() isDesigner: boolean @ApiProperty() @IsBoolean() isEditor: boolean @ApiProperty() @IsBoolean() isEnabled: boolean @ApiProperty() @IsString() boughtProduct: string }

Y solo después de @ApiProperty, mostrará la estructura como se muestra arriba para la entrada en swagger.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

No hay forma de evitar decorar sus propiedades DTO. Sin embargo, si sus DTO tienen mucho en común, es posible que esté buscando tipos asignados . La documentación se puede encontrar aquí .

Básicamente, le permiten transformar los tipos existentes para mantener sus DTO SECOS.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!