Skip to content

How to customize API validation error response in Flask #564

Open
@rohan-97

Description

@rohan-97

Actual Behavior

Getting generic resposne on validation error

{
    "errors": [
        {
            "class": "<class 'openapi_core.validation.schemas.exceptions.InvalidSchemaValue'>",
            "status": 400,
            "title": "Value {'flag': 'testF'} not valid for schema of type object: (<ValidationError: \"'testF' is too short\">,)"
        }
    ]
}

Expected Behavior

We should be able to generate custom responses, and should be able to capture the validation error info e.g. status code, validation error message, and title

Steps to Reproduce

I set up a flask server and followed the instructions provided here

Currently openapi-core is validating the incoming requets properly, however the response generated is as follows

{
    "errors": [
        {
            "class": "<class 'openapi_core.validation.schemas.exceptions.InvalidSchemaValue'>",
            "status": 400,
            "title": "Value {'flag': 'testF'} not valid for schema of type object: (<ValidationError: \"'testF' is too short\">,)"
        }
    ]
}

I want to customize the response body as per my application,

I wanted to know if is there any provision using which we can provide custom responses.

or even if we somehow capture the validation error info e.g. status code, validation error message, and title then we can generate our own response with the available information.

Thanks in advance

OpenAPI Core Version

0.17.1

OpenAPI Core Integration

Flask

Affected Area(s)

No response

References

No response

Anything else we need to know?

No response

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions