diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache index 7488de2f49d..bf210cffc24 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/ApiClient.mustache @@ -41,7 +41,7 @@ public class ApiClient { apiAuthorizations = new LinkedHashMap(); createDefaultAdapter(); } - + public ApiClient(String[] authNames) { this(); okClient = new OkHttpClient(); @@ -49,16 +49,17 @@ public class ApiClient { for(String authName : authNames) { if (apiAuthorizations.containsKey(authName)) { throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations"); - }{{#authMethods}} + }{{#hasAuthMethods}} Interceptor auth; - if (authName == "{{name}}") { {{#isBasic}} + {{#authMethods}}if (authName == "{{name}}") { {{#isBasic}} auth = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}} auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}} auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");{{/isOAuth}} - } else { + } else {{^hasMore}}{ throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); - } - apiAuthorizations.put(authName, auth);{{/authMethods}} + }{{/hasMore}}{{/authMethods}} + apiAuthorizations.put(authName, auth);{{/hasAuthMethods}}{{^hasAuthMethods}} + throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");{{/hasAuthMethods}} } addAuthsToOkClient(okClient); } diff --git a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java index 83ad22c4de8..343e545e83d 100644 --- a/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit/src/main/java/io/swagger/client/ApiClient.java @@ -41,7 +41,7 @@ public class ApiClient { apiAuthorizations = new LinkedHashMap(); createDefaultAdapter(); } - + public ApiClient(String[] authNames) { this(); okClient = new OkHttpClient(); @@ -51,11 +51,10 @@ public class ApiClient { throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations"); } Interceptor auth; - if (authName == "api_key") { - auth = new ApiKeyAuth("header", "api_key"); - } else if (authName == "petstore_auth") { auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets"); + } else if (authName == "api_key") { + auth = new ApiKeyAuth("header", "api_key"); } else { throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names"); }