Swagger UI refuses to add request header · swagger-api/swagger-ui Wiki · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Swagger UI refuses to add request header

Darren L. Weber, Ph.D edited this page Jan 20, 2018 · 1 revision

Extracted from https://github.com/swagger-api/swagger-ui/issues/1244, i.e.

For those who land here, like me, looking for more information, the missing piece for me was the matching name for the securityDefinitions, security and the JS code use of the same name. For example, here is some swagger spec JSON to specify global API token access:

    "securityDefinitions": {
      "my_token": {
        "type": "apiKey",
        "description": "Authorization Token",
        "name": "my_token",
        "in": "header"
      }
    },
    "security": [
      { "my_token": [] }
    ],

Given that API spec, the JS code to match must use the same name, i.e. "my_token", as in:

var tokenAuth = new SwaggerClient.ApiKeyAuthorization("Authorization", "Token " + token, "header");
window.swaggerUi.api.clientAuthorizations.add("my_token", tokenAuth);

The name of the securityDefinitions is arbitrary and crucial. Most of the examples use "api_key", but you might want something else. The string "api_key" is just a name, it's not a reserved identifier with special meaning for swagger-ui, it's arbitrary (AFAICT).

Clone this wiki locally

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.