Swagger: Nested objects not working (in certain pattern)

Created on 6 May 2020  路  13Comments  路  Source: nestjs/swagger

I'm submitting a...


[ ] Regression 
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


The "An object inside an array of object" structure isn't presenting properly (both Example Values and Schema sections).

Here is my code structure:

// NewBookingDto.ts
export class NewBookingDto {
  @ApiProperty({
    description: "List of buyers",
    type: [BuyerDto],
  })
  buyers: BuyerDto[];
}

...
// BuyerDto.ts
export class BuyerDto {
  @ApiProperty({
    description: "List of buyers' contact person",
    type: BuyerContactPersonDto, // <-- Not okay; [BuyerContactPersonDto] <-- okay
  })
  buyer_contact_person: BuyerContactPersonDto;
}

I tried three nested structure, only first structure not working properly.

  1. buyers[] -> buyer_contact_person - Not Okay
    Screenshot 2020-05-06 at 11 16 42 AM
  1. buyers[] -> buyer_contact_person[] - Okay
    Screenshot 2020-05-06 at 11 17 19 AM

  2. buyers -> buyer_contact_person - Okay
    Screenshot 2020-05-06 at 11 35 08 AM

Expected behavior


It should works like other nested patterns.

Environment


Nest version: 
"@nestjs/common": "^6.7.2",
"@nestjs/core": "^6.7.2",
"@nestjs/swagger": "^4.5.4"

For Tooling issues:
- Node version: v12.16.1
- Platform:  MacOS
needs clarification

Most helpful comment

I don't know why this issue was closed but the problem persists. As @huypvw stated, the problem appears at the third level of a nested object.

Removing description property from @ApiProperty() seems to do the trick. A proper fix should be made.

All 13 comments

Please provide a minimum reproduction repository.

Same happening here.
package.json:
"@nestjs/common": "^7.0.8", "@nestjs/core": "^7.0.8", "@nestjs/jwt": "^7.0.0", "@nestjs/microservices": "^7.0.8", "@nestjs/passport": "^7.0.0", "@nestjs/platform-express": "^7.0.8", "@nestjs/swagger": "^4.5.7", "@nestjs/typeorm": "^7.0.0",

Is this solved??
I faced this issue
@nestjs/common: "^6.7.2",,,

Is this solved??
I faced this issue
@nestjs/common: "^6.7.2",,,

I'm submitting a...

[ ] Regression 
[X] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

The "An object inside an array of object" structure isn't presenting properly (both Example Values and Schema sections).

Here is my code structure:

// NewBookingDto.ts
export class NewBookingDto {
  @ApiProperty({
    description: "List of buyers",
    type: [BuyerDto],
  })
  buyers: BuyerDto[];
}

...
// BuyerDto.ts
export class BuyerDto {
  @ApiProperty({
    description: "List of buyers' contact person",
    type: BuyerContactPersonDto, // <-- Not okay; [BuyerContactPersonDto] <-- okay
  })
  buyer_contact_person: BuyerContactPersonDto;
}

I tried three nested structure, only first structure not working properly.

  1. buyers[] -> buyer_contact_person - Not Okay

Screenshot 2020-05-06 at 11 16 42 AM

  1. buyers[] -> buyer_contact_person[] - Okay

Screenshot 2020-05-06 at 11 17 19 AM

  1. buyers -> buyer_contact_person - Okay

Screenshot 2020-05-06 at 11 35 08 AM

Expected behavior

It should works like other nested patterns.

Environment

Nest version: 
"@nestjs/common": "^6.7.2",
"@nestjs/core": "^6.7.2",
"@nestjs/swagger": "^4.5.4"

For Tooling issues:
- Node version: v12.16.1
- Platform:  MacOS

Hi, as a workaround you can remove description for this field. More info here https://github.com/nestjs/swagger/pull/842

Yes, with nested object lv3, it don't work

any solution for this? I have the same problem at the nested object lv3

I don't know why this issue was closed but the problem persists. As @huypvw stated, the problem appears at the third level of a nested object.

Removing description property from @ApiProperty() seems to do the trick. A proper fix should be made.

Like @manuelnucci says, works only if description property is in the last nested level.

I don't know why this issue was closed but the problem persists. As @huypvw stated, the problem appears at the third level of a nested object.

Removing description property from @ApiProperty() seems to do the trick. A proper fix should be made.

Same issue here, thanks for sharing the idea with description.

Same issue here. If there is a nested object with description, it just display as empty object. Removing description works.

Thanks for this suggestion of removing description. Worked for me as well.

I don't know why this issue was closed but the problem persists. As @huypvw stated, the problem appears at the third level of a nested object.

Removing description property from @ApiProperty() seems to do the trick. A proper fix should be made.

This worked for me <3 . Thanks for saving my day ;)

this is still happening; please reopen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

itslenny picture itslenny  路  3Comments

otroboe picture otroboe  路  3Comments

alisherks picture alisherks  路  4Comments

cdiaz picture cdiaz  路  4Comments

ericzon picture ericzon  路  4Comments