anatine/zod-plugins

Array handling not fully functional (misses item type)

danielsharvey opened this issue · 1 comments

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.

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 :)