Closed
Description
Actual Behavior
Traceback (most recent call last):
File "/home/anders/python/openapi-core/openapi_core/validation/decorators.py", line 31, in wrapper
return f(*args, **kwds)
File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 260, in _get_body
value, _ = self._get_content_and_schema(raw_body, content, mimetype)
File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 249, in _get_content_and_schema
self._validate_schema(schema, casted)
File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 144, in _validate_schema
validator.validate(value)
File "/home/anders/python/openapi-core/openapi_core/validation/schemas/validators.py", line 36, in validate
raise InvalidSchemaValue(value, schema_type, schema_errors=errors)
openapi_core.validation.schemas.exceptions.InvalidSchemaValue: Value {'foo': '123'} not valid for schema of type object: (<ValidationError: "'123' is not of type 'integer'">,)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/anders/python/openapi-core/test.py", line 35, in <module>
validate_request(request, spec=spec)
File "/home/anders/python/openapi-core/openapi_core/shortcuts.py", line 321, in validate_request
validate_apicall_request(
File "/home/anders/python/openapi-core/openapi_core/shortcuts.py", line 396, in validate_apicall_request
return v.validate(request)
File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 279, in validate
raise err
File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 114, in _iter_errors
self._get_body(request.body, request.mimetype, operation)
File "/home/anders/python/openapi-core/openapi_core/validation/decorators.py", line 33, in wrapper
self._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_error
raise init(**kw) from exc
openapi_core.validation.request.exceptions.InvalidRequestBody: Request body validation error
Expected Behavior
No error.
Steps to Reproduce
from openapi_core import Spec, validate_request
from openapi_core.testing import MockRequest
spec = Spec.from_dict(
{
"openapi": "3.1.0",
"info": {"version": "0", "title": "test"},
"paths": {
"/test": {
"post": {
"requestBody": {
"content": {
"application/x-www-form-urlencoded": {
"schema": {
"type": "object",
"properties": {"foo": {"type": "integer"}},
},
}
}
},
"responses": {"200": {"description": "OK"}},
}
}
},
}
)
request = MockRequest(
"http://localhost",
"post",
"/test",
data="foo=123",
mimetype="application/x-www-form-urlencoded",
)
validate_request(request, spec=spec)
OpenAPI Core Version
0.18.1 or current Git (cc95ed0)
OpenAPI Core Integration
none
Affected Area(s)
No response
References
No response
Anything else we need to know?
No response
Would you like to implement a fix?
None