Repository navigation
Ignore $ref sibling keywords in OAS 3.0 validators - #305
Open
josephaxisa wants to merge 1 commit into
Open
josephaxisa wants to merge 1 commit into
josephaxisa wants to merge 1 commit into
Conversation
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.
Fixes #304
In OpenAPI 3.0 (§4.7.24 Reference Object), a Reference Object (
{"$ref": "..."}) cannot be extended and any sibling keywords next to$refhave to be ignored (matching Draft 4 /json-referencebehavior). OpenAPI 3.1 and 3.2 switched to JSON Schema Draft 2020-12, where$refsiblings are evaluated alongside the referenced schema.Because
jsonschema.validators.create()defaultsapplicable_validatorsto evaluating every keyword on the schema dict (whereasDraft4Validatorexplicitly passesapplicable_validators=_legacy_keywords.ignore_ref_siblings),_build_oas30_validator()was evaluating sibling keywords next to$ref.In practice, OAS 3.0 specs and code-first generators often leave sibling keywords like
nullable,readOnly,writeOnly,type, orminLengthon$refproperties. WhenOAS30Validator(or downstream callers likeopenapi-core) validates against those schemas, two things go wrong:nullable: false,minLength,type,required) conflicts with or narrows the referenced target schema.$refproperty has a siblingreadOnly: trueorwriteOnly: true, becauserequired,read_required, andwrite_requiredin_keywords.pyinspectprop_schema.get("readOnly")/prop_schema.get("writeOnly")directly on the parent'spropertiesdict before$refresolution.What changed
applicable_validators=_legacy_keywords.ignore_ref_siblingsin_build_oas30_validator()(openapi_schema_validator/validators.py). This is inherited viaextend()byOAS30Validator,OAS30StrictValidator,OAS30ReadValidator,OAS30WriteValidator, andbuild_enforce_properties_required_validator(OAS30*), while leavingOAS31ValidatorandOAS32Validatoruntouched.if prop_schema and "$ref" not in prop_schema:inrequired,read_required, andwrite_required(openapi_schema_validator/_keywords.py) so siblingreadOnly/writeOnlyflags on a$refproperty don't suppress missing-required errors in OAS 3.0.OAS30Validator,OAS30StrictValidator,OAS30ReadValidator,OAS30WriteValidator,build_enforce_properties_required_validator,OAS31Validator,OAS32Validator, andvalidate().