Detect nullable in OpenAPI 3.1 documents (NullableDeprecation rule)#193
Open
takayamaki wants to merge 2 commits into
Open
Detect nullable in OpenAPI 3.1 documents (NullableDeprecation rule)#193takayamaki wants to merge 2 commits into
nullable in OpenAPI 3.1 documents (NullableDeprecation rule)#193takayamaki wants to merge 2 commits into
Conversation
Spec_validator only. `nullable` is removed in 3.1; any presence on a 3.1 document is flagged, regardless of true/false. Detection inspects raw_schema directly so a literal `nullable: false` is not confused with the field being absent.
`nullable` on a 3.1 document warns and raises (removed in favour of type: [..., null]); the same keyword on a 3.0 document stays clean.
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.
ref: #152
Continuing the OpenAPI 3.1 work from #192.
This PR adds a new
SpecValidatorrule:OpenAPIParser::SpecValidator::Rules::NullableDeprecationDesign
In 3.0,
nullable: truemarks a schema as acceptingnull.3.1 removed the keyword entirely in favor of
type: [..., "null"].The rule flags the mere presence of
nullableon a 3.1 document —trueandfalseare both violations, since the field itself is gone.This matches how OAS treats removed keywords: it is not about the value, it is about the keyword being there at all.
Implementation details
Detection inspects
raw_schemadirectlyschema.nullablereturnsfalsewhen the key is absent and when it is explicitly set tofalse. The rule needs to distinguish those two states,so it checks
schema.raw_schema.key?('nullable')instead of the accessor:Wiring
One line added to the
rulesarray inSpecValidator, plus the rule file underspec_validator/rules/. No changes to the parse layer or runtime— parsing continues to accept
nullableon either version; only the validator reports it.Tests
nullable: true/false(clean), 3.1 withnullable: true/false(both flagged), 3.1 withoutnullable(clean),
:unknownversion (skipped).openapi_3_1/nullable_30.yamlandnullable_31.yamlfixtures.