Fix nullable allOf ref type check - #1279
Conversation
A property declared nullable: true and composed via allOf containing only a $ref (e.g. OpenAPI 3.0 style composition) incorrectly rejected null values. The schema owning the failing type keyword is resolved through $ref and is a cached object whose lexical parent reflects where it is declared in the document, not where it was referenced from, so the existing one-hop parent/grandparent nullable check never found the nullable declaration on the referencing schema. Walk the dynamic evaluation stack instead, following through any chain of $ref schemas, to find the referencing schema and check it (and its lexical parent) for nullable: true. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Confirms, per maintainer feedback on the upstream issue, that the dynamic evaluation stack walk added for nullable allOf + $ref compositions has no effect outside dialects that enable the nullable keyword (currently only OpenAPI 3.0.x) — null is still rejected for the same schema shape under draft-07. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes OpenAPI 3.0 nullable: true handling when nullable is applied to a schema composed via allOf that only contains a $ref, ensuring null values are accepted as intended (per issue #1278).
Changes:
- Update nullable type-check logic to detect
nullable: trueacross$refevaluation context (not just lexical parentage). - Add an OpenAPI 3.0 regression test covering
nullable+allOf+$ref. - Add a Draft-07 test asserting
nullableremains ignored outside nullable-enabled dialects.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/main/java/com/networknt/schema/utils/JsonNodeTypes.java | Enhances nullable detection for null type mismatches by walking the evaluation schema stack to account for $ref caching/parentage. |
| src/test/java/com/networknt/schema/oas/OpenApi30Test.java | Adds regression test reproducing issue #1278 (nullable on allOf with $ref should allow null). |
| src/test/java/com/networknt/schema/TypeValidatorTest.java | Adds a Draft-07 test confirming nullable is not honored when the dialect does not enable the nullable keyword. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
PR review: Fix nullable allOf ref type checkRisk: HIGH — request changes Finding
Verification
Recommendation: REQUEST CHANGES before merge. |
Per PR review feedback (networknt#1279), the dynamic evaluation stack walk added to support nullable allOf + $ref compositions incorrectly honored nullable: true declared as a direct sibling of $ref. That's a Reference Object, and the OpenAPI 3.0 specification requires siblings of $ref to be ignored, so it must never grant nullability on its own. Track whether the current frame in the walk was reached via $ref and, if so, skip checking that frame's own nullable — only its lexical parent (the schema actually composing it, e.g. the allOf owner) is consulted. The allOf + $ref case that motivated the original fix still passes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Re-review: PR #1279No blocking findings. Risk: MEDIUM. Recommendation: APPROVE. The new commit 5d3d506 resolves the previous regression correctly:
Verification on the current head:
One non-blocking cleanup note: OpenApi30Test.java was normalized from CRLF to LF, making the diff look much larger than its functional change. That does not affect correctness. GitHub currently reports the PR (#1279) as mergeable, although no remote status checks are listed. |
|
Thanks! |
|
Should I open a 2.x PR also? We're still on v2, so it'd be great to have the fix there too. |
|
Yes. Please. |
Fixes issue where a nullable (OpenAPI dialect) on an element containing
allOfisn't honoured when a null value is passed.Closes #1278