You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON Schema generation fails for discriminated unions in recursive scopes #1546
toJsonSchema() throws "Unexpected JSON Schema input for structure: {}" when generating JSON schema for a recursive scope containing a discriminated union where the union members have additional fields beyond the discriminator.
Workaround is to define the union outside the scope.
🔎 Search Terms
toJSONSchema
discriminated unions
recursive types
cyclic types
🧩 Context
ArkType version: 2.1.26
TypeScript version (5.1+): 5.8.3
Other context you think may be relevant (JS flavor, OS, etc.): - Runtimes: Node.js v22.19.0, Bun 1.3.0
Activity
rynvelt commentedon Nov 15, 2025
Encountered the same issue but the workaround does not work for me.
My finding is:
toJsonSchema()fails when combining a recursive schema with a discriminated union where any variant has 2 or more properties:🧑💻 Repro
Output:
🧩 Context
I noticed that this does not happen for unions with two or more fields if there is no discriminator field in this union.
fix(schema): allow an alias only as a structural value
test(type): pin each cyclic issue's own repro
fix(schema): only emit referenced $defs in toJsonSchema
release: arktype 2.2.9 + dependents
release: arktype 2.2.9 + dependents
release: arktype 2.2.9 + dependents (#1704)
test(type): pin $defs of a partially overlapping discriminated union
Merge main (arktype 2.2.9, attest 0.57.1) into featherduster
fix(schema): only emit referenced $defs in toJsonSchema (arktypeio#1689)
⬆️ Update dependency arktype to ^2.2.9
⬆️ Update dependency arktype to ^2.2.9
⬆️ Update dependency arktype to ^2.2.9
⬆️ Update dependency arktype to ^2.2.9