Skip to content

test: OAS 3.1 scalar const: null is kept as NullNode (#2395) - #2413

Open
khayashi4337 wants to merge 1 commit into
swagger-api:masterfrom
khayashi4337:fix/oas31-const-null
Open

khayashi4337 wants to merge 1 commit into
swagger-api:masterfrom
khayashi4337:fix/oas31-const-null

Conversation

@khayashi4337

Copy link
Copy Markdown

Pull Request

Description

Regression test for #2395 (const: null on a scalar schema in OpenAPI 3.1).

With OpenAPIV3Parser, getConst() for const: null is already a Jackson NullNode, not Java null. So on this path, "const: null" and "no const" can already be told apart. NullNode.toString() prints null, which makes it easy to mistake for Java null. The test pins this down:

  • a scalar const: null gives a NullNode;
  • a schema without const gives null;
  • a null inside an object const is kept.

Where const: null is really lost is the swagger-core Jackson path (Yaml31/Json31 mappers): there it becomes Java null and is dropped when written back. That is fixed in swagger-api/swagger-core#5369. This PR doesn't depend on it, and passes against the released swagger-core 2.2.53.

Fixes: #2395 (parser side: verified, no code change needed)

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • ♻️ Refactor (non-breaking change)
  • 🧪 Tests
  • 📝 Documentation
  • 🧹 Chore (build or tooling)

Checklist

  • I have added/updated tests as needed
  • I have added/updated documentation where applicable
  • The PR title is descriptive
  • The code builds and passes tests locally
  • I have linked related issues (if any)

Screenshots / Additional Context

Adds OAI31DeserializationTest#testScalarConstNullOAS31 and 3.1.0/issue-2395.yaml (the spec from the issue). With the core change above installed locally, the whole swagger-parser-v3 test suite passes (697 tests).

Parts of this change were drafted with AI coding assistants (Devin, Claude Code) and reviewed and verified by me.

Locks in that a scalar-level "const: null" stays distinguishable from
a missing const (getConst() returns a NullNode), that object-level
const values keep embedded nulls, and that "const": null survives a
serialize/parse round-trip.

Companion fix in swagger-core adds a constSetFlag mechanism (like
exampleSetFlag/defaultSetFlag) so the same distinction is preserved
for schemas deserialized through swagger-core's own mappers.

Refs swagger-api#2395

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

[Bug]: Const: Null when passed in OpenApi 3.1 Yaml file is silently dropped by the swagger parser, hence producing invalid results

1 participant