python-openapi / openapi-core

Openapi-core is a Python library that adds client-side and server-side support for the OpenAPI v3.0 and OpenAPI v3.1 specification.
BSD 3-Clause "New" or "Revised" License
302 stars 132 forks source link

Using required and allOf together #359

Open flixx opened 3 years ago

flixx commented 3 years ago

Hello,

We are using openapi-core to validate Django Requests.

When I use this syntax:

SaveRequest:
  allOf:
    - $ref: "#/definitions/Dog"
    - required:
      - breed
      - name

I'm getting this error:

...
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/openapi_core/validation/request/validators.py", line 204, in _get_body
    body = self._unmarshal(media_type, casted)
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/openapi_core/validation/request/validators.py", line 255, in _unmarshal
    return super(RequestValidator, self)._unmarshal(
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/openapi_core/validation/validators.py", line 66, in _unmarshal
    return unmarshaller(value)
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 49, in __call__
    self.validate(value)
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/openapi_core/unmarshalling/schemas/unmarshallers.py", line 61, in validate
    errors = tuple(errors_iter)
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/jsonschema/validators.py", line 328, in iter_errors
    for error in errors:
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/jsonschema/_validators.py", line 315, in allOf
    for error in validator.descend(instance, subschema, schema_path=index):
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/jsonschema/validators.py", line 344, in descend
    for error in self.iter_errors(instance, schema):
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/jsonschema/validators.py", line 328, in iter_errors
    for error in errors:
  File "/Users/felix/Library/Caches/pypoetry/virtualenvs/button3d-iF01JEUe-py3.8/lib/python3.8/site-packages/openapi_schema_validator/_validators.py", line 43, in required
    prop_schema = schema['properties'][property]

According to this thread, it is a valid schema though: https://github.com/OAI/OpenAPI-Specification/issues/1608

Also related issue: https://github.com/p1c2u/openapi-core/issues/77

doemski commented 1 year ago

Any news on this issue? Seems to still persist.

Also is there a workaround?

p1c2u commented 1 year ago

@doemski please report separate issue with your details