Skip to content

Conversation

@alexrjones
Copy link
Contributor

Fixes #229

Per the linked issue, if a schema has nullable: true and an allOf component, when transforming the nullability property for JSON Schema, the transform should move the allOf component under a oneOf and add {"type": "null"} to the oneOf, such that null validates against the schema.

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.62%. Comparing base (0db7586) to head (33d377d).
⚠️ Report is 3 commits behind head on main.

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           
Flag Coverage Δ
unittests 97.62% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alexrjones alexrjones force-pushed the aj/nullable-transform-allof branch from b55eac6 to 33d377d Compare February 3, 2026 04:03
Copy link
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@alexrjones
Copy link
Contributor Author

Thanks @daveshanley!

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.

I'm away from my computer at the moment, but I checked what the behaviour would be (on jsonschema.dev) if we skipped adding null to the type array for this case, and IINM doing so causes a null value to fail validation, because null is not of type object - so I think specifying null in both places is required

@daveshanley daveshanley merged commit ba37a36 into pb33f:main Feb 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nullable transforms do not correctly apply to allOf schemas

2 participants