Ruby client: escape path parameters

Path parameters should be escaped when encoded into the path.

In the path '/pet/{petId}' let's pretend petId is a string instead of a
number.

If the user uses "Bobby" as the petId then they correctly get the path
'/pet/Bobby'.
But if they put 'Bobby/Tables' as the petId then they used to get the
path '/pet/Bobby/Tables' which will be interpreted by the server as a
different route.

Using CGI::Escape they now get '/pet/Bobby%2FTables' which is correct.
This commit is contained in:
Chris Couzens
2019-05-31 20:39:52 +01:00
parent f667effa76
commit 201cbdce29
7 changed files with 18 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
=end
require 'uri'
require 'cgi'
module {{moduleName}}
{{#operations}}
@@ -123,7 +124,7 @@ module {{moduleName}}
{{/hasValidation}}
{{/allParams}}
# resource path
local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}}
local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s)){{/pathParams}}
# query parameters
query_params = opts[:query_params] || {}