Skip to content

KeyError: 'items' validating [] against schema {} #380

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
andersk opened this issue Jan 12, 2022 · 1 comment
Closed

KeyError: 'items' validating [] against schema {} #380

andersk opened this issue Jan 12, 2022 · 1 comment

Comments

@andersk
Copy link
Contributor

andersk commented Jan 12, 2022

Validating an array against the empty schema {} gives KeyError: 'items'. A git bisect shows this was introduced by commit 35f8e28 (#318).

from openapi_core import create_spec
from openapi_core.testing import MockRequest, MockResponse
from openapi_core.validation.response.validators import ResponseValidator

spec = create_spec(
    {
        "openapi": "3.0.3",
        "info": {"version": "0", "title": ""},
        "servers": [{"url": "http://localhost"}],
        "paths": {
            "/test": {
                "get": {
                    "responses": {
                        "200": {
                            "description": "",
                            "content": {"application/json": {"schema": {}}},
                        }
                    },
                }
            }
        },
    }
)
response_validator = ResponseValidator(spec)
request = MockRequest("http://localhost", "get", "/test")
response = MockResponse("[]")
response_validator.validate(request, response)
Traceback (most recent call last):
  File "/home/anders/.cache/pypoetry/virtualenvs/openapi-core-XEMBi3Y7-py3.9/lib/python3.9/site-packages/dictpath/paths.py", line 138, in open
    yield self._content_cached
AttributeError: 'SpecPath' object has no attribute '_content_cached'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/anders/python/openapi-core/items-bug.py", line 27, in <module>
    response_validator.validate(request, response)
  File "/home/anders/python/openapi-core/openapi_core/validation/response/validators.py", line 185, in validate
    data, data_errors = self._get_data(response, operation_response)
  File "/home/anders/python/openapi-core/openapi_core/validation/response/validators.py", line 76, in _get_data
    data = self._unmarshal(schema, casted)
  File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 74, in _unmarshal
    return unmarshaller(value)
  File "/home/anders/python/openapi-core/openapi_core/unmarshalling/schemas/unmarshallers.py", line 48, in __call__
    return self.unmarshal(value)
  File "/home/anders/python/openapi-core/openapi_core/unmarshalling/schemas/unmarshallers.py", line 295, in unmarshal
    return unmarshaller(value)
  File "/home/anders/python/openapi-core/openapi_core/unmarshalling/schemas/unmarshallers.py", line 168, in __call__
    return list(map(self.items_unmarshaller, value))
  File "/home/anders/python/openapi-core/openapi_core/unmarshalling/schemas/unmarshallers.py", line 162, in items_unmarshaller
    return self.unmarshallers_factory.create(self.schema / "items")
  File "/home/anders/python/openapi-core/openapi_core/unmarshalling/schemas/factories.py", line 60, in create
    if schema.getkey("deprecated", False):
  File "/home/anders/.cache/pypoetry/virtualenvs/openapi-core-XEMBi3Y7-py3.9/lib/python3.9/site-packages/dictpath/paths.py", line 128, in getkey
    with self.open() as d:
  File "/nix/store/dn4fwp0yx6nsa85cr20cwvdmg64xwmcy-python3-3.9.9/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/home/anders/.cache/pypoetry/virtualenvs/openapi-core-XEMBi3Y7-py3.9/lib/python3.9/site-packages/dictpath/paths.py", line 140, in open
    with self._open() as content:
  File "/nix/store/dn4fwp0yx6nsa85cr20cwvdmg64xwmcy-python3-3.9.9/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/home/anders/python/openapi-core/openapi_core/spec/accessors.py", line 15, in open
    content = content[part]
KeyError: 'items'
andersk added a commit to andersk/zulip that referenced this issue Jan 13, 2022
This should not be needed, but works around an openapi-core bug:
python-openapi/openapi-core#380

Signed-off-by: Anders Kaseorg <anders@zulip.com>
timabbott pushed a commit to zulip/zulip that referenced this issue Jan 13, 2022
This should not be needed, but works around an openapi-core bug:
python-openapi/openapi-core#380

Signed-off-by: Anders Kaseorg <anders@zulip.com>
yashd26 pushed a commit to yashd26/zulip that referenced this issue Jan 16, 2022
This should not be needed, but works around an openapi-core bug:
python-openapi/openapi-core#380

Signed-off-by: Anders Kaseorg <anders@zulip.com>
Fingel pushed a commit to Fingel/zulip that referenced this issue Jan 21, 2022
This should not be needed, but works around an openapi-core bug:
python-openapi/openapi-core#380

Signed-off-by: Anders Kaseorg <anders@zulip.com>
tiger-yash pushed a commit to tiger-yash/zulip that referenced this issue Mar 8, 2022
This should not be needed, but works around an openapi-core bug:
python-openapi/openapi-core#380

Signed-off-by: Anders Kaseorg <anders@zulip.com>
@p1c2u
Copy link
Collaborator

p1c2u commented Dec 20, 2022

Works with new version hence closing.

@p1c2u p1c2u closed this as completed Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants