nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.66k stars 459 forks source link

Swagger is not showing extended properties #2946

Open kasir-barati opened 3 months ago

kasir-barati commented 3 months ago

Is there an existing issue for this?

Current behavior

Extending a class with custom properties does not work.

DTO: https://github.com/kasir-barati/you-say/blob/main/apps/backend/src/modules/post/dto/find-all-query.dto.ts#L8

Generated swagger docs:

image

Similar past issue: https://github.com/nestjs/swagger/issues/518

Minimum reproduction code

https://github.com/kasir-barati/you-say

Steps to reproduce

  1. npm ci
  2. cp .env.example .env
  3. npx nx dev backend

Open your browser and go to localhost:3001/docs

Expected behavior

Show both properties, extended one from PaginationDto and custom one (createdAt).

Package version

7.3.1

NestJS version

10.3.7

Node.js version

20.10.0

In which operating systems have you tested?

Other

No response

kasir-barati commented 3 months ago

Right now - trying to fix this issue - I'll upgrade packages version to see if that can help. Although I am skeptical about it.

kasir-barati commented 3 months ago

Faced tons of dependency conflicts :/.

code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: you-say@0.0.1
npm ERR! Found: eslint@9.2.0
npm ERR! node_modules/eslint
npm ERR!   dev eslint@"9.2.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer eslint@"^8.56.0" from @typescript-eslint/parser@7.8.0
npm ERR! node_modules/@typescript-eslint/parser
npm ERR!   dev @typescript-eslint/parser@"7.8.0" from the root project
npm ERR!   peer @typescript-eslint/parser@"^6.13.2 || ^7.0.0" from @nx/eslint-plugin@19.0.2
npm ERR!   node_modules/@nx/eslint-plugin
npm ERR!     dev @nx/eslint-plugin@"19.0.2" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! 
npm ERR! For a full report see:
npm ERR! /home/kasir/.npm/_logs/2024-05-10T11_04_49_215Z-eresolve-report.txt

npm ERR! A complete log of this run can be found in: /home/kasir/.npm/_logs/2024-05-10T11_04_49_215Z-debug-0.log

Probably not the smartest move I could make :sweat_smile:.

Also it did not change @nestjs/swagger version but did change some other packages. Still evaluating it. If it did not work, will undo changes since they are really big and I am in the middle of something :slightly_smiling_face:.

kasir-barati commented 3 months ago

It broke my Dockerfile like I suspected. So for now I am back to normal -- I reverted package.json and package-lock.json.

kasir-barati commented 3 months ago

That's weird, I just noticed that according to Git it was part of the doc but for some reason it was removed and when I added new prop to @ApiPorperty decorator it just recreated it in openApi.json file :/

image Is it really confusing since here I am creating the openApi.json file and I cannot shake the feeling that something is not right with @nestjs/swagger. I mean this helper function utilizes createSwaggerConfiguration and there we are only using DocumentBuilder to build the open API specification :confounded:.

Not sure what is wrong, but all of that aside we still have this behavior of swagger missing extended props.

kasir-barati commented 3 months ago

But before adding example it was removed completely :/.

kasir-barati commented 3 months ago

Here is my broken pipeline: https://github.com/kasir-barati/you-say/actions/runs/9023506806/job/24795454676

Not sure why but it is clear that the integration test failed due to the fact that openApi.json had not limit and page this time around while a few weeks or days ago it was passing.

kasir-barati commented 3 months ago

Feel free to close this issue if it did not happen to you. It happened in my local env and pipeline once but I am not sure why and how adding a simple example https://github.com/kasir-barati/you-say/commit/b902305178c78c389a1d8f3a0f42b8bd92631956 fixed the issue.