数値形式が未指定(OpenAPI 3.0)

数値の表現方法を示すformatが指定されていない状態

説明

クライアントとサーバーで数値のサイズや精度をそろえる必要がある場合は、任意の 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
          }
        }
      }
    }
  }
}

参考資料