I have written many APIs in C# and created a "Swagger" documentation website using Swashbuckle.
For Authenticate REST calls I use an API Key in the header.
I created a page that permits to download a specific client for any programming language as documented here: https://generator.swagger.io
I would like to enable the user to generate a client with his own API Key so he does not need to manually set the API Key in the code anymore.
In my Swagger JSON I have this security definition:
"securityDefinitions": {
"apiKey": {
"type": "apiKey",
"description": "API Key Authentication",
"name": "X-ApiKey",
"in": "header"
}
}
In Swagger Client Generator's page I have found this model that permit to set up the clients options but I cannot find how (and if) the API key can be hard coded (or any other kind of authorization) in the client code.
GeneratorInput {
spec (object, optional),
options (object, optional),
swaggerUrl (string, optional),
authorizationValue (AuthorizationValue, optional),
securityDefinition (SecuritySchemeDefinition, optional)
}
AuthorizationValue {
value (string, optional),
type (string, optional),
keyName (string, optional)
}
SecuritySchemeDefinition {
description (string, optional),
type (string, optional)
}
I suppose I must set AuthorizationValue object but there is no documentation about that (or I can not find it).
It would be sufficient to be able to be able to have the generated client lib add an arbitrary HTTP header to all requests.
In which case we could just have it add:
X-ApiKey:{whatever the key is}
Anyone has an idea ?
Many Thanks!