swagger icon indicating copy to clipboard operation
swagger copied to clipboard

Swagger does not correctly show schema for nested response data

Open pvogel1967 opened this issue 3 years ago • 7 comments

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:

pvogel1967 avatar May 04 '21 00:05 pvogel1967

any update on this? i'm facing the same issue

ruifernando7 avatar May 16 '21 04:05 ruifernando7

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

cybercarnage avatar May 27 '21 10:05 cybercarnage

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

Nothing change when update this temporary solution

vietkute02 avatar Jul 08 '21 09:07 vietkute02

Any updates on this issue !!!

ayoubgm avatar Sep 15 '21 13:09 ayoubgm

Would you like to create a PR for this issue?

kamilmysliwiec avatar Oct 20 '21 12:10 kamilmysliwiec

same here, is there a way to fix it?

xlmnxp avatar Jan 18 '23 11:01 xlmnxp

The problem is that the title somehow get erased. Setting the title manually will fix the issue.

No title:

  @ApiProperty({
    type: StoreAvailability,
    description: 'Store availability configuration',
  })
  availability!: StoreAvailability;
image

With title:

  @ApiProperty({
    type: StoreAvailability,
    title: 'StoreAvailability',
    description: 'Store availability configuration',
  })
  availability!: StoreAvailability;
image

ph55 avatar Aug 21 '23 00:08 ph55