question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@nestjs/swagger/plugin requires at least one decorator in the class to generate ApiProperty automatically

See original GitHub issue

Bug Report

Current behavior

Swagger module need at least one decorator in a class to correctly decorate classes with @nestjs/swagger/plugin

Step to reproduce

Take the default E2E sample (cats) provided in @nestjs/swagger/plugin. Remove all class-validator decorators.

export class CreateCatDto {
  readonly name: string;

  readonly age: number;

  readonly breed: string;
}

Expected behavior

Should add ApiProperty automatically to all fields. When no decorator is provided at all NestJS doesn’t decorate the class.

Possible Solution/Workaround

Add one fake decorator on any field 😃

Environment

Nest version: 6.10.5 “nestjs/swagger”: “4.0.2”,

For Tooling issues:

  • Node version: latest
  • Platform: Windows

An issue in model-class.visitor.ts visit() method ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilmysliwieccommented, Dec 5, 2019

Fixed in 4.0.6 😃

1reaction
muke1908commented, Mar 13, 2020

Using @nestjs/swagger:^4.3.2, still facing the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are types in dto not visible in swagger? - Stack Overflow
Create DTO without types, but matches type/interface structure just ... you deocorate at least one entry of your dto with @ApiProperty() ...
Read more >
Types and Parameters - OpenAPI - Documentation | NestJS
Types and parameters. The SwaggerModule searches for all @Body() , @Query() , and @Param() decorators in route handlers to generate the API document....
Read more >
What's new in NestJS Swagger 4? - Trilon Consulting
The plugin adds appropriate decorators on the fly based on the Abstract Syntax Tree. Hence, you no longer have to struggle with @ApiProperty...
Read more >
Integrating Swagger/OpenAPI with NestJS - codeburst
Automatically apply the ApiProperty() decorator to class fields (the class must have a file name of *.dto.ts or *.entity.ts ); Determine whether ...
Read more >
Bountysource
nestjs/swagger/plugin requires at least one decorator in the class to generate ApiProperty automatically.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found