Skip to content

Zod string literal enums are generated in OpenAPI spec without a string type #1453

@evrys

Description

@evrys

Environment

orpc@1.13.5

Reproduction

ZodToJsonSchemaConverter result for the following does not include string type:

z.enum(["bug", "feedback"])

Describe the bug

With Stoplight rendering my spec, I see a lot of these:

Image

I worked around it in my project like so:

const openApiGenerator = new OpenAPIGenerator({
  schemaConverters: [
    new ZodToJsonSchemaConverter({
      interceptors: [
        (options) => {
          // Workaround to make orpc correctly specify zod string
          // enums as strings in the OpenAPI spec (instead of "any")
          const [required, schema] = options.next();
          if (schema && "enum" in schema && !("type" in schema)) {
            return [required, { ...schema, type: "string" }];
          }
          return [required, schema];
        },
      ],
    }),
  ],
});

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions