I have the following input schema:
const inputSchema = z.union([
z.object({
id: z.string(),
}),
z.object({
key: z.string(),
}),
])
This schema works until I do:
import { generateOpenApiDocument } from 'trpc-openapi'
const openApiDocument = generateOpenApiDocument(trpcAppRouter, {
title: 'title',
baseUrl: '/route',
version: '0.0.1',
})
When I generate pass the route with the input to generateOpenApiDocument then I get the error:
TRPCError: [query.thing.route] - Input parser must be a ZodObject
I guess it's a bug in generateOpenApiDocument that doesn't check the input correctly because it is a ZodObject but I'm not sure how to work around this.
I found that trpc-opeapi uses zod-to-json-schema and zod-to-json-schema does not support union. Hence trpc-openapi does not support OpenAPI 3 spec.