forked from loafle/openapi-generator-original
update ruby client to support form parameters, add PATCH support, update
ruby petstore client
This commit is contained in:
parent
c96853d5aa
commit
fc9d632522
@ -45,6 +45,7 @@ class {{classname}}
|
|||||||
{{^headerParams}}headers = nil
|
{{^headerParams}}headers = nil
|
||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
{{#bodyParam}}
|
{{#bodyParam}}
|
||||||
if body != nil
|
if body != nil
|
||||||
@ -69,13 +70,18 @@ class {{classname}}
|
|||||||
end
|
end
|
||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
{{#formParams}}{{#optional}}form_parameter_hash["{{baseName}}"] = options[:'{{paramName}}'] if options[:'{{paramName}}']{{/optional}}
|
||||||
|
{{^optional}}form_parameter_hash["{{baseName}}"] = {{paramName}}{{/optional}}{{/formParams}}
|
||||||
|
|
||||||
{{#returnType}}
|
{{#returnType}}
|
||||||
response = Swagger::Request.new(:{{httpMethod}}, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
response = Swagger::Request.new(:{{httpMethod}}, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
{{#returnContainer}}
|
{{#returnContainer}}
|
||||||
response.map {|response|{{/returnContainer}} {{returnBaseType}}.new(response){{#returnContainer}} }{{/returnContainer}}
|
response.map {|response|{{/returnContainer}} {{returnBaseType}}.new(response){{#returnContainer}} }{{/returnContainer}}
|
||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
{{^returnType}}
|
{{^returnType}}
|
||||||
Swagger::Request.new(:{{httpMethod}}, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
Swagger::Request.new(:{{httpMethod}}, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
{{newline}}
|
{{newline}}
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module Swagger
|
|||||||
require 'typhoeus'
|
require 'typhoeus'
|
||||||
require "swagger/version"
|
require "swagger/version"
|
||||||
|
|
||||||
attr_accessor :host, :path, :format, :params, :body, :http_method, :headers
|
attr_accessor :host, :path, :format, :params, :body, :http_method, :headers, :form_params
|
||||||
|
|
||||||
|
|
||||||
# All requests must have an HTTP method and a path
|
# All requests must have an HTTP method and a path
|
||||||
@ -115,9 +115,18 @@ module Swagger
|
|||||||
end
|
end
|
||||||
|
|
||||||
# If body is an object, JSONify it before making the actual request.
|
# If body is an object, JSONify it before making the actual request.
|
||||||
#
|
# For form parameters, remove empty value
|
||||||
def outgoing_body
|
def outgoing_body
|
||||||
body.is_a?(String) ? body : body.to_json
|
# http form
|
||||||
|
if @body.nil? && @form_params && !@form_params.empty?
|
||||||
|
data = form_params.dup
|
||||||
|
data.each do |key, value|
|
||||||
|
data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
|
||||||
|
end
|
||||||
|
data
|
||||||
|
else # http body is JSON
|
||||||
|
@body.is_a?(String) ? @body : @body.to_json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Construct a query string from the query-string-type params
|
# Construct a query string from the query-string-type params
|
||||||
@ -163,6 +172,13 @@ module Swagger
|
|||||||
:headers => self.headers.stringify_keys,
|
:headers => self.headers.stringify_keys,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
when :patch,:PATCH
|
||||||
|
Typhoeus::Request.patch(
|
||||||
|
self.url,
|
||||||
|
:body => self.outgoing_body,
|
||||||
|
:headers => self.headers.stringify_keys,
|
||||||
|
)
|
||||||
|
|
||||||
when :put,:PUT
|
when :put,:PUT
|
||||||
Typhoeus::Request.put(
|
Typhoeus::Request.put(
|
||||||
self.url,
|
self.url,
|
||||||
|
@ -33,6 +33,7 @@ class PetApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
if body != nil
|
if body != nil
|
||||||
@ -57,9 +58,13 @@ class PetApi
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -89,6 +94,7 @@ class PetApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
if body != nil
|
if body != nil
|
||||||
@ -113,9 +119,13 @@ class PetApi
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -145,11 +155,16 @@ class PetApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
|
||||||
|
|
||||||
|
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
|
|
||||||
response.map {|response| Pet.new(response) }
|
response.map {|response| Pet.new(response) }
|
||||||
|
|
||||||
@ -182,11 +197,16 @@ class PetApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
|
||||||
|
|
||||||
|
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
|
|
||||||
response.map {|response| Pet.new(response) }
|
response.map {|response| Pet.new(response) }
|
||||||
|
|
||||||
@ -220,11 +240,16 @@ class PetApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
|
||||||
|
|
||||||
|
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
Pet.new(response)
|
Pet.new(response)
|
||||||
|
|
||||||
|
|
||||||
@ -263,12 +288,19 @@ class PetApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
form_parameter_hash["name"] = name
|
||||||
|
form_parameter_hash["status"] = status
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -304,12 +336,17 @@ class PetApi
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -346,12 +383,19 @@ class PetApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
form_parameter_hash["additionalMetadata"] = additionalMetadata
|
||||||
|
form_parameter_hash["file"] = file
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -31,11 +31,16 @@ class StoreApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
|
||||||
|
|
||||||
|
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
|
|
||||||
response.map {|response| map.new(response) }
|
response.map {|response| map.new(response) }
|
||||||
|
|
||||||
@ -68,6 +73,7 @@ class StoreApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
if body != nil
|
if body != nil
|
||||||
@ -92,8 +98,12 @@ class StoreApi
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
response = Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
|
||||||
|
|
||||||
|
response = Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
Order.new(response)
|
Order.new(response)
|
||||||
|
|
||||||
|
|
||||||
@ -126,11 +136,16 @@ class StoreApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
|
||||||
|
|
||||||
|
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
Order.new(response)
|
Order.new(response)
|
||||||
|
|
||||||
|
|
||||||
@ -163,12 +178,17 @@ class StoreApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -33,6 +33,7 @@ class UserApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
if body != nil
|
if body != nil
|
||||||
@ -57,9 +58,13 @@ class UserApi
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -89,6 +94,7 @@ class UserApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
if body != nil
|
if body != nil
|
||||||
@ -113,9 +119,13 @@ class UserApi
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -145,6 +155,7 @@ class UserApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
if body != nil
|
if body != nil
|
||||||
@ -169,9 +180,13 @@ class UserApi
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:POST, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -204,11 +219,16 @@ class UserApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
|
||||||
|
|
||||||
|
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
string.new(response)
|
string.new(response)
|
||||||
|
|
||||||
|
|
||||||
@ -238,12 +258,17 @@ class UserApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -274,11 +299,16 @@ class UserApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body }).make.body
|
|
||||||
|
|
||||||
|
response = Swagger::Request.new(:GET, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make.body
|
||||||
User.new(response)
|
User.new(response)
|
||||||
|
|
||||||
|
|
||||||
@ -314,6 +344,7 @@ class UserApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
if body != nil
|
if body != nil
|
||||||
@ -338,9 +369,13 @@ class UserApi
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:PUT, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -371,12 +406,17 @@ class UserApi
|
|||||||
headers = nil
|
headers = nil
|
||||||
|
|
||||||
|
|
||||||
|
# http body (model)
|
||||||
post_body = nil
|
post_body = nil
|
||||||
|
|
||||||
|
|
||||||
|
# form parameters
|
||||||
|
form_parameter_hash = {}
|
||||||
|
|
||||||
|
|
||||||
Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body}).make
|
|
||||||
|
|
||||||
|
Swagger::Request.new(:DELETE, path, {:params=>queryopts,:headers=>headers, :body=>post_body, :form_params => form_parameter_hash }).make
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ module Swagger
|
|||||||
require 'typhoeus'
|
require 'typhoeus'
|
||||||
require "swagger/version"
|
require "swagger/version"
|
||||||
|
|
||||||
attr_accessor :host, :path, :format, :params, :body, :http_method, :headers
|
attr_accessor :host, :path, :format, :params, :body, :http_method, :headers, :form_params
|
||||||
|
|
||||||
|
|
||||||
# All requests must have an HTTP method and a path
|
# All requests must have an HTTP method and a path
|
||||||
@ -115,9 +115,18 @@ module Swagger
|
|||||||
end
|
end
|
||||||
|
|
||||||
# If body is an object, JSONify it before making the actual request.
|
# If body is an object, JSONify it before making the actual request.
|
||||||
#
|
# For form parameters, remove empty value
|
||||||
def outgoing_body
|
def outgoing_body
|
||||||
body.is_a?(String) ? body : body.to_json
|
# http form
|
||||||
|
if @body.nil? && @form_params && !@form_params.empty?
|
||||||
|
data = form_params.dup
|
||||||
|
data.each do |key, value|
|
||||||
|
data[key] = value.to_s if value && !value.is_a?(File) # remove emtpy form parameter
|
||||||
|
end
|
||||||
|
data
|
||||||
|
else # http body is JSON
|
||||||
|
@body.is_a?(String) ? @body : @body.to_json
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Construct a query string from the query-string-type params
|
# Construct a query string from the query-string-type params
|
||||||
@ -163,6 +172,13 @@ module Swagger
|
|||||||
:headers => self.headers.stringify_keys,
|
:headers => self.headers.stringify_keys,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
when :patch,:PATCH
|
||||||
|
Typhoeus::Request.patch(
|
||||||
|
self.url,
|
||||||
|
:body => self.outgoing_body,
|
||||||
|
:headers => self.headers.stringify_keys,
|
||||||
|
)
|
||||||
|
|
||||||
when :put,:PUT
|
when :put,:PUT
|
||||||
Typhoeus::Request.put(
|
Typhoeus::Request.put(
|
||||||
self.url,
|
self.url,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user