forked from loafle/openapi-generator-original
Merge pull request #585 from wing328/ruby_fix_path_variable
Fixed Ruby path variable url-encoded twice, removed duplicated path variable replacement
This commit is contained in:
commit
b9514a40de
@ -5,10 +5,6 @@ class {{classname}}
|
|||||||
basePath = "{{basePath}}"
|
basePath = "{{basePath}}"
|
||||||
# apiInvoker = APIInvoker
|
# apiInvoker = APIInvoker
|
||||||
|
|
||||||
def self.escapeString(string)
|
|
||||||
URI.encode(string.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
{{newline}}
|
{{newline}}
|
||||||
# {{summary}}
|
# {{summary}}
|
||||||
@ -34,7 +30,7 @@ class {{classname}}
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#resource path
|
||||||
path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', escapeString({{paramName}}))
|
path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s)
|
||||||
{{/pathParams}}{{newline}}
|
{{/pathParams}}{{newline}}
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
|
@ -74,11 +74,6 @@ module Swagger
|
|||||||
def interpreted_path
|
def interpreted_path
|
||||||
p = self.path.dup
|
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
|
# Stick a .{format} placeholder into the path if there isn't
|
||||||
# one already or an actual format like json or xml
|
# one already or an actual format like json or xml
|
||||||
# e.g. /words/blah => /words.{format}/blah
|
# e.g. /words/blah => /words.{format}/blah
|
||||||
|
@ -4,10 +4,6 @@ class PetApi
|
|||||||
basePath = "http://petstore.swagger.io/v2"
|
basePath = "http://petstore.swagger.io/v2"
|
||||||
# apiInvoker = APIInvoker
|
# apiInvoker = APIInvoker
|
||||||
|
|
||||||
def self.escapeString(string)
|
|
||||||
URI.encode(string.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# Update an existing pet
|
# Update an existing pet
|
||||||
#
|
#
|
||||||
@ -266,7 +262,7 @@ class PetApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#resource path
|
||||||
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id))
|
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
@ -321,7 +317,7 @@ class PetApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#resource path
|
||||||
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id))
|
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
@ -375,7 +371,7 @@ class PetApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#resource path
|
||||||
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', escapeString(pet_id))
|
path = "/pet/{petId}".sub('{format}','json').sub('{' + 'petId' + '}', pet_id.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
@ -429,7 +425,7 @@ class PetApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#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.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
|
@ -4,10 +4,6 @@ class StoreApi
|
|||||||
basePath = "http://petstore.swagger.io/v2"
|
basePath = "http://petstore.swagger.io/v2"
|
||||||
# apiInvoker = APIInvoker
|
# apiInvoker = APIInvoker
|
||||||
|
|
||||||
def self.escapeString(string)
|
|
||||||
URI.encode(string.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# Returns pet inventories by status
|
# Returns pet inventories by status
|
||||||
# Returns a map of status codes to quantities
|
# Returns a map of status codes to quantities
|
||||||
@ -145,7 +141,7 @@ class StoreApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#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.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
@ -196,7 +192,7 @@ class StoreApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#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.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
|
@ -74,11 +74,6 @@ module Swagger
|
|||||||
def interpreted_path
|
def interpreted_path
|
||||||
p = self.path.dup
|
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
|
# Stick a .{format} placeholder into the path if there isn't
|
||||||
# one already or an actual format like json or xml
|
# one already or an actual format like json or xml
|
||||||
# e.g. /words/blah => /words.{format}/blah
|
# e.g. /words/blah => /words.{format}/blah
|
||||||
|
@ -4,10 +4,6 @@ class UserApi
|
|||||||
basePath = "http://petstore.swagger.io/v2"
|
basePath = "http://petstore.swagger.io/v2"
|
||||||
# apiInvoker = APIInvoker
|
# apiInvoker = APIInvoker
|
||||||
|
|
||||||
def self.escapeString(string)
|
|
||||||
URI.encode(string.to_s)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# Create user
|
# Create user
|
||||||
# This can only be done by the logged in user.
|
# This can only be done by the logged in user.
|
||||||
@ -332,7 +328,7 @@ class UserApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#resource path
|
||||||
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username))
|
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
@ -385,7 +381,7 @@ class UserApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#resource path
|
||||||
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username))
|
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
@ -455,7 +451,7 @@ class UserApi
|
|||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
#resource path
|
#resource path
|
||||||
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', escapeString(username))
|
path = "/user/{username}".sub('{format}','json').sub('{' + 'username' + '}', username.to_s)
|
||||||
|
|
||||||
|
|
||||||
# pull querystring keys from options
|
# pull querystring keys from options
|
||||||
|
@ -65,7 +65,7 @@ describe "Store" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should fetch an order" do
|
it "should fetch an order" do
|
||||||
item = StoreApi.getOrderById(2)
|
item = StoreApi.getOrderById(5)
|
||||||
item.id.should == 2
|
item.id.should == 5
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -73,20 +73,18 @@ describe Swagger::Request do
|
|||||||
describe "path" do
|
describe "path" do
|
||||||
|
|
||||||
it "accounts for a total absence of format in the path string" 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",
|
:format => "xml",
|
||||||
:params => {
|
:params => {
|
||||||
:word => "cat"
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
@request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries"
|
@request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does string substitution on path params" do
|
it "does string substitution (format) on path params" 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",
|
:format => "xml",
|
||||||
:params => {
|
:params => {
|
||||||
:word => "cat"
|
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
@request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries"
|
@request.url.should == "http://petstore.swagger.io/v2/word.xml/cat/entries"
|
||||||
@ -123,7 +121,7 @@ describe Swagger::Request do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "URI encodes the path" do
|
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 => {
|
:params => {
|
||||||
:word => "bill gates"
|
:word => "bill gates"
|
||||||
}
|
}
|
||||||
|
16
samples/client/petstore/ruby/spec/store_spec.rb
Normal file
16
samples/client/petstore/ruby/spec/store_spec.rb
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user