Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Description makes property to generate allOf instead of $ref #3289

Closed
1 of 4 tasks
papirosko opened this issue Feb 4, 2025 · 2 comments
Closed
1 of 4 tasks

Description makes property to generate allOf instead of $ref #3289

papirosko opened this issue Feb 4, 2025 · 2 comments

Comments

@papirosko
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

Using

    "@nestjs/swagger": "^7.1.11",

I have an object with property:

    @ApiProperty({
        type: OfferedServiceView,
        description: 'any text',
    })
    offeredServiceSnapshot: OfferedServiceView;

openapi file contains this for the property, which is wrong

"offeredServiceSnapshot":{"description":"any text","allOf":[{"$ref":"#/components/schemas/OfferedServiceView"}]}

while without description:

    @ApiProperty({
        type: OfferedServiceView
    })
    offeredServiceSnapshot: OfferedServiceView;

generates

"offeredServiceSnapshot":{"$ref":"#/components/schemas/OfferedServiceView"}

The latest is correct, I wonder, why adding description breaks this?

Minimum reproduction code

Steps to reproduce

No response

Expected behavior

openapi should contain

"offeredServiceSnapshot":{"$ref":"#/components/schemas/OfferedServiceView"}

Package version

10.2.5

NestJS version

7.1.11

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

@An-dz
Copy link

An-dz commented Feb 19, 2025

@kamilmysliwiec
Here's a reproduction repo: https://github.com/An-dz/nestjs-swagger-ref-reproducible

And here's the OpenAPI specification that tells that description is allowed with $ref:
https://swagger.io/specification/#reference-object

What to see:

  • In /api two of the properties are linked with SecondLevelDTO, two others are not.
  • In /api-json you can see the weird $ref in the components section.

Edit:
It's not only "description" that does that, "nullable" also causes the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants