github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/libraries/feign/auth/ApiKeyAuth.mustache (about) 1 package {{invokerPackage}}.auth; 2 3 import feign.RequestInterceptor; 4 import feign.RequestTemplate; 5 6 public class ApiKeyAuth implements RequestInterceptor { 7 private final String location; 8 private final String paramName; 9 10 private String apiKey; 11 12 public ApiKeyAuth(String location, String paramName) { 13 this.location = location; 14 this.paramName = paramName; 15 } 16 17 public String getLocation() { 18 return location; 19 } 20 21 public String getParamName() { 22 return paramName; 23 } 24 25 public String getApiKey() { 26 return apiKey; 27 } 28 29 public void setApiKey(String apiKey) { 30 this.apiKey = apiKey; 31 } 32 33 @Override 34 public void apply(RequestTemplate template) { 35 if ("query".equals(location)) { 36 template.query(paramName, apiKey); 37 } else if ("header".equals(location)) { 38 template.header(paramName, apiKey); 39 } else if ("cookie".equals(location)) { 40 template.header("Cookie", String.format("%s=%s", paramName, apiKey)); 41 } 42 } 43 }