You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OpenAPI allows specifying an application/x-www-form-urlencoded request body that contains individual application/json encoded properties, by using the contentType field of the encoding object. The Swagger specification shows an example of this (under “Complex Serialization in Form Data”, and reproduced below). However, openapi-core ignores the contentType field and fails to validate a valid request against such a spec.
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 253, in _get_bodyreturnself._get_content_value(raw_body, mimetype, content)
File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 126, in _get_content_valueself._validate_schema(schema, casted)
File "/home/anders/python/openapi-core/openapi_core/validation/validators.py", line 102, in _validate_schema
validator.validate(value)
File "/home/anders/python/openapi-core/openapi_core/validation/schemas/validators.py", line 36, in validateraise InvalidSchemaValue(value, schema_type, schema_errors=errors)
openapi_core.validation.schemas.exceptions.InvalidSchemaValue: Value {'payload': '{"text":"Swagger is awesome"}'} not valid for schema of type object: (<ValidationError: '\'{"text":"Swagger is awesome"}\' is not of type \'object\''>,)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/anders/python/openapi-core/post_encoding_test.py", line 65, in <module>
validate_request(request, spec=spec)
File "/home/anders/python/openapi-core/openapi_core/shortcuts.py", line 305, in validate_request
validate_apicall_request(
File "/home/anders/python/openapi-core/openapi_core/shortcuts.py", line 379, in validate_apicall_requestreturn v.validate(request)
File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 269, in validateraise err
File "/home/anders/python/openapi-core/openapi_core/validation/request/validators.py", line 110, in _iter_errorsself._get_body(request.body, request.mimetype, operation)
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.InvalidRequestBody: Request body validation error
Expected Behavior
This request should successfully validate.
Steps to Reproduce
importyamlfromurllib.parseimporturlencodefromopenapi_coreimportSpecfromopenapi_coreimportvalidate_requestfromopenapi_core.testingimportMockRequestSPEC=r"""openapi: 3.0.0info: version: 1.0.0 title: Slack Incoming WebhookexternalDocs: url: https://api.slack.com/incoming-webhooksservers: - url: https://hooks.slack.compaths: /services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX: post: summary: Post a message to Slack requestBody: content: application/json: schema: $ref: '#/components/schemas/Message' application/x-www-form-urlencoded: schema: type: object properties: payload: # <--- form field that contains the JSON message $ref: '#/components/schemas/Message' encoding: payload: contentType: application/json responses: '200': description: OKcomponents: schemas: Message: title: A Slack message type: object properties: text: type: string description: Message text required: - text"""spec=Spec.from_dict(yaml.safe_load(SPEC))
request=MockRequest(
"https://hooks.slack.com/",
"post",
"/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX",
data=urlencode({"payload": '{"text":"Swagger is awesome"}'}),
mimetype="application/x-www-form-urlencoded",
)
validate_request(request, spec=spec)
OpenAPI Core Version
0.18.0
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
The text was updated successfully, but these errors were encountered:
Actual Behavior
OpenAPI allows specifying an
application/x-www-form-urlencoded
request body that contains individualapplication/json
encoded properties, by using thecontentType
field of the encoding object. The Swagger specification shows an example of this (under “Complex Serialization in Form Data”, and reproduced below). However, openapi-core ignores thecontentType
field and fails to validate a valid request against such a spec.Expected Behavior
This request should successfully validate.
Steps to Reproduce
OpenAPI Core Version
0.18.0
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
The text was updated successfully, but these errors were encountered: