Skip to content

[Bug]: 0.23.0 regression: default: [] leads to ValidationError: "SchemaPath('…#default') is not of type 'array'" #1157

Description

@andersk

Actual Behavior

A simple array parameter with a default value like this:

name: fooin: queryschema:
type: arraydefault: []

leads to an error in 0.23.0:

Traceback (most recent call last):
File "/home/anders/python/openapi-core/openapi_core/validation/decorators.py", line 31, in wrapperreturn f(*args, **kwds)
File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 208, in _get_parameter
value, _ =self._get_param_or_header_and_schema(param, location)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 196, in _get_param_or_header_and_schemaself._validate_schema(schema, casted)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 174, in _validate_schema
validator.validate(value)
~~~~~~~~~~~~~~~~~~^^^^^^^
File "/home/anders/python/openapi-core/openapi_core/validation/schemas/validators.py", line 40, in validateraise InvalidSchemaValue(value, schema_type, schema_errors=errors)
openapi_core.validation.schemas.exceptions.InvalidSchemaValue: Value paths#/test#get#parameters#0#schema#default not valid for schema of type array: (<ValidationError: "SchemaPath('paths#/test#get#parameters#0#schema#default') is not of type 'array'">,)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/anders/python/openapi-core/default_test.py", line 25, in <module>
spec.validate_request(request)
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/home/anders/python/openapi-core/openapi_core/app.py", line 564, in validate_requestself.validate_apicall_request(request)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/home/anders/python/openapi-core/openapi_core/app.py", line 613, in validate_apicall_requestself.request_validator.validate(request)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 287, in validateraise err
File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 172, in _get_parameters
value =self._get_parameter(parameters, param)
File "/home/anders/python/openapi-core/openapi_core/validation/decorators.py", line 33, in wrapperself._raise_error(exc, self.err_validate_cls, f, *args, **kwds)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/anders/python/openapi-core/openapi_core/validation/decorators.py", line 58, in _raise_errorraise init(**kw) from exc
openapi_core.validation.request.exceptions.InvalidParameter: Invalid query parameter: foo

Expected Behavior

No errors; this worked in 0.22.0.

Steps to Reproduce

fromopenapi_coreimportOpenAPIfromopenapi_core.testingimportMockRequestspec=OpenAPI.from_dict(
{
"openapi": "3.1.0",
"info": {"version": "0", "title": "Test"},
"paths": {
"/test": {
"get": {
"parameters": [
{
"name": "foo",
"in": "query",
"schema": {"type": "array", "default": []},
}
],
"responses": {"200": {"description": ""}},
},
}
},
}
)
request=MockRequest("http://localhost", "get", "/test")
spec.validate_request(request)

OpenAPI Core Version

0.23.0

OpenAPI Core Integration

MockRequest

Affected Area(s)

schema, validation

References

No response

Anything else we need to know?

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions