Link Object OperationId Does Not Target Operation Object

  • Query id: c5bb7461-aa57-470b-a714-3bc3d74f4669
  • Query name: Link Object OperationId Does Not Target Operation Object
  • Platform: OpenAPI
  • Severity: Info
  • Category: Structure and Semantics
  • URL: Github

Description

Link object 'OperationId' should target an existing operation object in the OpenAPI definition
Documentation

Code samples

Code samples with security vulnerabilities

Positive test num. 1 - json file
{
  "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": "getUser2Address",
            "parameters": {
              "userId": "$request.path.id"
            }
          }
        }
      }
    },
    "schemas": {
      "Pet": {
        "$ref": "../models/pet.yaml"
      },
      "User": {
        "$ref": "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
      }
    }
  }
}
Positive test num. 2 - json file
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/test": {
      "get": {
        "responses": {
          "200": {
            "description": "the user being returned",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "uuid": {
                      "format": "uuid",
                      "type": "string"
                    }
                  }
                }
              }
            },
            "links": {
              "address": {
                "operationId": "getUserAddress",
                "parameters": {
                  "userId": "$request.path.id"
                }
              }
            }
          }
        }
      }
    },
    "/users/{userid}/address": {
      "parameters": [
        {
          "name": "userid",
          "in": "path",
          "required": true,
          "description": "the user identifier, as userId",
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getUserwAddress",
        "responses": {
          "200": {
            "description": "the user's address"
          }
        }
      }
    }
  }
}
Positive test num. 3 - json file
{
  "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": {
    "schemas": {
      "Pet": {
        "$ref": "../models/pet.yaml"
      },
      "User": {
        "$ref": "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
      }
    },
    "responses": {
      "GenericError": {
        "$ref": "../template-api.yaml#/components/responses/GenericError"
      }
    },
    "links": {
      "address": {
        "operationId": "getUsewerAddress",
        "parameters": {
          "userId": "$request.path.id"
        }
      }
    }
  }
}

Positive test num. 4 - yaml file
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:
  schemas:
    Pet:
      $ref: "../models/pet.yaml"
    User:
      $ref: "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
  responses:
    "200":
      description: the user being returned
      content:
        application/json:
          schema:
            type: object
            properties:
              uuid:
                type: string
                format: uuid
      links:
        address:
          operationId: getUserAsddress
          parameters:
            userId: $request.path.id
Positive test num. 5 - yaml file
openapi: 3.0.0
info:
  title: Simple API overview
  version: 1.0.0
paths:
  "/test":
    get:
      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: $request.path.id
  "/users/{userid}/address":
    parameters:
      - name: userid
        in: path
        required: true
        description: the user identifier, as userId
        schema:
          type: string
    get:
      operationId: getUserAdsssdress
      responses:
        "200":
          description: the user's address
Positive test num. 6 - yaml file
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:
  schemas:
    Pet:
      $ref: "../models/pet.yaml"
    User:
      $ref: "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
  responses:
    GenericError:
      $ref: "../template-api.yaml#/components/responses/GenericError"
  links:
    address:
      operationId: getUssssserAddress
      parameters:
        userId: $request.path.id

Code samples without security vulnerabilities

Negative test num. 1 - json file
{
  "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": "$request.path.id"
            }
          }
        }
      }
    },
    "schemas": {
      "Pet": {
        "$ref": "../models/pet.yaml"
      },
      "User": {
        "$ref": "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
      }
    }
  }
}
Negative test num. 2 - json file
{
  "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": {
                      "format": "uuid",
                      "type": "string"
                    }
                  }
                }
              }
            },
            "links": {
              "address": {
                "operationId": "getUserAddress",
                "parameters": {
                  "userId": "$request.path.id"
                }
              }
            }
          }
        }
      }
    },
    "/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"
          }
        }
      }
    }
  }
}
Negative test num. 3 - json file
{
  "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": {
    "schemas": {
      "Pet": {
        "$ref": "../models/pet.yaml"
      },
      "User": {
        "$ref": "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
      }
    },
    "responses": {
      "GenericError": {
        "$ref": "../template-api.yaml#/components/responses/GenericError"
      }
    },
    "links": {
      "address": {
        "operationId": "getUserAddress",
        "parameters": {
          "userId": "$request.path.id"
        }
      }
    }
  }
}

Negative test num. 4 - yaml file
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:
  schemas:
    Pet:
      $ref: "../models/pet.yaml"
    User:
      $ref: "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
  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: $request.path.id
Negative test num. 5 - yaml file
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
          links:
            address:
              operationId: getUserAddress
              parameters:
                userId: $request.path.id
  "/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
Negative test num. 6 - yaml file
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:
  schemas:
    Pet:
      $ref: "../models/pet.yaml"
    User:
      $ref: "https://api.example.com/v2/openapi.yaml#/components/schemas/User"
  responses:
    GenericError:
      $ref: "../template-api.yaml#/components/responses/GenericError"
  links:
    address:
      operationId: getUserAddress
      parameters:
        userId: $request.path.id