All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dart2-v3template.auth.api_key_auth.mustache Maven / Gradle / Ivy

Go to download

dart2 generator from openapi 3.x spec files. Changing to openapitools dependencies.

There is a newer version: 4.7
Show newest version
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;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy