How to customize API validation error response in Flask

オープン
#564 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
flask, python
領域
api, backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
368
フォーク
140
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python-openapi/openapi-core のほかの issue

python-openapi/openapi-core の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。