Skip to content

[0.14.0 regression] param['schema']['type'] in ['array', 'object'] raises KeyError: 'type' #322

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 May 8, 2021 · 0 comments · Fixed by #323
Closed
Labels
area/schema Indicates an issue on schema area kind/bug/confirmed

Comments

@andersk
Copy link
Contributor

andersk commented May 8, 2021

This succeeds in 0.13.8 and unexpectedly raises KeyError: 'type' in 0.14.0. I bisected the problem to commit 35f8e28 “Spec path”.

from openapi_core import create_spec
from openapi_core.testing import MockRequest
from openapi_core.validation.request.validators import RequestValidator

spec = create_spec(
    {
        "openapi": "3.0.0",
        "info": {"title": "test", "version": "0"},
        "paths": {
            "/messages": {
                "get": {
                    "parameters": [
                        {
                            "name": "anchor",
                            "in": "query",
                            "schema": {
                                "oneOf": [{"type": "string"}, {"type": "integer"}]
                            },
                        }
                    ],
                    "responses": {"200": {"description": "Success."}},
                }
            }
        },
    },
)
validator = RequestValidator(spec)
request = MockRequest(
    "http://localhost", "GET", "/messages", args={"anchor": "first_unread"}
)
result = validator.validate(request)
result.raise_for_errors()
Traceback (most recent call last):
  File "oneof_test.py", line 31, in <module>
    result = validator.validate(request)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 48, in validate
    params, params_errors = self._get_parameters(
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 138, in _get_parameters
    raw_value = self._get_parameter_value(param, request)
  File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 226, in _get_parameter_value
    aslist = get_aslist(param)
  File "/home/anders/python/openapi-core/openapi_core/schema/parameters.py", line 4, in get_aslist
    param['schema']['type'] in ['array', 'object']
KeyError: 'type'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/schema Indicates an issue on schema area kind/bug/confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants