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.

Swagger does not correctly show schema for nested response data

See original GitHub issue

Bug Report

Current behavior

Consider the Cat sample, but the cat entity contains a “preferredFood” field that is the cat’s preferred food as a “Food” entity and the Food entity, in turn, contains a field “vendor” that is a Vendor entity that supplies the food. When rendering swagger for the Cat API, we see the details of the preferredFood field’s object, but we see only that the “vendor” field is an object, but no details about that object.

image

Input Code

https://github.com/pvogel1967/11-swagger

Expected behavior

Cat > {
    age , etc.
    preferredFood > {
         weight, etc.
         vendor > {
             name: string
                        example: Purina
                        The name of the vendor
             address: string
                         example: 1600 Pennsylvania Ave, N.W., Washington, DC. 20500
                         The mailing address of the vendor
          }
    }
}              

Possible Solution

Environment


Nest version: 7.6.15

 
For Tooling issues:
- Node version: 14.15.5  
- Platform:  Mac

Others:

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
cybercarnagecommented, May 27, 2021

Something wrong with schemas. Temporary solution. You can use oneOf keyword and getSchemaPath method:

@Type(() => YourClass)
@ValidateNested()
@ApiProperty({
  description: 'Test',
  oneOf: [{ $ref: getSchemaPath(YourClass) }],
  type: () => YourClass,
})
public readonly yourField: YourClass;

Docs: https://docs.nestjs.com/openapi/types-and-parameters

0reactions
kamilmysliwieccommented, Oct 20, 2021

Would you like to create a PR for this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swashbuckle nested responses not showing up correctly
The issue I'm having is the response schema isn't showing up correctly if the response has another object within it. While using Swagger...
Read more >
Solved: Defining Nested Data in Response Schema
Solved: I'm trying to define a schema for a response in the Yaml for my API and this includes a field being an...
Read more >
Using $ref - Swagger
OAS 3 This guide is for OpenAPI 3.0. Using $ref. When you document an API, it is common to have some features which...
Read more >
Swagger PUT/POST body value issue
However, when we PUT or POST data via the Swagger UI, we see issues where Swagger is missing an extra JSON wrapper around...
Read more >
F.A.Q - Springdoc-openapi
How can I map Pageable (spring-data-commons) object to correct ... Otherwise, the swagger documentation will not show the fields of the annotated entity....
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