OpenAPI link defines both operationId and operationRef

Identify a link target with either operationId or operationRef.

Description

Identify a Link’s target with either operationId or operationRef. OpenAPI 3.0 permits only one, even if both identify the same operation.

Potential impact

Tools can reject a Link that declares both fields.

Remediation

Use operationId for a unique operation ID in the document or operationRef for a URI reference to an operation. Remove the other field and verify the parameter mapping.

Examples

The reusable response’s address link keeps getUserAddress and maps uuid to userid. Reference that response from an operation. The caller can then make the follow-up request. The separate Pet and User schema references need their targets for full-document validation.

Before

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

After

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

References