Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"peerDependencies": {
"@trpc/server": "^11.1.0",
"zod": "^3.25.0 || ^4.0.0",
"zod-openapi": "^5.0.1"
"zod-openapi": "^5.4.4"
},
"dependencies": {
"co-body": "6.2.0",
Expand Down Expand Up @@ -75,8 +75,8 @@
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "5.8.3",
"zod": "^4.0.0",
"zod-openapi": "5.4.2"
"zod": "^4.1.13",
"zod-openapi": "5.4.6"
Comment thread
mcampa marked this conversation as resolved.
},
"optionalDependencies": {
"@rollup/rollup-linux-x64-gnu": "4.6.1"
Expand Down
23 changes: 19 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 27 additions & 4 deletions test/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ describe('generator', () => {
"id": Object {
"description": "User ID",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
"type": "string",
},
"name": Object {
Expand Down Expand Up @@ -1282,7 +1282,7 @@ describe('generator', () => {
"id": Object {
"description": "User ID",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
"type": "string",
},
"name": Object {
Expand Down Expand Up @@ -1363,7 +1363,7 @@ describe('generator', () => {
"schema": Object {
"description": "User ID",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
"type": "string",
},
},
Expand All @@ -1379,7 +1379,7 @@ describe('generator', () => {
"id": Object {
"description": "User ID",
"format": "uuid",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000)$",
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
"type": "string",
},
"name": Object {
Expand Down Expand Up @@ -3514,4 +3514,27 @@ describe('generator', () => {

expect(openApiDocument.paths!['/metadata/all']!.get!.operationId).toBe('getAllMetadataAboutMe');
});

// Repro for https://github.com/mcampa/trpc-to-openapi/pull/151
// Zod 4.1.13+ emits discriminated unions as `anyOf` rather than `oneOf`,
// and zod-openapi <5.4.4 crashes on Object.entries(jsonSchema.oneOf) when
// generating the document.
test('discriminated union in input does not crash document generation', () => {
const appRouter = t.router({
submit: t.procedure
.meta({ openapi: { method: 'POST', path: '/submit' } })
.input(
z.object({
payload: z.discriminatedUnion('kind', [
z.object({ kind: z.literal('a'), a: z.string() }),
z.object({ kind: z.literal('b'), b: z.number() }),
]),
}),
)
.output(z.object({ ok: z.boolean() }))
.mutation(() => ({ ok: true })),
});

expect(() => generateOpenApiDocument(appRouter, defaultDocOpts)).not.toThrow();
});
});
Loading