説明
クライアントとサーバーで数値のサイズや精度をそろえる必要がある場合は、任意の format フィールドを使います。
想定される影響
ツールが異なる型を生成すると、値が切り捨てられたり、シリアライズ結果が異なったりすることがあります。
対処方法
integer には int32 または int64、number には float または double を指定し、ツールが生成する型を確認します。値の許容範囲は minimum と maximum で指定します。
例
例では code に int32 を追加します。許容範囲は引き続き 0 から 50 です。
変更前
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": 0,
"maximum": 50
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32",
"minimum": 0,
"maximum": 50
}
}
}
}
}
}