forked from loafle/openapi-generator-original
Merge pull request #1444 from xhh/retrofit-syntex-error
Fix syntax error on authMethods in java retrofit client
This commit is contained in:
commit
cf59b5dc7e
@ -41,7 +41,7 @@ public class ApiClient {
|
|||||||
apiAuthorizations = new LinkedHashMap<String, Interceptor>();
|
apiAuthorizations = new LinkedHashMap<String, Interceptor>();
|
||||||
createDefaultAdapter();
|
createDefaultAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiClient(String[] authNames) {
|
public ApiClient(String[] authNames) {
|
||||||
this();
|
this();
|
||||||
okClient = new OkHttpClient();
|
okClient = new OkHttpClient();
|
||||||
@ -49,16 +49,17 @@ public class ApiClient {
|
|||||||
for(String authName : authNames) {
|
for(String authName : authNames) {
|
||||||
if (apiAuthorizations.containsKey(authName)) {
|
if (apiAuthorizations.containsKey(authName)) {
|
||||||
throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations");
|
throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations");
|
||||||
}{{#authMethods}}
|
}{{#hasAuthMethods}}
|
||||||
Interceptor auth;
|
Interceptor auth;
|
||||||
if (authName == "{{name}}") { {{#isBasic}}
|
{{#authMethods}}if (authName == "{{name}}") { {{#isBasic}}
|
||||||
auth = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}}
|
auth = new HttpBasicAuth();{{/isBasic}}{{#isApiKey}}
|
||||||
auth = new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}");{{/isApiKey}}{{#isOAuth}}
|
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}}
|
auth = new OAuth(OAuthFlow.{{flow}}, "{{authorizationUrl}}", "{{tokenUrl}}", "{{#scopes}}{{scope}}{{#hasMore}}, {{/hasMore}}{{/scopes}}");{{/isOAuth}}
|
||||||
} else {
|
} else {{/authMethods}}{
|
||||||
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
|
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
|
||||||
}
|
}
|
||||||
apiAuthorizations.put(authName, auth);{{/authMethods}}
|
apiAuthorizations.put(authName, auth);{{/hasAuthMethods}}{{^hasAuthMethods}}
|
||||||
|
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");{{/hasAuthMethods}}
|
||||||
}
|
}
|
||||||
addAuthsToOkClient(okClient);
|
addAuthsToOkClient(okClient);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class ApiClient {
|
|||||||
apiAuthorizations = new LinkedHashMap<String, Interceptor>();
|
apiAuthorizations = new LinkedHashMap<String, Interceptor>();
|
||||||
createDefaultAdapter();
|
createDefaultAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiClient(String[] authNames) {
|
public ApiClient(String[] authNames) {
|
||||||
this();
|
this();
|
||||||
okClient = new OkHttpClient();
|
okClient = new OkHttpClient();
|
||||||
@ -51,11 +51,10 @@ public class ApiClient {
|
|||||||
throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations");
|
throw new RuntimeException("auth name \"" + authName + "\" already in api authorizations");
|
||||||
}
|
}
|
||||||
Interceptor auth;
|
Interceptor auth;
|
||||||
if (authName == "api_key") {
|
|
||||||
auth = new ApiKeyAuth("header", "api_key");
|
|
||||||
} else
|
|
||||||
if (authName == "petstore_auth") {
|
if (authName == "petstore_auth") {
|
||||||
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
|
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 {
|
} else {
|
||||||
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
|
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user