Support type: "null" for OpenAPI 3.1 schemas (runtime + TypeNullIn30 rule)#197
Open
takayamaki wants to merge 4 commits into
Open
Support type: "null" for OpenAPI 3.1 schemas (runtime + TypeNullIn30 rule)#197takayamaki wants to merge 4 commits into
takayamaki wants to merge 4 commits into
Conversation
- nil_validator now passes when schema declares `type: \"null\"` even without `nullable: true` - NullTypeValidator handles non-nil values against `type: \"null\"` with a ValidateError so 3.1 enforces the singleton-null semantic - Rules::TypeNullIn30 flags `type: \"null\"` on 3.0 documents
type: "null" on a 3.0 document warns and raises (3.0 has no such primitive); the same type on a 3.1 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.
Continuing the OpenAPI 3.1 work from #195 / #152.
OpenAPI 3.1 (via JSON Schema) adds
"null"as a primitive type name.In 3.0, nullability was expressed via the
nullablekeyword;type: "null"had no meaning.This PR adds both runtime validation and version-mismatch detection for
type: "null".Runtime validation
The accept side and the reject side live in two different validators,
because of how
SchemaValidator#validatordispatches:Accepting
nilhappens in the existing
NilValidator, which handles all nil values regardless of schema type. It now treatsschema.type == "null"as valid, exactly like the existingnullable: truepath.Rejecting everything else
happens in the new
NullTypeValidator. Since nil values are routed toNilValidatorbefore the type dispatch, any value reaching thewhen 'null'branch is by construction non-nil.So
NullTypeValidatorunconditionally returns a validation error.Without the new branch,
type: "null"would fall through toUnspecifiedTypeValidatorand accept any value.SpecValidator rule
TypeNullIn30walks all schemas and reports a violation when a 3.0 document usestype: "null".Array-form types like
["string", "null"]are covered by a separate rule in a later PR.