既定値が型と一致しない(OpenAPI 3.0)

defaultの値が宣言されたデータ型と一致していない状態

説明

OpenAPI 3.0 では、default に同じスキーマの type に合う値を指定します。

想定される影響

型が合わないと、文書の検証や SDK の生成に失敗したり、既定値を使うクライアントでエラーになったりします。

対処方法

許容範囲に収まる既定値を選び、値を省略したときのサーバーとクライアントの動作を確認してください。

例

GET / の 200 レスポンスで、既定値を文字列 "a" から整数 1 に変更しています。1 は minimum: 0 も満たします。

変更前

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "integer",
                  "format": "int32",
                  "description": "the size of the pack the dog is from",
                  "default": "a",
                  "minimum": 0
                }
              }
            }
          }
        }
      }
    }
  }
}

変更後

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "integer",
                  "format": "int32",
                  "description": "the size of the pack the dog is from",
                  "default": 1,
                  "minimum": 0
                }
              }
            }
          }
        }
      }
    }
  }
}

参考資料