forked from loafle/openapi-generator-original
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:
@@ -3,6 +3,7 @@
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
module {{moduleName}}
|
module {{moduleName}}
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
@@ -123,7 +124,7 @@ module {{moduleName}}
|
|||||||
{{/hasValidation}}
|
{{/hasValidation}}
|
||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
# resource path
|
# 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 parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ OpenAPI Generator version: 4.0.2-SNAPSHOT
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
module Petstore
|
module Petstore
|
||||||
class AnotherFakeApi
|
class AnotherFakeApi
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ OpenAPI Generator version: 4.0.2-SNAPSHOT
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
module Petstore
|
module Petstore
|
||||||
class FakeApi
|
class FakeApi
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ OpenAPI Generator version: 4.0.2-SNAPSHOT
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
module Petstore
|
module Petstore
|
||||||
class FakeClassnameTags123Api
|
class FakeClassnameTags123Api
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ OpenAPI Generator version: 4.0.2-SNAPSHOT
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
module Petstore
|
module Petstore
|
||||||
class PetApi
|
class PetApi
|
||||||
@@ -103,7 +104,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.delete_pet"
|
fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.delete_pet"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/pet/{petId}'.sub('{' + 'petId' + '}', pet_id.to_s)
|
local_var_path = '/pet/{petId}'.sub('{' + 'petId' + '}', CGI.escape(pet_id.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
@@ -290,7 +291,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.get_pet_by_id"
|
fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.get_pet_by_id"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/pet/{petId}'.sub('{' + 'petId' + '}', pet_id.to_s)
|
local_var_path = '/pet/{petId}'.sub('{' + 'petId' + '}', CGI.escape(pet_id.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
@@ -414,7 +415,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.update_pet_with_form"
|
fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.update_pet_with_form"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/pet/{petId}'.sub('{' + 'petId' + '}', pet_id.to_s)
|
local_var_path = '/pet/{petId}'.sub('{' + 'petId' + '}', CGI.escape(pet_id.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
@@ -480,7 +481,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.upload_file"
|
fail ArgumentError, "Missing the required parameter 'pet_id' when calling PetApi.upload_file"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/pet/{petId}/uploadImage'.sub('{' + 'petId' + '}', pet_id.to_s)
|
local_var_path = '/pet/{petId}/uploadImage'.sub('{' + 'petId' + '}', CGI.escape(pet_id.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
@@ -552,7 +553,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'required_file' when calling PetApi.upload_file_with_required_file"
|
fail ArgumentError, "Missing the required parameter 'required_file' when calling PetApi.upload_file_with_required_file"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/fake/{petId}/uploadImageWithRequiredFile'.sub('{' + 'petId' + '}', pet_id.to_s)
|
local_var_path = '/fake/{petId}/uploadImageWithRequiredFile'.sub('{' + 'petId' + '}', CGI.escape(pet_id.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ OpenAPI Generator version: 4.0.2-SNAPSHOT
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
module Petstore
|
module Petstore
|
||||||
class StoreApi
|
class StoreApi
|
||||||
@@ -43,7 +44,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'order_id' when calling StoreApi.delete_order"
|
fail ArgumentError, "Missing the required parameter 'order_id' when calling StoreApi.delete_order"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/store/order/{order_id}'.sub('{' + 'order_id' + '}', order_id.to_s)
|
local_var_path = '/store/order/{order_id}'.sub('{' + 'order_id' + '}', CGI.escape(order_id.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
@@ -167,7 +168,7 @@ module Petstore
|
|||||||
end
|
end
|
||||||
|
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/store/order/{order_id}'.sub('{' + 'order_id' + '}', order_id.to_s)
|
local_var_path = '/store/order/{order_id}'.sub('{' + 'order_id' + '}', CGI.escape(order_id.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ OpenAPI Generator version: 4.0.2-SNAPSHOT
|
|||||||
=end
|
=end
|
||||||
|
|
||||||
require 'uri'
|
require 'uri'
|
||||||
|
require 'cgi'
|
||||||
|
|
||||||
module Petstore
|
module Petstore
|
||||||
class UserApi
|
class UserApi
|
||||||
@@ -219,7 +220,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'username' when calling UserApi.delete_user"
|
fail ArgumentError, "Missing the required parameter 'username' when calling UserApi.delete_user"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/user/{username}'.sub('{' + 'username' + '}', username.to_s)
|
local_var_path = '/user/{username}'.sub('{' + 'username' + '}', CGI.escape(username.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
@@ -277,7 +278,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'username' when calling UserApi.get_user_by_name"
|
fail ArgumentError, "Missing the required parameter 'username' when calling UserApi.get_user_by_name"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/user/{username}'.sub('{' + 'username' + '}', username.to_s)
|
local_var_path = '/user/{username}'.sub('{' + 'username' + '}', CGI.escape(username.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
@@ -465,7 +466,7 @@ module Petstore
|
|||||||
fail ArgumentError, "Missing the required parameter 'body' when calling UserApi.update_user"
|
fail ArgumentError, "Missing the required parameter 'body' when calling UserApi.update_user"
|
||||||
end
|
end
|
||||||
# resource path
|
# resource path
|
||||||
local_var_path = '/user/{username}'.sub('{' + 'username' + '}', username.to_s)
|
local_var_path = '/user/{username}'.sub('{' + 'username' + '}', CGI.escape(username.to_s))
|
||||||
|
|
||||||
# query parameters
|
# query parameters
|
||||||
query_params = opts[:query_params] || {}
|
query_params = opts[:query_params] || {}
|
||||||
|
|||||||
Reference in New Issue
Block a user