-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from nekochans/feature/issue128/add-openapime…
…ta-to-errormodels API Docが見やすくなるように改善を実施
- Loading branch information
Showing
2 changed files
with
70 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,80 @@ | ||
from pydantic import BaseModel | ||
from pydantic import BaseModel, Field | ||
from typing import Literal | ||
|
||
|
||
class UnauthorizedError(BaseModel): | ||
type: Literal["UNAUTHORIZED"] | ||
title: Literal["Invalid Authorization Header."] | ||
type: Literal["UNAUTHORIZED"] = Field( | ||
description="問題のタイプを識別する文字列 RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": ["UNAUTHORIZED"], | ||
}, | ||
) | ||
title: Literal["Invalid Authorization Header."] = Field( | ||
description="エラーのタイトル RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": ["Invalid Authorization Header."], | ||
}, | ||
) | ||
|
||
|
||
class UnexpectedErrorBody(BaseModel): | ||
type: Literal["INTERNAL_SERVER_ERROR"] | ||
title: Literal["an unexpected error has occurred."] | ||
type: Literal["INTERNAL_SERVER_ERROR"] = Field( | ||
description="問題のタイプを識別する文字列 RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": ["INTERNAL_SERVER_ERROR"], | ||
}, | ||
) | ||
title: Literal["an unexpected error has occurred."] = Field( | ||
description="エラーのタイトル RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": ["an unexpected error has occurred."], | ||
}, | ||
) | ||
|
||
|
||
class InvalidParam(BaseModel): | ||
name: str | ||
reason: str | ||
name: str = Field( | ||
description="バリデーションに引っかかったキー名 RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": ["userId", "message"], | ||
}, | ||
) | ||
reason: str = Field( | ||
description="バリデーションに引っかかった理由 RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": [ | ||
"userId is not in UUID format", | ||
"message must be at least 2 character and no more than 5,000 characters", | ||
], | ||
}, | ||
) | ||
|
||
|
||
class ValidationErrorBody(BaseModel): | ||
type: Literal["UNPROCESSABLE_ENTITY"] | ||
title: Literal["validation Error."] | ||
invalidParams: list[InvalidParam] | ||
type: Literal["UNPROCESSABLE_ENTITY"] = Field( | ||
description="問題のタイプを識別する文字列 RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": ["UNPROCESSABLE_ENTITY"], | ||
}, | ||
) | ||
title: Literal["validation Error."] = Field( | ||
description="エラーのタイトル RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": ["validation Error."], | ||
}, | ||
) | ||
invalidParams: list[InvalidParam] = Field( | ||
description="バリデーションエラーの詳細情報 RFC7807を参考に定義した https://zenn.dev/ryamakuchi/articles/d7c932afc57e30", | ||
json_schema_extra={ | ||
"examples": [ | ||
{ | ||
"name": "userId", | ||
"reason": "userId is not in UUID format", | ||
}, | ||
{ | ||
"name": "message", | ||
"reason": "message must be at least 2 character and no more than 5,000 characters", | ||
}, | ||
], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters