Skip to content

OpenAPI schema generator doen't handle Zod object without shape on dynamic params #1162

@isaac-sec

Description

@isaac-sec

Environment

orpc@1.10.3, node 24.10.0, zod 3.25.51

Reproduction

import { OpenAPIGenerator } from '@orpc/openapi';
import { ZodToJsonSchemaConverter } from '@orpc/zod';
import { oc } from '@orpc/contract';
import { z } from 'zod';

const PlanetIdInputSchema = z.object({
  id: z.string().min(1),
});

const FooSchema = z.object({
  foo: z.number().int().positive(),
});

const PlanetSchema = z.object({
  id: PlanetIdInputSchema.shape.id,
  name: z.string().min(1),
});

const getPlanetContract = oc
  .route({ method: 'GET', path: '/planet/{id}' })
  .input(FooSchema.and(PlanetIdInputSchema))
  .output(PlanetSchema);

const contract = {
  getPlanet: getPlanetContract,
};

const generator = new OpenAPIGenerator({
  schemaConverters: [new ZodToJsonSchemaConverter()],
});

const spec = await generator.generate(contract, {
  info: {
    title: 'Planet API',
    version: '1.0.0',
  },
});

console.log(JSON.stringify(spec, null, 2));

Describe the bug

Using @orpc/opnapi@1.10.3, the generator fails to find existing properties for dynamic params when Zod objects have no shape. This can happen if e.g. intersection (.and()) is used to construct an object, or when using a discriminated union.

Here's the error:

[OpenAPIGenerator] Error occurred while generating OpenAPI for procedure at path: getPlanet
When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.

Additional context

No response

Logs

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions