[BUG][dart] Dart generated code for authentication only supports OAuth2
Created by: dalewking
Description
When you have a spec that uses apiKey authentication the dart generator dutifully generates an ApiKeyAuth class and puts an instance of it into the list of authentications for the ApiClient. The problem is that there is no way to actually use this class in that you cannot actually set the access token on it.
The problem is that the setAccessTokens method generated on ApiClient does not actually do anything for ApiKeyAuth. Here is the code it generates:
void setAccessToken(String accessToken) {
_authentications.forEach((key, auth) {
if (auth is OAuth) {
auth.setAccessToken(accessToken);
}
});
}
openapi-generator version
3.3.4 and 4.0.0 behave the same
Suggest a fix
Change the template for setAccessTokens to include:
else if (auth is ApiKeyAuth) {
auth.apiKey = accessToken;
}
Would be nice if it also supported apiKeyPrefix, but I'm not holding my breath.
The generated documentation contains examples saying you can do it like this:
// TODO Configure API key authorization: jwt
//my_service.api.Configuration.apiKey{'Authorization'} = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//my_service.api.Configuration.apiKeyPrefix{'Authorization'} = "Bearer";
But there is no such Configuration class