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

Array handling not fully functional (misses item type) #215

Open
danielsharvey opened this issue Aug 4, 2024 · 1 comment · May be fixed by #216
Open

Array handling not fully functional (misses item type) #215

danielsharvey opened this issue Aug 4, 2024 · 1 comment · May be fixed by #216

Comments

@danielsharvey
Copy link

For createZodDto() usage such as:

const contactGroupsSchema = z.object({
  contactGroups: z.string().array().optional().describe('Filter by Xero Contact Groups'),
});
class ContactGroupsDto extends createZodDto(contactGroupsSchema) {}

produces

{
  "name": "contactGroups",
  "required": false,
  "in": "query",
  "description": "Filter by Xero Contact Groups",
  "schema": {
    "type": "array"
  }
}

rather than

{
  "name": "contactGroups",
  "required": false,
  "in": "query",
  "description": "Filter by Xero Contact Groups",
  "schema": {
    "type": "array",
    "items": {
      "type": "string"
    }
  }
}

This is due to Nest expecting the isArray boolean. See

  1. https://docs.nestjs.com/openapi/types-and-parameters#arrays
  2. https://github.com/nestjs/swagger/blob/02e03411f7823362247cdf0de0e185657ace2069/lib/services/swagger-types-mapper.ts#L47-L52

Setting isArray in createZodDto() resolves the issue.

@fhawkes
Copy link

fhawkes commented Oct 15, 2024

We're also being impacted by this. I pulled the patch that @danielsharvey so graciously created and it does indeed fix the issue. Would be great if we could get that into the next cut of this package :)

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

Successfully merging a pull request may close this issue.

2 participants