From 034064be4cba2de290877640cc097d88dba3b4eb Mon Sep 17 00:00:00 2001 From: Chris Couzens Date: Mon, 24 Jun 2019 16:30:00 +0100 Subject: [PATCH] Ruby-client: Don't encode slashes if strict-spec false (#3204) URL-special characters such as /,?,% should be encoded when inside path parameters. I changed the Ruby-client to do so. https://github.com/OpenAPITools/openapi-generator/pull/3039 Unfortunately, some projects relied on slashes not being expanded within path paramters: https://github.com/OpenAPITools/openapi-generator/issues/3119 With this commit, these projects can now pass `--strict-spec false` to not have / converted to %2F. strict spec not specified: / -> %2F --strict-spec true: / -> %2F --strict-spec false: / -> / --- .../main/java/org/openapitools/codegen/DefaultGenerator.java | 1 + .../src/main/resources/ruby-client/api.mustache | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index 7a76a472269..56a4a25a2b9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -562,6 +562,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { operation.put("classVarName", config.toApiVarName(tag)); operation.put("importPath", config.toApiImport(tag)); operation.put("classFilename", config.toApiFilename(tag)); + operation.put("strictSpecBehavior", config.isStrictSpecBehavior()); if (allModels == null || allModels.isEmpty()) { operation.put("hasModel", false); diff --git a/modules/openapi-generator/src/main/resources/ruby-client/api.mustache b/modules/openapi-generator/src/main/resources/ruby-client/api.mustache index 1c5a053a9b9..bebf2fcae86 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/api.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/api.mustache @@ -123,7 +123,7 @@ module {{moduleName}} {{/hasValidation}} {{/allParams}} # resource path - local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s)){{/pathParams}} + local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s){{^strictSpecBehavior}}.gsub('%2F', '/'){{/strictSpecBehavior}}){{/pathParams}} # query parameters query_params = opts[:query_params] || {}