OpenAPI リンクに operationId と operationRef を同時指定

リンク先は operationId または operationRef のどちらかで指定してください。

説明

Link の対象は operationId または operationRef のどちらかで指定します。同じ操作を指す場合でも、OpenAPI 3.0 では併用できません。

想定される影響

両方を宣言した Link はツールに拒否される場合があります。

対処方法

文書内の一意の操作 ID で指定するには operationId、操作の URI 参照で指定するには operationRef を使います。もう一方を削除し、パラメーターの対応を確認します。

例

再利用する応答の address リンクは getUserAddress を残し、uuid を userid に対応付けています。操作からこの応答を参照すると、呼び出し元がリンクに従って次のリクエストを送信できます。文書全体を検証する場合は、別に参照されている Pet と User のスキーマも必要です。

変更前

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "the user being returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "uuid": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/users/{userid}/address": {
      "parameters": [
        {
          "name": "userid",
          "in": "path",
          "required": true,
          "description": "the user identifier, as userId",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getUserAddress",
        "responses": {
          "200": {
            "description": "the user's address"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "200": {
        "description": "the user being returned",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "uuid": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        },
        "links": {
          "address": {
            "operationId": "getUserAddress",
            "operationRef": "#/paths/~1users~1{userid}~1address/get",
            "parameters": {
              "userid": "$response.body#/uuid"
            }
          }
        }
      }
    },
    "schemas": {
      "Pet": {
        "$ref": "../models/pet.yaml"
      },
      "User": {
        "$ref": "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
      }
    }
  }
}

変更後

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "the user being returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "uuid": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/users/{userid}/address": {
      "parameters": [
        {
          "name": "userid",
          "in": "path",
          "required": true,
          "description": "the user identifier, as userId",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getUserAddress",
        "responses": {
          "200": {
            "description": "the user's address"
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "200": {
        "description": "the user being returned",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "uuid": {
                  "type": "string",
                  "format": "uuid"
                }
              }
            }
          }
        },
        "links": {
          "address": {
            "operationId": "getUserAddress",
            "parameters": {
              "userid": "$response.body#/uuid"
            }
          }
        }
      }
    },
    "schemas": {
      "Pet": {
        "$ref": "../models/pet.yaml"
      },
      "User": {
        "$ref": "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
      }
    }
  }
}

参考資料