diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index bdf074fbbdd8..b0cb8d1006c2 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -176,7 +176,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { config.additionalProperties().put("termsOfService", config.escapeText(info.getTermsOfService())); } } - + if(swagger.getVendorExtensions() != null) { config.vendorExtensions().putAll(swagger.getVendorExtensions()); } @@ -280,21 +280,21 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { Map models = processModels(config, modelMap, definitions); models.put("classname", config.toModelName(name)); models.putAll(config.additionalProperties()); - + allProcessedModels.put(name, models); } catch (Exception e) { throw new RuntimeException("Could not process model '" + name + "'", e); } } - + // post process all processed models allProcessedModels = config.postProcessAllModels(allProcessedModels); - + // generate files based on processed models for (String name: allProcessedModels.keySet()) { Map models = (Map)allProcessedModels.get(name); - + try { //don't generate models that have an import mapping if(config.importMapping().containsKey(name)) { @@ -394,7 +394,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { operation.put("classname", config.toApiName(tag)); operation.put("classVarName", config.toApiVarName(tag)); operation.put("importPath", config.toApiImport(tag)); - + if(!config.vendorExtensions().isEmpty()) { operation.put("vendorExtensions", config.vendorExtensions()); } @@ -705,7 +705,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { tags = new ArrayList(); tags.add("default"); } - + /* build up a set of parameter "ids" defined at the operation level per the swagger 2.0 spec "A unique parameter is defined by a combination of a name and location" diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index 6dc0107e8471..7b333428899f 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -89,7 +89,7 @@ module {{moduleName}} {{/hasValidation}} {{/allParams}} # resource path - local_var_path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}} + local_var_path = "{{{path}}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}} # query parameters query_params = {} diff --git a/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache b/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache index 71a392082388..496d52d3757e 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache @@ -199,7 +199,7 @@ module {{moduleName}} # @return [Tempfile] the file downloaded def download_file(response) content_disposition = response.headers['Content-Disposition'] - if content_disposition + if content_disposition and content_disposition =~ /filename=/i filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1] prefix = sanitize_filename(filename) else diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/ruby/RubyClientCodegenTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/ruby/RubyClientCodegenTest.java new file mode 100644 index 000000000000..40b7e8dc55b0 --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/ruby/RubyClientCodegenTest.java @@ -0,0 +1,67 @@ +package io.swagger.codegen.ruby; + +import io.swagger.codegen.ClientOpts; +import io.swagger.codegen.ClientOptInput; +import io.swagger.codegen.CodegenConfig; +import io.swagger.codegen.DefaultGenerator; +import io.swagger.codegen.languages.RubyClientCodegen; +import io.swagger.models.Swagger; +import io.swagger.parser.SwaggerParser; + +import org.apache.commons.io.FileUtils; +import org.junit.rules.TemporaryFolder; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.util.List; + +import static org.junit.Assert.fail; +import static org.testng.Assert.*; + +/** + * Tests for RubyClientCodegen-generated templates + */ +public class RubyClientCodegenTest { + + public TemporaryFolder folder = new TemporaryFolder(); + + @BeforeMethod + public void setUp() throws Exception { + folder.create(); + } + + @AfterMethod + public void tearDown() throws Exception { + folder.delete(); + } + + @Test + public void testGenerateRubyClientWithHtmlEntity() throws Exception { + final File output = folder.getRoot(); + + final Swagger swagger = new SwaggerParser().read("src/test/resources/2_0/pathWithHtmlEntity.yaml"); + CodegenConfig codegenConfig = new RubyClientCodegen(); + codegenConfig.setOutputDir(output.getAbsolutePath()); + + ClientOptInput clientOptInput = new ClientOptInput().opts(new ClientOpts()).swagger(swagger).config(codegenConfig); + + DefaultGenerator generator = new DefaultGenerator(); + generator.opts(clientOptInput); + List files = generator.generate(); + boolean apiFileGenerated = false; + for (File file : files) { + if (file.getName().equals("default_api.rb")) { + apiFileGenerated = true; + // Ruby client should set the path unescaped in the api file + assertTrue(FileUtils.readFileToString(file, StandardCharsets.UTF_8).contains("local_var_path = \"/foo=bar\"")); + } + } + if (!apiFileGenerated) { + fail("Default api file is not generated!"); + } + } + +} diff --git a/modules/swagger-codegen/src/test/resources/2_0/pathWithHtmlEntity.yaml b/modules/swagger-codegen/src/test/resources/2_0/pathWithHtmlEntity.yaml new file mode 100644 index 000000000000..929a5cd8f9b5 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/2_0/pathWithHtmlEntity.yaml @@ -0,0 +1,10 @@ +--- +swagger: "2.0" +basePath: "/" +paths: + /foo=bar: + get: + parameters: [] + responses: + 200: + description: "success"