How to customize API validation error response in Flask

Đang mở
#564 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
flask, python
Lĩnh vực
api, backend

Hướng nghiên cứu

Start with the Flask integration instructions linked in the issue and trace how incoming validation errors are turned into the generic response. Determine how an application could customize the response while accessing the status code, validation message, and title; done should include documented, working behavior for custom responses.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area/documentation kind/bug kind/missing-implementation
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

Ngôn ngữ chính
Python
Star
368
Fork
140
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python-openapi/openapi-core

Tất cả issue của python-openapi/openapi-core

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.