dart2-v3template.auth.api_key_auth.mustache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of connect-openapi-dart Show documentation
Show all versions of connect-openapi-dart Show documentation
dart2 generator from openapi 3.x spec files. Changing to openapitools dependencies.
part of {{pubName}}.api;
class ApiKeyAuth implements Authentication {
final String location;
final String paramName;
String _apiKey;
String apiKeyPrefix;
set apiKey(String key) => _apiKey = key;
ApiKeyAuth(this.location, this.paramName);
@override
void applyToParams(List queryParams, Map headerParams) {
String value;
if (apiKeyPrefix != null) {
value = '$apiKeyPrefix $_apiKey';
} else {
value = _apiKey;
}
if (location == 'query' && value != null) {
queryParams.add(QueryParam(paramName, value));
} else if (location == 'header' && value != null) {
headerParams[paramName] = value;
}
}
}