fix(schema): support boolean "false" subschemas#3004
Merged
Conversation
Draft-07+ JSON Schema allows a subschema to be the literal boolean `false`, meaning "nothing is valid here" (e.g. to disallow a property in a particular oneOf branch). quicktype's schema input unconditionally rejected this with "Schema \"false\" is not supported", aborting codegen entirely for real-world schemas that use the pattern (such as the Amazon Selling Partner Listings Feed schema from the issue). `false` subschemas now map to quicktype's existing "none" primitive type, the same mechanism already used for empty unions; a later pass (noneToAny) converts it to "any" before rendering. `items: false` is now also accepted the same way properties are. Intersections (allOf) treat "none" as absorbing, matching normal empty-type semantics. Added test/inputs/schema/boolean-subschema.schema (+ .1.json sample) covering false as a property value, as items, and inside allOf. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
Co-Authored-By: Claude <noreply@anthropic.com>
The bare boolean-subschema.1.fail.json ran for every language but relied
on a type violation (object supplied for the string 'foo') that Jackson
leniently coerces to "", so kotlin/schema-kotlin did not reject it and
the round-trip produced {"empty":[],"foo":""} instead of failing.
Replace it with a scalar supplied for the required 'empty' array, which
every target's deserializer rejects (no language coerces a scalar into a
list): verified via the real fixture harness for schema-golang and
schema-python, and manually for go/rust/python generated code.
Co-Authored-By: Claude <noreply@anthropic.com>
…alidation gap (#3004) Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
Bring the branch up to date with master so CI (which tests the PR-head/master merge) reflects current mainline state.
test/unit/cjson-enum-default.test.ts, pulled in by merging master, expected alphabetical enum-case order, but quicktype preserves JSON Schema declaration order for enum cases in cJSON (and every other language). Update the expectation to match actual generator output. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
…cking (#3004) Elixir's generated from_map/1 assigns JSON fields directly with no type validation (same pre-existing, already-documented limitation that already excludes strict-optional.schema and required.schema for this language), so the new boolean-subschema.1.fail.json type-mismatch case can't be enforced. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
…ation (#3004) test/fixtures/haskell/Main.hs unconditionally encodes the decoded Maybe result, so a failed decode prints "null" and exits 0 (same pre-existing, already-documented limitation that already excludes nested-intersection-union.schema and prefix-items.schema for this language), so the new boolean-subschema.1.fail.json case can't be detected. Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Fixes #1896.
quicktype crashed with
Error: Schema "false" is not supported at <ref>onvalid draft-07+ JSON Schema documents that use a boolean subschema
(
false) as a property/items value — e.g."patches": falseto mean "thisproperty is disallowed here." This is a normal part of the JSON Schema spec
(commonly emitted by tools that compile
oneOf/allOfbranches), and itappears in the real-world Amazon Selling Partner Listings Feed schema
attached to the issue.
Repro before the fix:
Exit code 1, no code generated at all, for any target language.
Root cause
In
packages/quicktype-core/src/input/JSONSchemaInput.ts,toType()handled
schema === true(mapping it to theanyprimitive) but assertedagainst
schema === false, throwingSchemaFalseNotSupportedand abortingthe whole run.
items: falsehit a similar rejection in the array-itemshandling.
Fix
falsesubschemas now map to quicktype's existingnoneprimitive type —the same type already used to represent an empty union. A later pass
(
noneToAny, already run in the pipeline) convertsnonetoanybeforerendering, so
falsenow behaves like an always-empty/unknown valueinstead of crashing.
truekeeps mapping toanyas before.items: falseis now accepted the same way object properties are (waspreviously rejected as "must be string or array").
resolveIntersections(used forallOf) now treatsnoneas anabsorbing member, so
allOf: [false, ...]correctly resolves tonone(nothing valid) rather than mis-simplifying.
Test coverage
Added
test/inputs/schema/boolean-subschema.schema(+boolean-subschema.1.jsonsample), covering:falseas a plain property valueitems: falseinside an array schemafalseinside anallOf(intersection)This is a new JSON Schema fixture input under
test/inputs/schema/, so itruns automatically against every language's
schema-<language>fixture inCI (per the repo's fixture-based testing convention).
Verification performed locally
npm run buildpasses.amazon.schemafrom Can not create C# code or any other from Amazon json schemas #1896) with--lang csharp: now generates valid C# (458 lines, exit 0) instead oferroring.
QUICKTEST=true FIXTURE=schema-typescript script/test test/inputs/schema/boolean-subschema.schema: passes.QUICKTEST=true FIXTURE=schema-typescript script/test(full TS schemasuite): passes, aside from one pre-existing, unrelated failure
(
vega-lite.schemahits a TypeScriptTS2411index-signature error) thatI confirmed also reproduces identically on
masterwithout this change.npm run test:unit: all 163 unit tests pass.schema-csharp) could not be run locally(
dotnetis not installed in this environment); CI will validate it andthe other language fixtures.
🤖 Generated with Claude Code