astahmer / openapi-zod-client

Generate a zodios (typescript http client with zod validation) from an OpenAPI spec (json/yaml)

Home Page:openapi-zod-client.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

additionalProperties with type and nullable: true not producing expected zodis content

simonbinwang opened this issue · comments

I have a model which generated openapi schema like:

      "ScopeValuesRequest": {
        "type": "object",
        "properties": {
          "SignalId": {
            "type": "string",
            "nullable": true
          },
          "ScopeDisplayName": {
            "type": "string",
            "nullable": true
          },
          "StartTime": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "EndTime": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "CustomFilters": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "nullable": true
            },
            "nullable": true
          }
        },
        "additionalProperties": false
      }

it produce zodis schema like:

const ScopeValuesRequest = z
    .object({
        SignalId: z.string().nullable(),
        ScopeDisplayName: z.string().nullable(),
        StartTime: z.string().datetime({ offset: true }).nullable(),
        EndTime: z.string().datetime({ offset: true }).nullable(),
        CustomFilters: z.record(z.string()).nullable()
    })
    .partial();

For CustomFilters in this model, I think the value type should be string | null, aka CustomFilters: z.record(z.string().nullable()).nullable()
instead of CustomFilters: z.record(z.string()).nullable()?

makes sense, feel free to send a PR ! 🙏