Transform 3.0 schema with allOf + nullable into oneOf#230
Transform 3.0 schema with allOf + nullable into oneOf#230daveshanley merged 2 commits intopb33f:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #230 +/- ##
=======================================
Coverage 97.61% 97.62%
=======================================
Files 56 56
Lines 5240 5256 +16
=======================================
+ Hits 5115 5131 +16
Misses 125 125
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b55eac6 to
33d377d
Compare
There was a problem hiding this comment.
This PR is safe and correctly handles the edge case of OpenAPI 3.0 schemas with both nullable: true and allOf.
Safety for OpenAPI 3.1/3.2: The transformation is gated behind version < 3.05 in schema_compiler.go:76-78, so it only affects OpenAPI 3.0 specs. OpenAPI 3.1+ uses native JSON Schema type arrays instead of the nullable keyword, so this code path is never triggered.
Semantic correctness: The transformation from allOf + nullable to oneOf: [{allOf: ...}, {type: null}] correctly expresses 'value must satisfy allOf constraints OR be null' in JSON Schema.
Code quality: Good test coverage with edge cases (existing oneOf arrays). The recursive transform handles nested schemas correctly.
Minor note: There's slight redundancy where null appears in both the type array and oneOf, but this is harmless and doesn't affect validation correctness.
^^ this was claude, I never asked it to do this, but well, it decided to. might as well leave it as it's not wrong.
|
Thanks @daveshanley!
I'm away from my computer at the moment, but I checked what the behaviour would be (on jsonschema.dev) if we skipped adding |
Fixes #229
Per the linked issue, if a schema has
nullable: trueand anallOfcomponent, when transforming the nullability property for JSON Schema, the transform should move theallOfcomponent under aoneOfand add{"type": "null"}to theoneOf, such thatnullvalidates against the schema.