Skip to content

Failure to correctly validate required in allOf #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sebastianmika opened this issue Jun 24, 2021 · 2 comments
Closed

Failure to correctly validate required in allOf #15

sebastianmika opened this issue Jun 24, 2021 · 2 comments

Comments

@sebastianmika
Copy link
Contributor

Having one spec with optional properties and creating a derived spec using allOf that makes a property required fails. This should be supported according to json schema itself (e.g. here)

To reproduce (with 0.1.5):

from openapi_schema_validator import validate


schema = {
    "allOf": [
        {"type": "object", "properties": {"some_prop": {"type": "string"}}},
        {"type": "object", "required": ["some_prop"]},
    ]
}

validate({"another_prop": "bla"}, schema)

Expected behaviour: an error that the required property some_prop is missing. The code actually correctly figures that out, but when it tries to check whether it is ok to have that property missing because it is e.g. a readOnly missing in a write operation a "runtime" error is produced instead of a validation exception:

~/venvs/py39/lib/python3.9/site-packages/openapi_schema_validator/_validators.py in required(validator, required, instance, schema)
     41     for property in required:
     42         if property not in instance:
---> 43             prop_schema = schema['properties'][property]
     44             read_only = prop_schema.get('readOnly', False)
     45             write_only = prop_schema.get('writeOnly', False)

KeyError: 'properties'

The problem is that here schema is only the second schema with the required - but the property can come from any schema in the allOf.

@sebastianmika
Copy link
Contributor Author

Ok - looking closer I would say the root cause is the same as in #14

@p1c2u
Copy link
Collaborator

p1c2u commented Dec 28, 2021

Fix merged hence closing

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

No branches or pull requests

2 participants