feat: validate generated models against source JSON Schema - #68
Merged
Conversation
JSON Schema 2020-12 allows `true` and `false` in any schema position: `true`
accepts every value, `false` accepts none. `properties: {extra: true}` is how a
spec says "this key exists, any value". The parser modeled schemas as objects
only, so one boolean anywhere took the whole document down with the same opaque
error #60 was about.
`Schema::Bool` models it once, at the type every position already uses, rather
than adding another per-keyword enum. That makes `Items::Bool` redundant —
`items: false` is now the ordinary single-schema slot holding a boolean schema —
so it is gone, and closedness reads the boolean through it.
Generated code cannot say more than `serde_json::Value` for either spelling, so
what changes is that the document parses and its other fields keep their types.
`true` reports as `any-schema` and `false` as `never-matches`, both faithful. In
a union a `true` branch makes the whole union unconstrained, and a `false`
branch can never be taken and is dropped: `oneOf: [A, false]` is `A`.
Also reads integer keywords written as decimals (`maxItems: 2.0`), which JSON
Schema permits and the suite exercises; `2.5` is still an error rather than a
silent round.
The vendored JSON Schema 2020-12 corpus goes from 38 parse failures to zero,
with no round-trip loss — the boolean fix accounts for 30 of them across
`contains`, `if-then-else`, `items`, `not`, `patternProperties`, `prefixItems`,
`properties`, `propertyNames`, and `dependentSchemas`.
Closes #63
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TD3TSeWKu4VqLtEnRMDjry
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
scripts/spec-compile.shruns with aggregate failure reporting, retained artifacts, coverage totals, and explicit skip classifications.allOfprojection, nullable fields and references, dynamic object members, wide integers, binary/time wire formats, inline-schema identity, and boolean subschemas.The authoritative uninterrupted corpus run completed with:
Generated compatibility
nullwithOption<Option<T>>; integer widths follow the effective schema domain; and inline types use collision-safe provenance-aware names.anyOfpreserves complete object input,oneOfrejects ambiguous/no-match values, discriminator mappings and literal domains are enforced, required nullable values serialize as explicitnull, binary model values remain JSON strings, and RFC 3339 offsets round-trip exactly.schema-roundtripbinary. Corpus scratch crates addjsonschemaas a dev dependency only when round-trip validation is enabled.SPEC_COMPILE_SCHEMA_ROUNDTRIP=0only to isolate unrelated compile failures.Validation
cargo fmt --all -- --checkcargo clippy --all-features -- -D warningscargo test --all-featuresscripts/install-smoke.sh(GitHub CI)scripts/spec-compile.shgenerator/compile/schema-round-trip corpus (GitHub CI)openai2.45.0 andanthropic0.120.0 SDK compatibility tests against generated Axum servers.message_startthroughmessage_stop.Notes for reviewers
This PR contains 61 commits across 121 files because each independently reproducible corpus failure was tracked and fixed with focused coverage. All 68 child issues under Beads issue
openapi-generator-cu5are closed.Suggested review path:
src/schema_roundtrip.rs,src/bin/schema-roundtrip.rs, andscripts/spec-compile.shfor the validation architecture.src/analysis.rs,src/generator.rs, andsrc/openapi.rsfor generated-model correctness fixes.tests/corpus_fixture_schema_validity.rs.