Search code examples
c#swaggerswagger-codegen

swagger api key in header


I am using swagger codegen to create C# code to use as a client api call.

java -jar swagger-codegen-cli.jar generate -i http://testing.com/swagger/docs/v1 -c config.json -l csharp -o testing-api

config.json:

{
  "modelPropertyNaming": "PascalCase",
  "securityDefinitions": {
    "apiKey": {
      "type": "apiKey",
      "description": "API Key Authentication",
      "name": "X-Key",
      "in": "header"
    }
  }
}

This is how I call the api using the generated c# code:

var apiInstance = new EventApi();
var testRequest = new TestRequest(); 

apiInstance.TestSendEvent(testRequest );

How can I add spi key in the header?


Solution

  • I can do this, and it works:

    apiInstance.Configuration.AddDefaultHeader("X-Key", "12345");