nestjs/swagger

Cannot use nested objects in response

matthew-kaye opened this issue · 1 comments

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I think this issue was closed without a real fix. When trying to generate a Swagger document, it will create required fields as a boolean rather than an array, for example if you defined a class like this:

class AddressResponseDTO {
  status: string;
  data: {
    line1: string;
    line2?: string;
    city: string;
    province?: string;
    postalCode: string;
    country: string;
  };
}

it generates the following:

{"type":"object","properties":{"status":{"type":"string"},"data":{"type":"object","properties":{"line1":{"type":"string","minLength":1,"required":true},"line2":{"type":"string","required":true},"city":{"type":"string","minLength":1,"required":true},"province":{"type":"string","required":true},"postalCode":{"type":"string","minLength":1,"required":true},"country":{"type":"string","minLength":1,"required":true}}}},"required":["status","data"]}

Minimum reproduction code

#2117

Steps to reproduce

  1. Define a class with a nested object or array of objects as the response type
  2. Generate a Swagger document
  3. Observe required fields are boolean when required fields should be defined by a separate array

Expected behavior

The required field should only ever be an array, not a boolean

Package version

8.0.1

NestJS version

10.4.5

Node.js version

20

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

I can't reproduce this issue.

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project). The one from #2117 is inccorect