From b773d40034431a995516b1e02727b4554a1a8d91 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 2 Apr 2015 16:15:08 +0800 Subject: [PATCH 1/7] fixed path variable double uri-encoded issue --- .../swagger-codegen/src/main/resources/ruby/api.mustache | 6 +----- .../src/main/resources/ruby/swagger/request.mustache | 5 ----- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index 6514f2c1b75..488bcbeb16d 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -5,10 +5,6 @@ class {{classname}} basePath = "{{basePath}}" # apiInvoker = APIInvoker - def self.escapeString(string) - URI.encode(string.to_s) - end - {{#operation}} {{newline}} # {{summary}} @@ -33,7 +29,7 @@ class {{classname}} }.merge(opts) #resource path - path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', escapeString({{paramName}})) + path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}) {{/pathParams}}{{newline}} # pull querystring keys from options diff --git a/modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache b/modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache index fb1c57298bb..fbd70eeb9f5 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache @@ -74,11 +74,6 @@ module Swagger def interpreted_path p = self.path.dup - # Fill in the path params - self.params.each_pair do |key, value| - p = p.gsub("{#{key}}", value.to_s) - end - # Stick a .{format} placeholder into the path if there isn't # one already or an actual format like json or xml # e.g. /words/blah => /words.{format}/blah From e73957e7906f63e59ced7f20e7cdc027f803aea0 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 2 Apr 2015 21:12:01 +0800 Subject: [PATCH 2/7] update ruby petstore sample --- samples/client/petstore/ruby/lib/pet_api.rb | 12 ++++-------- samples/client/petstore/ruby/lib/store_api.rb | 8 ++------ samples/client/petstore/ruby/lib/swagger/request.rb | 5 ----- samples/client/petstore/ruby/lib/user_api.rb | 10 +++------- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index 771536c9248..c48cf0c2c01 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -4,10 +4,6 @@ class PetApi basePath = "http://petstore.swagger.io/v2" # apiInvoker = APIInvoker - def self.escapeString(string) - URI.encode(string.to_s) - end - # Update an existing pet # @@ -229,7 +225,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id)) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) # pull querystring keys from options @@ -275,7 +271,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id)) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) # pull querystring keys from options @@ -320,7 +316,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id)) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) # pull querystring keys from options @@ -365,7 +361,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id)) + path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index 0d438576ecd..2606213ee0b 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -4,10 +4,6 @@ class StoreApi basePath = "http://petstore.swagger.io/v2" # apiInvoker = APIInvoker - def self.escapeString(string) - URI.encode(string.to_s) - end - # Returns pet inventories by status # Returns a map of status codes to quantities @@ -126,7 +122,7 @@ class StoreApi }.merge(opts) #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id)) + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id) # pull querystring keys from options @@ -168,7 +164,7 @@ class StoreApi }.merge(opts) #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id)) + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/swagger/request.rb b/samples/client/petstore/ruby/lib/swagger/request.rb index fb1c57298bb..fbd70eeb9f5 100644 --- a/samples/client/petstore/ruby/lib/swagger/request.rb +++ b/samples/client/petstore/ruby/lib/swagger/request.rb @@ -74,11 +74,6 @@ module Swagger def interpreted_path p = self.path.dup - # Fill in the path params - self.params.each_pair do |key, value| - p = p.gsub("{#{key}}", value.to_s) - end - # Stick a .{format} placeholder into the path if there isn't # one already or an actual format like json or xml # e.g. /words/blah => /words.{format}/blah diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 64aeb210f60..ffa90a4e8ff 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -4,10 +4,6 @@ class UserApi basePath = "http://petstore.swagger.io/v2" # apiInvoker = APIInvoker - def self.escapeString(string) - URI.encode(string.to_s) - end - # Create user # This can only be done by the logged in user. @@ -286,7 +282,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username)) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) # pull querystring keys from options @@ -330,7 +326,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username)) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) # pull querystring keys from options @@ -391,7 +387,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username)) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) # pull querystring keys from options From 40d512fe431bf44d5c4900306c56ee415e96a112 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 2 Apr 2015 21:37:54 +0800 Subject: [PATCH 3/7] fix test cases --- .../src/main/resources/ruby/api.mustache | 2 +- samples/client/petstore/ruby/lib/pet_api.rb | 8 ++++---- samples/client/petstore/ruby/lib/store_api.rb | 4 ++-- samples/client/petstore/ruby/lib/user_api.rb | 6 +++--- samples/client/petstore/ruby/spec/request_spec.rb | 12 +++++------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index 488bcbeb16d..43481184f5d 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -29,7 +29,7 @@ class {{classname}} }.merge(opts) #resource path - path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}) + path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s) {{/pathParams}}{{newline}} # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index c48cf0c2c01..3e91297a997 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -225,7 +225,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) # pull querystring keys from options @@ -271,7 +271,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) # pull querystring keys from options @@ -316,7 +316,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) # pull querystring keys from options @@ -361,7 +361,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) + path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index 2606213ee0b..1b355de8dfc 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -122,7 +122,7 @@ class StoreApi }.merge(opts) #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id) + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id.to_s) # pull querystring keys from options @@ -164,7 +164,7 @@ class StoreApi }.merge(opts) #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id) + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id.to_s) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index ffa90a4e8ff..efb37d6768d 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -282,7 +282,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) # pull querystring keys from options @@ -326,7 +326,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) # pull querystring keys from options @@ -387,7 +387,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/spec/request_spec.rb b/samples/client/petstore/ruby/spec/request_spec.rb index 015f04c7db4..61389eddc9c 100644 --- a/samples/client/petstore/ruby/spec/request_spec.rb +++ b/samples/client/petstore/ruby/spec/request_spec.rb @@ -73,20 +73,18 @@ describe Swagger::Request do describe "path" do it "accounts for a total absence of format in the path string" do - @request = Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({ + @request = Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({ :format => "xml", :params => { - :word => "cat" } })) @request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries" end - it "does string substitution on path params" do - @request = Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({ + it "does string substitution (format) on path params" do + @request = Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({ :format => "xml", :params => { - :word => "cat" } })) @request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries" @@ -123,7 +121,7 @@ describe Swagger::Request do end it "URI encodes the path" do - @request = Swagger::Request.new(:get, "word.{format}/{word}/definitions", @default_params.merge({ + @request = Swagger::Request.new(:get, "word.{format}/bill gates/definitions", @default_params.merge({ :params => { :word => "bill gates" } @@ -200,4 +198,4 @@ describe Swagger::Request do end -end \ No newline at end of file +end From a717aba826c2e52f07533fb6e8a91b953e546867 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 2 Apr 2015 16:15:08 +0800 Subject: [PATCH 4/7] fixed path variable double uri-encoded issue --- .../swagger-codegen/src/main/resources/ruby/api.mustache | 6 +----- .../src/main/resources/ruby/swagger/request.mustache | 5 ----- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index ef6aee911e2..b38a5c35212 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -5,10 +5,6 @@ class {{classname}} basePath = "{{basePath}}" # apiInvoker = APIInvoker - def self.escapeString(string) - URI.encode(string.to_s) - end - {{#operation}} {{newline}} # {{summary}} @@ -34,7 +30,7 @@ class {{classname}} }.merge(opts) #resource path - path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', escapeString({{paramName}})) + path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}) {{/pathParams}}{{newline}} # pull querystring keys from options diff --git a/modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache b/modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache index fb1c57298bb..fbd70eeb9f5 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/swagger/request.mustache @@ -74,11 +74,6 @@ module Swagger def interpreted_path p = self.path.dup - # Fill in the path params - self.params.each_pair do |key, value| - p = p.gsub("{#{key}}", value.to_s) - end - # Stick a .{format} placeholder into the path if there isn't # one already or an actual format like json or xml # e.g. /words/blah => /words.{format}/blah From 0a4fc6a40fecd847e2b179e81bf4fb5768b24a17 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 2 Apr 2015 21:12:01 +0800 Subject: [PATCH 5/7] update ruby petstore sample --- samples/client/petstore/ruby/lib/pet_api.rb | 12 ++++-------- samples/client/petstore/ruby/lib/store_api.rb | 8 ++------ samples/client/petstore/ruby/lib/swagger/request.rb | 5 ----- samples/client/petstore/ruby/lib/user_api.rb | 10 +++------- 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index 3adc80d9a31..848a5889dc5 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -4,10 +4,6 @@ class PetApi basePath = "http://petstore.swagger.io/v2" # apiInvoker = APIInvoker - def self.escapeString(string) - URI.encode(string.to_s) - end - # Update an existing pet # @@ -266,7 +262,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id)) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) # pull querystring keys from options @@ -321,7 +317,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id)) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) # pull querystring keys from options @@ -375,7 +371,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id)) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) # pull querystring keys from options @@ -429,7 +425,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id)) + path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index bbf48db1edf..5209edea0e7 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -4,10 +4,6 @@ class StoreApi basePath = "http://petstore.swagger.io/v2" # apiInvoker = APIInvoker - def self.escapeString(string) - URI.encode(string.to_s) - end - # Returns pet inventories by status # Returns a map of status codes to quantities @@ -145,7 +141,7 @@ class StoreApi }.merge(opts) #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id)) + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id) # pull querystring keys from options @@ -196,7 +192,7 @@ class StoreApi }.merge(opts) #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', escapeString(order_id)) + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/swagger/request.rb b/samples/client/petstore/ruby/lib/swagger/request.rb index fb1c57298bb..fbd70eeb9f5 100644 --- a/samples/client/petstore/ruby/lib/swagger/request.rb +++ b/samples/client/petstore/ruby/lib/swagger/request.rb @@ -74,11 +74,6 @@ module Swagger def interpreted_path p = self.path.dup - # Fill in the path params - self.params.each_pair do |key, value| - p = p.gsub("{#{key}}", value.to_s) - end - # Stick a .{format} placeholder into the path if there isn't # one already or an actual format like json or xml # e.g. /words/blah => /words.{format}/blah diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 6de9535f1af..6a85d80907f 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -4,10 +4,6 @@ class UserApi basePath = "http://petstore.swagger.io/v2" # apiInvoker = APIInvoker - def self.escapeString(string) - URI.encode(string.to_s) - end - # Create user # This can only be done by the logged in user. @@ -332,7 +328,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username)) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) # pull querystring keys from options @@ -385,7 +381,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username)) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) # pull querystring keys from options @@ -455,7 +451,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username)) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) # pull querystring keys from options From 9c5153e8c85d725c5a1e480682a4620269abecc9 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 2 Apr 2015 21:37:54 +0800 Subject: [PATCH 6/7] fix test cases --- .../src/main/resources/ruby/api.mustache | 2 +- samples/client/petstore/ruby/lib/pet_api.rb | 8 ++++---- samples/client/petstore/ruby/lib/store_api.rb | 4 ++-- samples/client/petstore/ruby/lib/user_api.rb | 6 +++--- samples/client/petstore/ruby/spec/request_spec.rb | 12 +++++------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/ruby/api.mustache b/modules/swagger-codegen/src/main/resources/ruby/api.mustache index b38a5c35212..a45c3455859 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api.mustache @@ -30,7 +30,7 @@ class {{classname}} }.merge(opts) #resource path - path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}) + path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s) {{/pathParams}}{{newline}} # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/pet_api.rb b/samples/client/petstore/ruby/lib/pet_api.rb index 848a5889dc5..8bb98d4efb1 100644 --- a/samples/client/petstore/ruby/lib/pet_api.rb +++ b/samples/client/petstore/ruby/lib/pet_api.rb @@ -262,7 +262,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) # pull querystring keys from options @@ -317,7 +317,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) # pull querystring keys from options @@ -371,7 +371,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) + path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) # pull querystring keys from options @@ -425,7 +425,7 @@ class PetApi }.merge(opts) #resource path - path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', pet_id) + path = "/pet/{petId}/uploadImage".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/store_api.rb b/samples/client/petstore/ruby/lib/store_api.rb index 5209edea0e7..bb1ece99f3c 100644 --- a/samples/client/petstore/ruby/lib/store_api.rb +++ b/samples/client/petstore/ruby/lib/store_api.rb @@ -141,7 +141,7 @@ class StoreApi }.merge(opts) #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id) + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id.to_s) # pull querystring keys from options @@ -192,7 +192,7 @@ class StoreApi }.merge(opts) #resource path - path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id) + path = "/store/order/{orderId}".sub('{format}','json').sub('{' + 'orderId' + '}', order_id.to_s) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/lib/user_api.rb b/samples/client/petstore/ruby/lib/user_api.rb index 6a85d80907f..90b12ef1308 100644 --- a/samples/client/petstore/ruby/lib/user_api.rb +++ b/samples/client/petstore/ruby/lib/user_api.rb @@ -328,7 +328,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) # pull querystring keys from options @@ -381,7 +381,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) # pull querystring keys from options @@ -451,7 +451,7 @@ class UserApi }.merge(opts) #resource path - path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username) + path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s) # pull querystring keys from options diff --git a/samples/client/petstore/ruby/spec/request_spec.rb b/samples/client/petstore/ruby/spec/request_spec.rb index 015f04c7db4..61389eddc9c 100644 --- a/samples/client/petstore/ruby/spec/request_spec.rb +++ b/samples/client/petstore/ruby/spec/request_spec.rb @@ -73,20 +73,18 @@ describe Swagger::Request do describe "path" do it "accounts for a total absence of format in the path string" do - @request = Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({ + @request = Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({ :format => "xml", :params => { - :word => "cat" } })) @request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries" end - it "does string substitution on path params" do - @request = Swagger::Request.new(:get, "/word.{format}/{word}/entries", @default_params.merge({ + it "does string substitution (format) on path params" do + @request = Swagger::Request.new(:get, "/word.{format}/cat/entries", @default_params.merge({ :format => "xml", :params => { - :word => "cat" } })) @request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries" @@ -123,7 +121,7 @@ describe Swagger::Request do end it "URI encodes the path" do - @request = Swagger::Request.new(:get, "word.{format}/{word}/definitions", @default_params.merge({ + @request = Swagger::Request.new(:get, "word.{format}/bill gates/definitions", @default_params.merge({ :params => { :word => "bill gates" } @@ -200,4 +198,4 @@ describe Swagger::Request do end -end \ No newline at end of file +end From 2967cc3801100388650ad9a3d942d46e7547bcf1 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 6 Apr 2015 19:05:19 +0800 Subject: [PATCH 7/7] moved store spec into a separate file, update order id to 5 (as the order with ID 2 is no longer found) --- samples/client/petstore/ruby/spec/pet_spec.rb | 6 +++--- samples/client/petstore/ruby/spec/store_spec.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 samples/client/petstore/ruby/spec/store_spec.rb diff --git a/samples/client/petstore/ruby/spec/pet_spec.rb b/samples/client/petstore/ruby/spec/pet_spec.rb index 175cb01681e..2a715f8b8eb 100644 --- a/samples/client/petstore/ruby/spec/pet_spec.rb +++ b/samples/client/petstore/ruby/spec/pet_spec.rb @@ -65,7 +65,7 @@ describe "Store" do end it "should fetch an order" do - item = StoreApi.getOrderById(2) - item.id.should == 2 + item = StoreApi.getOrderById(5) + item.id.should == 5 end -end \ No newline at end of file +end diff --git a/samples/client/petstore/ruby/spec/store_spec.rb b/samples/client/petstore/ruby/spec/store_spec.rb new file mode 100644 index 00000000000..0d3233ee558 --- /dev/null +++ b/samples/client/petstore/ruby/spec/store_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe "Store" do + before do + Swagger.configure do |config| + config.api_key = 'special-key' + config.host = 'petstore.swagger.io' + config.base_path = '/v2' + end + end + + it "should fetch an order" do + item = StoreApi.getOrderById(5) + item.id.should == 5 + end +end