Use File.separatorChar in Ruby generator, add comments

This commit is contained in:
xhh 2015-05-29 12:05:47 +08:00
parent 623a1278cf
commit a29c3abeb8
3 changed files with 14 additions and 8 deletions

View File

@ -36,7 +36,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
moduleName = generateModuleName(); moduleName = generateModuleName();
modelPackage = gemName + "/models"; modelPackage = gemName + "/models";
apiPackage = gemName + "/api"; apiPackage = gemName + "/api";
outputFolder = "generated-code/ruby"; outputFolder = "generated-code" + File.separatorChar + "ruby";
modelTemplateFiles.put("model.mustache", ".rb"); modelTemplateFiles.put("model.mustache", ".rb");
apiTemplateFiles.put("api.mustache", ".rb"); apiTemplateFiles.put("api.mustache", ".rb");
templateDir = "ruby"; templateDir = "ruby";
@ -69,17 +69,17 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("List", "array"); typeMapping.put("List", "array");
typeMapping.put("map", "map"); typeMapping.put("map", "map");
String baseFolder = "lib/" + gemName; String baseFolder = "lib" + File.separatorChar + gemName;
String swaggerFolder = baseFolder + "/swagger"; String swaggerFolder = baseFolder + File.separatorChar + "swagger";
String modelFolder = baseFolder + "/models"; String modelFolder = baseFolder + File.separatorChar + "models";
supportingFiles.add(new SupportingFile("swagger_client.gemspec.mustache", "", gemName + ".gemspec")); supportingFiles.add(new SupportingFile("swagger_client.gemspec.mustache", "", gemName + ".gemspec"));
supportingFiles.add(new SupportingFile("swagger_client.mustache", "lib", gemName + ".rb")); supportingFiles.add(new SupportingFile("swagger_client.mustache", "lib", gemName + ".rb"));
supportingFiles.add(new SupportingFile("monkey.mustache", baseFolder, "monkey.rb")); supportingFiles.add(new SupportingFile("monkey.mustache", baseFolder, "monkey.rb"));
supportingFiles.add(new SupportingFile("swagger.mustache", baseFolder, "swagger.rb")); supportingFiles.add(new SupportingFile("swagger.mustache", baseFolder, "swagger.rb"));
supportingFiles.add(new SupportingFile("swagger/request.mustache", swaggerFolder, "request.rb")); supportingFiles.add(new SupportingFile("swagger" + File.separatorChar + "request.mustache", swaggerFolder, "request.rb"));
supportingFiles.add(new SupportingFile("swagger/response.mustache", swaggerFolder, "response.rb")); supportingFiles.add(new SupportingFile("swagger" + File.separatorChar + "response.mustache", swaggerFolder, "response.rb"));
supportingFiles.add(new SupportingFile("swagger/version.mustache", swaggerFolder, "version.rb")); supportingFiles.add(new SupportingFile("swagger" + File.separatorChar + "version.mustache", swaggerFolder, "version.rb"));
supportingFiles.add(new SupportingFile("swagger/configuration.mustache", swaggerFolder, "configuration.rb")); supportingFiles.add(new SupportingFile("swagger" + File.separatorChar + "configuration.mustache", swaggerFolder, "configuration.rb"));
supportingFiles.add(new SupportingFile("base_object.mustache", modelFolder, "base_object.rb")); supportingFiles.add(new SupportingFile("base_object.mustache", modelFolder, "base_object.rb"));
} }

View File

@ -36,6 +36,7 @@ module {{moduleName}}
update_params_for_auth! update_params_for_auth!
end end
# Update hearder and query params based on authentication settings.
def update_params_for_auth! def update_params_for_auth!
(@auth_names || []).each do |auth_name| (@auth_names || []).each do |auth_name|
case auth_name case auth_name
@ -50,6 +51,8 @@ module {{moduleName}}
end end
end end
# Get API key (with prefix if set).
# @param [String] param_name the parameter name of API key auth
def get_api_key_with_prefix(param_name) def get_api_key_with_prefix(param_name)
if Swagger.configuration.api_key_prefix[param_name].present? if Swagger.configuration.api_key_prefix[param_name].present?
"#{Swagger.configuration.api_key_prefix[param_name]} #{Swagger.configuration.api_key[param_name]}" "#{Swagger.configuration.api_key_prefix[param_name]} #{Swagger.configuration.api_key[param_name]}"

View File

@ -36,6 +36,7 @@ module SwaggerClient
update_params_for_auth! update_params_for_auth!
end end
# Update hearder and query params based on authentication settings.
def update_params_for_auth! def update_params_for_auth!
(@auth_names || []).each do |auth_name| (@auth_names || []).each do |auth_name|
case auth_name case auth_name
@ -49,6 +50,8 @@ module SwaggerClient
end end
end end
# Get API key (with prefix if set).
# @param [String] param_name the parameter name of API key auth
def get_api_key_with_prefix(param_name) def get_api_key_with_prefix(param_name)
if Swagger.configuration.api_key_prefix[param_name].present? if Swagger.configuration.api_key_prefix[param_name].present?
"#{Swagger.configuration.api_key_prefix[param_name]} #{Swagger.configuration.api_key[param_name]}" "#{Swagger.configuration.api_key_prefix[param_name]} #{Swagger.configuration.api_key[param_name]}"