Fix syntax error when there are no authMethods

This commit is contained in:
xhh 2015-07-09 10:48:16 +08:00
parent a24fee00cb
commit a51d71e728
3 changed files with 13 additions and 3 deletions

View File

@ -218,7 +218,11 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
bundle.put("models", allModels);
bundle.put("apiFolder", config.apiPackage().replace('.', File.separatorChar));
bundle.put("modelPackage", config.modelPackage());
bundle.put("authMethods", config.fromSecurity(swagger.getSecurityDefinitions()));
List<CodegenSecurity> authMethods = config.fromSecurity(swagger.getSecurityDefinitions());
if (!authMethods.isEmpty()) {
bundle.put("authMethods", authMethods);
bundle.put("hasAuthMethods", true);
}
if (swagger.getExternalDocs() != null) {
bundle.put("externalDocs", swagger.getExternalDocs());
}

View File

@ -30,10 +30,12 @@ module {{moduleName}}
self.path = path
attributes.each { |name, value| send "#{name}=", value }
{{#hasAuthMethods}}
update_params_for_auth!
{{/hasAuthMethods}}
end
{{#hasAuthMethods}}
# Update hearder and query params based on authentication settings.
def update_params_for_auth!
(@auth_names || []).each do |auth_name|
@ -48,6 +50,7 @@ module {{moduleName}}
end
end
end
{{/hasAuthMethods}}
# Get API key (with prefix if set).
# @param [String] param_name the parameter name of API key auth

View File

@ -30,10 +30,12 @@ module Petstore
self.path = path
attributes.each { |name, value| send "#{name}=", value }
update_params_for_auth!
end
# Update hearder and query params based on authentication settings.
def update_params_for_auth!
(@auth_names || []).each do |auth_name|
@ -47,6 +49,7 @@ module Petstore
end
end
end
# Get API key (with prefix if set).
# @param [String] param_name the parameter name of API key auth