An OpenAPI operation has no declared authentication requirement

Declare authentication for protected operations through global or operation-level security.

Description

If neither the operation nor the document defines security, the specification gives that operation no authentication requirement. This is valid for a public operation.

Potential impact

For a protected operation, a generated client may omit credentials and have its request rejected.

Remediation

Reference the server’s authentication scheme on the protected operation, or set top-level security once for operations that share it.

Examples

Both examples already define exampleSecurity. Adding the global reference tells clients to send X-API-Key for GET /.

Before

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "exampleSecurity": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "ok"
          }
        }
      }
    }
  },
  "security": [
    {
      "exampleSecurity": []
    }
  ],
  "components": {
    "securitySchemes": {
      "exampleSecurity": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      }
    }
  }
}

References