Support optional body parameter

This commit is contained in:
xhh
2015-04-16 18:20:36 +08:00
parent 61bf7f49cc
commit de21088619
7 changed files with 106 additions and 97 deletions
@@ -42,22 +42,23 @@ class {{classname}}
# http body (model)
post_body = nil{{#bodyParam}}
if body != nil
if body.is_a?(Array)
array = Array.new
body.each do |item|
if item.respond_to?("to_body".to_sym)
array.push item.to_body
_body_param = {{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}
if _body_param != nil
if _body_param.is_a?(Array)
_array = Array.new
_body_param.each do |item|
if item.respond_to?(:to_body)
_array.push item.to_body
else
array.push item
_array.push item
end
end
post_body = array
post_body = _array
else
if body.respond_to?("to_body".to_sym)
post_body = body.to_body
if _body_param.respond_to?(:to_body)
post_body = _body_param.to_body
else
post_body = body
post_body = _body_param
end
end
end{{/bodyParam}}
+24 -22
View File
@@ -32,22 +32,23 @@ class PetApi
# http body (model)
post_body = nil
if body != nil
if body.is_a?(Array)
array = Array.new
body.each do |item|
if item.respond_to?("to_body".to_sym)
array.push item.to_body
_body_param = opts[:'body']
if _body_param != nil
if _body_param.is_a?(Array)
_array = Array.new
_body_param.each do |item|
if item.respond_to?(:to_body)
_array.push item.to_body
else
array.push item
_array.push item
end
end
post_body = array
post_body = _array
else
if body.respond_to?("to_body".to_sym)
post_body = body.to_body
if _body_param.respond_to?(:to_body)
post_body = _body_param.to_body
else
post_body = body
post_body = _body_param
end
end
end
@@ -83,22 +84,23 @@ class PetApi
# http body (model)
post_body = nil
if body != nil
if body.is_a?(Array)
array = Array.new
body.each do |item|
if item.respond_to?("to_body".to_sym)
array.push item.to_body
_body_param = opts[:'body']
if _body_param != nil
if _body_param.is_a?(Array)
_array = Array.new
_body_param.each do |item|
if item.respond_to?(:to_body)
_array.push item.to_body
else
array.push item
_array.push item
end
end
post_body = array
post_body = _array
else
if body.respond_to?("to_body".to_sym)
post_body = body.to_body
if _body_param.respond_to?(:to_body)
post_body = _body_param.to_body
else
post_body = body
post_body = _body_param
end
end
end
+12 -11
View File
@@ -64,22 +64,23 @@ class StoreApi
# http body (model)
post_body = nil
if body != nil
if body.is_a?(Array)
array = Array.new
body.each do |item|
if item.respond_to?("to_body".to_sym)
array.push item.to_body
_body_param = opts[:'body']
if _body_param != nil
if _body_param.is_a?(Array)
_array = Array.new
_body_param.each do |item|
if item.respond_to?(:to_body)
_array.push item.to_body
else
array.push item
_array.push item
end
end
post_body = array
post_body = _array
else
if body.respond_to?("to_body".to_sym)
post_body = body.to_body
if _body_param.respond_to?(:to_body)
post_body = _body_param.to_body
else
post_body = body
post_body = _body_param
end
end
end
+2 -1
View File
@@ -7,6 +7,8 @@ require 'logger'
module Swagger
@configuration = Configuration.new
class << self
attr_accessor :logger
@@ -27,7 +29,6 @@ module Swagger
# end
#
def configure
self.configuration ||= Configuration.new
yield(configuration) if block_given?
# Configure logger. Default to use Rails
+48 -44
View File
@@ -32,22 +32,23 @@ class UserApi
# http body (model)
post_body = nil
if body != nil
if body.is_a?(Array)
array = Array.new
body.each do |item|
if item.respond_to?("to_body".to_sym)
array.push item.to_body
_body_param = opts[:'body']
if _body_param != nil
if _body_param.is_a?(Array)
_array = Array.new
_body_param.each do |item|
if item.respond_to?(:to_body)
_array.push item.to_body
else
array.push item
_array.push item
end
end
post_body = array
post_body = _array
else
if body.respond_to?("to_body".to_sym)
post_body = body.to_body
if _body_param.respond_to?(:to_body)
post_body = _body_param.to_body
else
post_body = body
post_body = _body_param
end
end
end
@@ -83,22 +84,23 @@ class UserApi
# http body (model)
post_body = nil
if body != nil
if body.is_a?(Array)
array = Array.new
body.each do |item|
if item.respond_to?("to_body".to_sym)
array.push item.to_body
_body_param = opts[:'body']
if _body_param != nil
if _body_param.is_a?(Array)
_array = Array.new
_body_param.each do |item|
if item.respond_to?(:to_body)
_array.push item.to_body
else
array.push item
_array.push item
end
end
post_body = array
post_body = _array
else
if body.respond_to?("to_body".to_sym)
post_body = body.to_body
if _body_param.respond_to?(:to_body)
post_body = _body_param.to_body
else
post_body = body
post_body = _body_param
end
end
end
@@ -134,22 +136,23 @@ class UserApi
# http body (model)
post_body = nil
if body != nil
if body.is_a?(Array)
array = Array.new
body.each do |item|
if item.respond_to?("to_body".to_sym)
array.push item.to_body
_body_param = opts[:'body']
if _body_param != nil
if _body_param.is_a?(Array)
_array = Array.new
_body_param.each do |item|
if item.respond_to?(:to_body)
_array.push item.to_body
else
array.push item
_array.push item
end
end
post_body = array
post_body = _array
else
if body.respond_to?("to_body".to_sym)
post_body = body.to_body
if _body_param.respond_to?(:to_body)
post_body = _body_param.to_body
else
post_body = body
post_body = _body_param
end
end
end
@@ -288,22 +291,23 @@ class UserApi
# http body (model)
post_body = nil
if body != nil
if body.is_a?(Array)
array = Array.new
body.each do |item|
if item.respond_to?("to_body".to_sym)
array.push item.to_body
_body_param = opts[:'body']
if _body_param != nil
if _body_param.is_a?(Array)
_array = Array.new
_body_param.each do |item|
if item.respond_to?(:to_body)
_array.push item.to_body
else
array.push item
_array.push item
end
end
post_body = array
post_body = _array
else
if body.respond_to?("to_body".to_sym)
post_body = body.to_body
if _body_param.respond_to?(:to_body)
post_body = _body_param.to_body
else
post_body = body
post_body = _body_param
end
end
end
@@ -15,17 +15,17 @@ describe "Pet" do
end
it "should find pets by status" do
pets = PetApi.findPetsByStatus('available')
pets = PetApi.findPetsByStatus(:status => 'available')
pets.length.should >= 3
end
it "should not find a pet with invalid status" do
pets = PetApi.findPetsByStatus('invalid-status')
pets = PetApi.findPetsByStatus(:status => 'invalid-status')
pets.length.should == 0
end
it "should find a pet by status" do
pets = PetApi.findPetsByStatus("available,sold")
pets = PetApi.findPetsByStatus(:status => "available,sold")
pets.map {|pet|
if(pet.status != 'available' && pet.status != 'sold')
raise "pet status wasn't right"
@@ -35,7 +35,7 @@ describe "Pet" do
it "should update a pet" do
pet = Pet.new({'id' => 10002, 'status' => 'sold'})
PetApi.addPet(pet)
PetApi.addPet(:body => pet)
fetched = PetApi.getPetById(10002)
fetched.id.should == 10002
@@ -44,7 +44,7 @@ describe "Pet" do
it "should create a pet" do
pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
PetApi.addPet(pet)
PetApi.addPet(:body => pet)
pet = PetApi.getPetById(10002)
pet.id.should == 10002
@@ -47,10 +47,10 @@ end
# always delete and then re-create the pet object with 10002
def prepare_pet
# remove the pet
PetApi.deletePet('special-key', 10002)
PetApi.deletePet(10002, :api_key => 'special-key')
# recreate the pet
pet = Pet.new('id' => 10002, 'name' => "RUBY UNIT TESTING")
PetApi.addPet(pet)
PetApi.addPet(:body => pet)
end
# always delete and then re-create the store order
@@ -61,7 +61,7 @@ def prepare_store
"shipDate" => "2015-04-06T23:42:01.678Z",
"status" => "placed",
"complete" => false)
StoreApi.placeOrder(order)
StoreApi.placeOrder(:body => order)
end
configure_swagger