python-openapi/openapi-core

[Bug]: Error with multiple schemas in urlencoded request body

rganczarek opened this issue · 0 comments

Actual Behavior

I have this schema:

...
    post:
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              oneOf:
                - $ref: '#/components/schemas/requestA'
                - $ref: '#/components/schemas/requestB'

and when I test a request with data that follows requestB schema I'm getting this error:

{
    "errors": [
        {
            "title": "Value {'errors': [{'title': \"Value {} not valid for schema of type any: (<ValidationError: '{} is not valid under any of the given schemas'>,)\", 'status': 400, 'type': \"<class 'openapi_core.validation.schemas.exceptions.InvalidSchemaValue'>\"}]} not valid for schema of type any: (<ValidationError: '{\\'errors\\': [{\\'title\\': \"Value {} not valid for schema of type any: (<ValidationError: \\'{} is not valid under any of the given schemas\\'>,)\", \\'status\\': 400, \\'type\\': \"<class \\'openapi_core.validation.schemas.exceptions.InvalidSchemaValue\\'>\"}]} is not valid under any of the given schemas'>,)",
            "status": 400,
            "type": "<class 'openapi_core.validation.schemas.exceptions.InvalidSchemaValue'>",
        }
    ]
}

However, when I change the schema to have only one requestBody schema, I get correct results (requestB schema accepts the payload and reuqestA schema returns a list of wrong fields).

Expected Behavior

Validator should validate request trying according to one of the provided request schemas.

Steps to Reproduce

Described in actual behavior

OpenAPI Core Version

0.19.4

OpenAPI Core Integration

django

Affected Area(s)

schema, validation

References

No response

Anything else we need to know?

No response

Would you like to implement a fix?

No