Skip to content

Unable to generate OpenAPI schema while using z.preprocess() #1317

@GalvinGao

Description

@GalvinGao

Environment

@orpc/openapi: 0.0.0-next.c20c3b4
zod: ^4.1.12

Reproduction

https://stackblitz.com/edit/github-7egr8s3b-2pxykj31

Describe the bug

Unable to generate an OpenAPI schema while using z.preprocess(). This is necessary since we're preprocessing user input before validating it against a enum type.

Key reproducible:

const SchemaWithPreprocess = z.preprocess((val) => {
  if (typeof val === 'string') {
    return val.toUpperCase();
  }
  return val;
}, z.string());

oc.input(
  z.object({
    params: z.object({
      type: SchemaWithPreprocess,
    }),
  })
)

Additional context

No response

Logs

OpenAPIGeneratorError: Some error occurred during OpenAPI generation:

[OpenAPIGenerator] Error occurred while generating OpenAPI for procedure at path: test
When input structure is "detailed" and path has dynamic params, the "params" schema must be an object with all dynamic params as required.
    at new OpenAPIGeneratorError (file:///home/projects/github-7egr8s3b-2pxykj31/node_modules/@orpc/openapi/dist/shared/openapi.CoREqFh3.mjs:517:1)
    at OpenAPIGenerator.generate (file:///home/projects/github-7egr8s3b-2pxykj31/node_modules/@orpc/openapi/dist/shared/openapi.CoREqFh3.mjs:587:13)
    at async Server.eval (file:///home/projects/github-7egr8s3b-2pxykj31/src/main.ts:18:935)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions