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

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

説明

スキーマの default 値は、フィールドの型と一致している必要があります。例えば、type: integer の既定値に文字列 "a" を指定すると、型の定義と矛盾します。

想定される影響

コード生成や検証に失敗したり、既定値を使うクライアントで型エラーが発生したりする可能性があります。

対処方法

default を実際の型と許容範囲に合わせて修正してください。値が省略されたときのサーバーの動作も、文書の既定値と一致することを確認してください。

例

次のOpenAPI 3.0の例では、整数スキーマの既定値を文字列 "a" から整数 1 に修正しています。

変更前

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
                }
              }
            }
          }
        }
      }
    }
  }
}

参考資料