Skip to content

A schema with an id gets no options, only --json #233

Open

Description

@FluteBlade

Giving an input schema an id, as one does to name it in JSON Schema or in an OpenAPI document, removes its options. With trpc-cli 0.17.1 and zod 4.6.7:

import { z } from "zod";
import { createCli, os } from "trpc-cli";

const Greeting = z.object({ name: z.string() }).meta({ id: "Greeting" });
const router = os.router({ greet: os.input(Greeting).handler(({ input }) => `hi ${input.name}`) });
await createCli({ router }).run();

greet --help lists only --json, with "procedure's schema couldn't be converted to CLI arguments: Invalid input type {...}, expected object or tuple", and greet --name Ada fails with "unknown option '--name'". Without the id, --name <string> is there. .register(z.globalRegistry, { id: "Greeting" }) does the same.

Zod writes a schema that has an id as a reference: the root is {"$ref": "#/$defs/Greeting", "$defs": {"Greeting": {...}}}, or #/definitions/Greeting for draft-07, and trpc-cli reads that root as the input's type. A field with an id has a smaller version of the problem: retries: z.int().meta({ id: "Retries" }).optional() becomes --retries [json] instead of --retries [integer].

Resolving a local $ref against the schema's own $defs or definitions before reading it would fix both. I tried the root case from outside, passing the same JSON Schema with its root $ref replaced by its target as a Standard JSON Schema, and greet --help then lists --name <string> and greet --name Ada prints "hi Ada".

For now we pass a copy of the object's fields, z.object(Greeting.shape), which has no id.

Activity

  1. pullfrog commented on Oct 24, 2026

    @pullfrog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions