mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 19:33:55 +00:00
rollback ruby template
This commit is contained in:
parent
d5cbbae182
commit
5f6622c70d
@ -2,60 +2,60 @@ require "uri"
|
||||
|
||||
module {{moduleName}}
|
||||
{{#operations}}
|
||||
class {{classname}}
|
||||
class {{classname}}
|
||||
basePath = "{{basePath}}"
|
||||
# apiInvoker = APIInvoker
|
||||
{{#operation}}
|
||||
{{newline}}
|
||||
# {{summary}}
|
||||
# {{notes}}
|
||||
{{#allParams}}{{#required}} # @param {{paramName}} {{description}}
|
||||
{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
|
||||
{{#allParams}}{{^required}} # @option opts [{{dataType}}] :{{paramName}} {{description}}
|
||||
{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}]
|
||||
def self.{{nickname}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
|
||||
{{#allParams}}{{#required}}
|
||||
# verify the required parameter '{{paramName}}' is set
|
||||
raise "Missing the required parameter '{{paramName}}' when calling {{nickname}}" if {{{paramName}}}.nil?
|
||||
{{/required}}{{/allParams}}
|
||||
{{#operation}}
|
||||
{{newline}}
|
||||
# {{summary}}
|
||||
# {{notes}}
|
||||
{{#allParams}}{{#required}} # @param {{paramName}} {{description}}
|
||||
{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
|
||||
{{#allParams}}{{^required}} # @option opts [{{dataType}}] :{{paramName}} {{description}}
|
||||
{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}]
|
||||
def self.{{nickname}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
|
||||
{{#allParams}}{{#required}}
|
||||
# verify the required parameter '{{paramName}}' is set
|
||||
raise "Missing the required parameter '{{paramName}}' when calling {{nickname}}" if {{{paramName}}}.nil?
|
||||
{{/required}}{{/allParams}}
|
||||
|
||||
# resource path
|
||||
path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}}
|
||||
# resource path
|
||||
path = "{{path}}".sub('{format}','json'){{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}}
|
||||
|
||||
# query parameters
|
||||
query_params = {}{{#queryParams}}{{#required}}
|
||||
query_params[:'{{{baseName}}}'] = {{{paramName}}}{{/required}}{{/queryParams}}{{#queryParams}}{{^required}}
|
||||
query_params[:'{{{baseName}}}'] = opts[:'{{{paramName}}}'] if opts[:'{{{paramName}}}']{{/required}}{{/queryParams}}
|
||||
# query parameters
|
||||
query_params = {}{{#queryParams}}{{#required}}
|
||||
query_params[:'{{{baseName}}}'] = {{{paramName}}}{{/required}}{{/queryParams}}{{#queryParams}}{{^required}}
|
||||
query_params[:'{{{baseName}}}'] = opts[:'{{{paramName}}}'] if opts[:'{{{paramName}}}']{{/required}}{{/queryParams}}
|
||||
|
||||
# header parameters
|
||||
header_params = {}
|
||||
# header parameters
|
||||
header_params = {}
|
||||
|
||||
# HTTP header 'Accept' (if needed)
|
||||
_header_accept = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]
|
||||
_header_accept_result = Swagger::Request.select_header_accept(_header_accept) and header_params['Accept'] = _header_accept_result
|
||||
# HTTP header 'Accept' (if needed)
|
||||
_header_accept = [{{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]
|
||||
_header_accept_result = Swagger::Request.select_header_accept(_header_accept) and header_params['Accept'] = _header_accept_result
|
||||
|
||||
# HTTP header 'Content-Type'
|
||||
_header_content_type = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]
|
||||
header_params['Content-Type'] = Swagger::Request.select_header_content_type(_header_content_type){{#headerParams}}{{#required}}
|
||||
header_params[:'{{{baseName}}}'] = {{{paramName}}}{{/required}}{{/headerParams}}{{#headerParams}}{{^required}}
|
||||
header_params[:'{{{baseName}}}'] = opts[:'{{{paramName}}}'] if opts[:'{{{paramName}}}']{{/required}}{{/headerParams}}
|
||||
# HTTP header 'Content-Type'
|
||||
_header_content_type = [{{#consumes}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]
|
||||
header_params['Content-Type'] = Swagger::Request.select_header_content_type(_header_content_type){{#headerParams}}{{#required}}
|
||||
header_params[:'{{{baseName}}}'] = {{{paramName}}}{{/required}}{{/headerParams}}{{#headerParams}}{{^required}}
|
||||
header_params[:'{{{baseName}}}'] = opts[:'{{{paramName}}}'] if opts[:'{{{paramName}}}']{{/required}}{{/headerParams}}
|
||||
|
||||
# form parameters
|
||||
form_params = {}{{#formParams}}{{#required}}
|
||||
form_params["{{baseName}}"] = {{paramName}}{{/required}}{{/formParams}}{{#formParams}}{{^required}}
|
||||
form_params["{{baseName}}"] = opts[:'{{paramName}}'] if opts[:'{{paramName}}']{{/required}}{{/formParams}}
|
||||
# form parameters
|
||||
form_params = {}{{#formParams}}{{#required}}
|
||||
form_params["{{baseName}}"] = {{paramName}}{{/required}}{{/formParams}}{{#formParams}}{{^required}}
|
||||
form_params["{{baseName}}"] = opts[:'{{paramName}}'] if opts[:'{{paramName}}']{{/required}}{{/formParams}}
|
||||
|
||||
# http body (model)
|
||||
{{^bodyParam}}post_body = nil
|
||||
{{/bodyParam}}{{#bodyParam}}post_body = Swagger::Request.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}})
|
||||
{{/bodyParam}}
|
||||
# http body (model)
|
||||
{{^bodyParam}}post_body = nil
|
||||
{{/bodyParam}}{{#bodyParam}}post_body = Swagger::Request.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}})
|
||||
{{/bodyParam}}
|
||||
|
||||
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
|
||||
{{#returnType}}response = Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
||||
{{#returnContainer}}response.map {|response| {{/returnContainer}}obj = {{returnBaseType}}.new() and obj.build_from_hash(response){{#returnContainer}} }{{/returnContainer}}{{/returnType}}{{^returnType}}Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||
nil{{/returnType}}
|
||||
end
|
||||
{{/operation}}
|
||||
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
|
||||
{{#returnType}}response = Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params, :headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make.body
|
||||
{{#returnContainer}}response.map {|response| {{/returnContainer}}obj = {{returnBaseType}}.new() and obj.build_from_hash(response){{#returnContainer}} }{{/returnContainer}}{{/returnType}}{{^returnType}}Swagger::Request.new(:{{httpMethod}}, path, {:params => query_params,:headers => header_params, :form_params => form_params, :body => post_body, :auth_names => auth_names}).make
|
||||
nil{{/returnType}}
|
||||
end
|
||||
{{/operation}}
|
||||
end
|
||||
{{/operations}}
|
||||
end
|
||||
|
@ -1,83 +1,83 @@
|
||||
module {{moduleName}}
|
||||
# base class containing fundamental method such as to_hash, build_from_hash and more
|
||||
class BaseObject
|
||||
# base class containing fundamental method such as to_hash, build_from_hash and more
|
||||
class BaseObject
|
||||
|
||||
# return the object in the form of hash
|
||||
def to_body
|
||||
body = {}
|
||||
self.class.attribute_map.each_pair do |key, value|
|
||||
body[value] = self.send(key) unless self.send(key).nil?
|
||||
end
|
||||
body
|
||||
end
|
||||
# return the object in the form of hash
|
||||
def to_body
|
||||
body = {}
|
||||
self.class.attribute_map.each_pair do |key, value|
|
||||
body[value] = self.send(key) unless self.send(key).nil?
|
||||
end
|
||||
body
|
||||
end
|
||||
|
||||
# build the object from hash
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^array\[(.*)\]/i
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
else
|
||||
#TODO show warning in debug mode
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
else
|
||||
# data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
end
|
||||
# build the object from hash
|
||||
def build_from_hash(attributes)
|
||||
return nil unless attributes.is_a?(Hash)
|
||||
self.class.swagger_types.each_pair do |key, type|
|
||||
if type =~ /^array\[(.*)\]/i
|
||||
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
||||
self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
|
||||
else
|
||||
#TODO show warning in debug mode
|
||||
end
|
||||
elsif !attributes[self.class.attribute_map[key]].nil?
|
||||
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
||||
else
|
||||
# data not found in attributes(hash), not an issue as the data can be optional
|
||||
end
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :string
|
||||
value.to_s
|
||||
when :int
|
||||
value.to_i
|
||||
when :double
|
||||
value.to_f
|
||||
when :boolean
|
||||
if value =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
else # model
|
||||
_model = {{moduleName}}.const_get(type).new
|
||||
_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
def _deserialize(type, value)
|
||||
case type.to_sym
|
||||
when :DateTime
|
||||
DateTime.parse(value)
|
||||
when :string
|
||||
value.to_s
|
||||
when :int
|
||||
value.to_i
|
||||
when :double
|
||||
value.to_f
|
||||
when :boolean
|
||||
if value =~ /^(true|t|yes|y|1)$/i
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
else # model
|
||||
_model = {{moduleName}}.const_get(type).new
|
||||
_model.build_from_hash(value)
|
||||
end
|
||||
end
|
||||
|
||||
# to_body is an alias to to_body (backward compatibility)
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |key, value|
|
||||
if self.send(key).is_a?(Array)
|
||||
next if self.send(key).empty?
|
||||
hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
else
|
||||
unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
hash[value] = _tmp_value
|
||||
end
|
||||
end
|
||||
end
|
||||
hash
|
||||
end
|
||||
# to_body is an alias to to_body (backward compatibility)
|
||||
def to_hash
|
||||
hash = {}
|
||||
self.class.attribute_map.each_pair do |key, value|
|
||||
if self.send(key).is_a?(Array)
|
||||
next if self.send(key).empty?
|
||||
hash[value] = self.send(key).select{|v| !v.nil?}.map{ |v| _to_hash v} unless self.send(key).nil?
|
||||
else
|
||||
unless (_tmp_value = _to_hash self.send(key)).nil?
|
||||
hash[value] = _tmp_value
|
||||
end
|
||||
end
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
||||
# Method to output non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
def _to_hash(value)
|
||||
if value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
# Method to output non-array value in the form of hash
|
||||
# For object, use to_hash. Otherwise, just return the value
|
||||
def _to_hash(value)
|
||||
if value.respond_to? :to_hash
|
||||
value.to_hash
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,40 +1,40 @@
|
||||
module {{moduleName}}
|
||||
{{#models}} # {{description}}
|
||||
{{#model}} class {{classname}} < BaseObject
|
||||
attr_accessor {{#vars}}:{{{name}}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{newline}}
|
||||
# attribute mapping from ruby-style variable name to JSON key
|
||||
def self.attribute_map
|
||||
{
|
||||
{{#vars}}
|
||||
# {{description}}
|
||||
:'{{{name}}}' => :'{{{baseName}}}'{{#hasMore}},{{/hasMore}}
|
||||
{{/vars}}
|
||||
}
|
||||
end
|
||||
|
||||
# attribute type
|
||||
def self.swagger_types
|
||||
{
|
||||
{{#vars}}:'{{{name}}}' => :'{{{datatype}}}'{{#hasMore}},{{/hasMore}}
|
||||
{{/vars}}
|
||||
}
|
||||
end
|
||||
|
||||
def initialize(attributes = {})
|
||||
return if !attributes.is_a?(Hash) || attributes.empty?
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
|
||||
{{#vars}}
|
||||
if attributes[:'{{{baseName}}}']
|
||||
{{#isContainer}}if (value = attributes[:'{{{baseName}}}']).is_a?(Array)
|
||||
@{{{name}}} = value
|
||||
end{{/isContainer}}{{^isContainer}}@{{{name}}} = attributes[:'{{{baseName}}}']{{/isContainer}}
|
||||
attr_accessor {{#vars}}:{{{name}}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{newline}}
|
||||
# attribute mapping from ruby-style variable name to JSON key
|
||||
def self.attribute_map
|
||||
{
|
||||
{{#vars}}
|
||||
# {{description}}
|
||||
:'{{{name}}}' => :'{{{baseName}}}'{{#hasMore}},{{/hasMore}}
|
||||
{{/vars}}
|
||||
}
|
||||
end
|
||||
{{/vars}}
|
||||
end
|
||||
end
|
||||
|
||||
# attribute type
|
||||
def self.swagger_types
|
||||
{
|
||||
{{#vars}}:'{{{name}}}' => :'{{{datatype}}}'{{#hasMore}},{{/hasMore}}
|
||||
{{/vars}}
|
||||
}
|
||||
end
|
||||
|
||||
def initialize(attributes = {})
|
||||
return if !attributes.is_a?(Hash) || attributes.empty?
|
||||
|
||||
# convert string to symbol for hash key
|
||||
attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
||||
|
||||
{{#vars}}
|
||||
if attributes[:'{{{baseName}}}']
|
||||
{{#isContainer}}if (value = attributes[:'{{{baseName}}}']).is_a?(Array)
|
||||
@{{{name}}} = value
|
||||
end{{/isContainer}}{{^isContainer}}@{{{name}}} = attributes[:'{{{baseName}}}']{{/isContainer}}
|
||||
end
|
||||
{{/vars}}
|
||||
end
|
||||
end
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
end
|
||||
|
@ -1,90 +1,90 @@
|
||||
# module Swagger
|
||||
class Object
|
||||
class Object
|
||||
|
||||
unless Object.method_defined? :blank?
|
||||
def blank?
|
||||
respond_to?(:empty?) ? empty? : !self
|
||||
end
|
||||
end
|
||||
|
||||
unless Object.method_defined? :present?
|
||||
def present?
|
||||
!blank?
|
||||
end
|
||||
end
|
||||
|
||||
unless Object.method_defined? :blank?
|
||||
def blank?
|
||||
respond_to?(:empty?) ? empty? : !self
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Object.method_defined? :present?
|
||||
def present?
|
||||
!blank?
|
||||
end
|
||||
end
|
||||
class String
|
||||
|
||||
end
|
||||
unless String.method_defined? :underscore
|
||||
def underscore
|
||||
self.gsub(/::/, '/').
|
||||
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
||||
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
||||
tr("-", "_").
|
||||
downcase
|
||||
end
|
||||
end
|
||||
|
||||
unless String.method_defined? :camelize
|
||||
def camelize(first_letter_in_uppercase = true)
|
||||
if first_letter_in_uppercase != :lower
|
||||
self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
||||
else
|
||||
self.to_s[0].chr.downcase + camelize(self)[1..-1]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class String
|
||||
end
|
||||
|
||||
unless String.method_defined? :underscore
|
||||
def underscore
|
||||
self.gsub(/::/, '/').
|
||||
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
||||
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
||||
tr("-", "_").
|
||||
downcase
|
||||
end
|
||||
end
|
||||
class Hash
|
||||
|
||||
unless String.method_defined? :camelize
|
||||
def camelize(first_letter_in_uppercase = true)
|
||||
if first_letter_in_uppercase != :lower
|
||||
self.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
||||
else
|
||||
self.to_s[0].chr.downcase + camelize(self)[1..-1]
|
||||
end
|
||||
end
|
||||
end
|
||||
unless Hash.method_defined? :stringify_keys
|
||||
def stringify_keys
|
||||
inject({}) do |options, (key, value)|
|
||||
options[key.to_s] = value
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Hash.method_defined? :stringify_keys!
|
||||
def stringify_keys!
|
||||
self.replace(self.stringify_keys)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
unless Hash.method_defined? :symbolize_keys
|
||||
def symbolize_keys
|
||||
inject({}) do |options, (key, value)|
|
||||
options[(key.to_sym rescue key) || key] = value
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Hash.method_defined? :symbolize_keys!
|
||||
def symbolize_keys!
|
||||
self.replace(self.symbolize_keys)
|
||||
end
|
||||
end
|
||||
|
||||
class Hash
|
||||
unless Hash.method_defined? :symbolize_and_underscore_keys
|
||||
def symbolize_and_underscore_keys
|
||||
inject({}) do |options, (key, value)|
|
||||
options[(key.to_s.underscore.to_sym rescue key) || key] = value
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Hash.method_defined? :stringify_keys
|
||||
def stringify_keys
|
||||
inject({}) do |options, (key, value)|
|
||||
options[key.to_s] = value
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Hash.method_defined? :stringify_keys!
|
||||
def stringify_keys!
|
||||
self.replace(self.stringify_keys)
|
||||
end
|
||||
end
|
||||
|
||||
unless Hash.method_defined? :symbolize_keys
|
||||
def symbolize_keys
|
||||
inject({}) do |options, (key, value)|
|
||||
options[(key.to_sym rescue key) || key] = value
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Hash.method_defined? :symbolize_keys!
|
||||
def symbolize_keys!
|
||||
self.replace(self.symbolize_keys)
|
||||
end
|
||||
end
|
||||
|
||||
unless Hash.method_defined? :symbolize_and_underscore_keys
|
||||
def symbolize_and_underscore_keys
|
||||
inject({}) do |options, (key, value)|
|
||||
options[(key.to_s.underscore.to_sym rescue key) || key] = value
|
||||
options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless Hash.method_defined? :symbolize_and_underscore_keys!
|
||||
def symbolize_and_underscore_keys!
|
||||
self.replace(self.symbolize_and_underscore_keys)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
unless Hash.method_defined? :symbolize_and_underscore_keys!
|
||||
def symbolize_and_underscore_keys!
|
||||
self.replace(self.symbolize_and_underscore_keys)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
# end
|
@ -2,77 +2,77 @@ require 'logger'
|
||||
require 'json'
|
||||
|
||||
module {{moduleName}}
|
||||
module Swagger
|
||||
class << self
|
||||
attr_accessor :logger
|
||||
module Swagger
|
||||
class << self
|
||||
attr_accessor :logger
|
||||
|
||||
# A Swagger configuration object. Must act like a hash and return sensible
|
||||
# values for all Swagger configuration options. See Swagger::Configuration.
|
||||
attr_accessor :configuration
|
||||
# A Swagger configuration object. Must act like a hash and return sensible
|
||||
# values for all Swagger configuration options. See Swagger::Configuration.
|
||||
attr_accessor :configuration
|
||||
|
||||
attr_accessor :resources
|
||||
attr_accessor :resources
|
||||
|
||||
# Call this method to modify defaults in your initializers.
|
||||
#
|
||||
# @example
|
||||
# Swagger.configure do |config|
|
||||
# config.api_key['api_key'] = '1234567890abcdef' # api key authentication
|
||||
# config.username = 'wordlover' # http basic authentication
|
||||
# config.password = 'i<3words' # http basic authentication
|
||||
# config.format = 'json' # optional, defaults to 'json'
|
||||
# end
|
||||
#
|
||||
def configure
|
||||
yield(configuration) if block_given?
|
||||
# Call this method to modify defaults in your initializers.
|
||||
#
|
||||
# @example
|
||||
# Swagger.configure do |config|
|
||||
# config.api_key['api_key'] = '1234567890abcdef' # api key authentication
|
||||
# config.username = 'wordlover' # http basic authentication
|
||||
# config.password = 'i<3words' # http basic authentication
|
||||
# config.format = 'json' # optional, defaults to 'json'
|
||||
# end
|
||||
#
|
||||
def configure
|
||||
yield(configuration) if block_given?
|
||||
|
||||
# Configure logger. Default to use Rails
|
||||
self.logger ||= configuration.logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
|
||||
# Configure logger. Default to use Rails
|
||||
self.logger ||= configuration.logger || (defined?(Rails) ? Rails.logger : Logger.new(STDOUT))
|
||||
|
||||
# remove :// from scheme
|
||||
configuration.scheme.sub!(/:\/\//, '')
|
||||
# remove :// from scheme
|
||||
configuration.scheme.sub!(/:\/\//, '')
|
||||
|
||||
# remove http(s):// and anything after a slash
|
||||
configuration.host.sub!(/https?:\/\//, '')
|
||||
configuration.host = configuration.host.split('/').first
|
||||
# remove http(s):// and anything after a slash
|
||||
configuration.host.sub!(/https?:\/\//, '')
|
||||
configuration.host = configuration.host.split('/').first
|
||||
|
||||
# Add leading and trailing slashes to base_path
|
||||
configuration.base_path = "/#{configuration.base_path}".gsub(/\/+/, '/')
|
||||
configuration.base_path = "" if configuration.base_path == "/"
|
||||
end
|
||||
|
||||
def authenticated?
|
||||
Swagger.configuration.auth_token.present?
|
||||
end
|
||||
|
||||
def de_authenticate
|
||||
Swagger.configuration.auth_token = nil
|
||||
end
|
||||
|
||||
def authenticate
|
||||
return if Swagger.authenticated?
|
||||
|
||||
if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
|
||||
raise ClientError, "Username and password are required to authenticate."
|
||||
end
|
||||
|
||||
request = Swagger::Request.new(
|
||||
:get,
|
||||
"account/authenticate/{username}",
|
||||
:params => {
|
||||
:username => Swagger.configuration.username,
|
||||
:password => Swagger.configuration.password
|
||||
}
|
||||
)
|
||||
|
||||
response_body = request.response.body
|
||||
Swagger.configuration.auth_token = response_body['token']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ServerError < StandardError
|
||||
end
|
||||
|
||||
class ClientError < StandardError
|
||||
end
|
||||
# Add leading and trailing slashes to base_path
|
||||
configuration.base_path = "/#{configuration.base_path}".gsub(/\/+/, '/')
|
||||
configuration.base_path = "" if configuration.base_path == "/"
|
||||
end
|
||||
|
||||
def authenticated?
|
||||
Swagger.configuration.auth_token.present?
|
||||
end
|
||||
|
||||
def de_authenticate
|
||||
Swagger.configuration.auth_token = nil
|
||||
end
|
||||
|
||||
def authenticate
|
||||
return if Swagger.authenticated?
|
||||
|
||||
if Swagger.configuration.username.blank? || Swagger.configuration.password.blank?
|
||||
raise ClientError, "Username and password are required to authenticate."
|
||||
end
|
||||
|
||||
request = Swagger::Request.new(
|
||||
:get,
|
||||
"account/authenticate/{username}",
|
||||
:params => {
|
||||
:username => Swagger.configuration.username,
|
||||
:password => Swagger.configuration.password
|
||||
}
|
||||
)
|
||||
|
||||
response_body = request.response.body
|
||||
Swagger.configuration.auth_token = response_body['token']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ServerError < StandardError
|
||||
end
|
||||
|
||||
class ClientError < StandardError
|
||||
end
|
||||
end
|
||||
|
@ -3,30 +3,30 @@ $:.push File.expand_path("../lib", __FILE__)
|
||||
require "{{gemName}}/swagger/version"
|
||||
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "{{gemName}}"
|
||||
s.version = {{moduleName}}::Swagger::VERSION
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["Zeke Sikelianos", "Tony Tam"]
|
||||
s.email = ["zeke@wordnik.com", "fehguy@gmail.com"]
|
||||
s.homepage = "http://swagger.io"
|
||||
s.summary = %q{A ruby wrapper for the swagger APIs}
|
||||
s.description = %q{This gem maps to a swagger API}
|
||||
s.license = "Apache-2.0"
|
||||
s.name = "{{gemName}}"
|
||||
s.version = {{moduleName}}::Swagger::VERSION
|
||||
s.platform = Gem::Platform::RUBY
|
||||
s.authors = ["Zeke Sikelianos", "Tony Tam"]
|
||||
s.email = ["zeke@wordnik.com", "fehguy@gmail.com"]
|
||||
s.homepage = "http://swagger.io"
|
||||
s.summary = %q{A ruby wrapper for the swagger APIs}
|
||||
s.description = %q{This gem maps to a swagger API}
|
||||
s.license = "Apache-2.0"
|
||||
|
||||
s.add_runtime_dependency 'typhoeus', '~> 0.2', '>= 0.2.1'
|
||||
s.add_runtime_dependency 'addressable', '~> 2.2', '>= 2.2.4'
|
||||
s.add_runtime_dependency 'json', '~> 1.4', '>= 1.4.6'
|
||||
s.add_runtime_dependency 'typhoeus', '~> 0.2', '>= 0.2.1'
|
||||
s.add_runtime_dependency 'addressable', '~> 2.2', '>= 2.2.4'
|
||||
s.add_runtime_dependency 'json', '~> 1.4', '>= 1.4.6'
|
||||
|
||||
s.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
|
||||
s.add_development_dependency 'vcr', '~> 2.9', '>= 2.9.3'
|
||||
s.add_development_dependency 'webmock', '~> 1.6', '>= 1.6.2'
|
||||
s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6'
|
||||
s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2'
|
||||
s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16'
|
||||
s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.10'
|
||||
s.add_development_dependency 'rspec', '~> 3.2', '>= 3.2.0'
|
||||
s.add_development_dependency 'vcr', '~> 2.9', '>= 2.9.3'
|
||||
s.add_development_dependency 'webmock', '~> 1.6', '>= 1.6.2'
|
||||
s.add_development_dependency 'autotest', '~> 4.4', '>= 4.4.6'
|
||||
s.add_development_dependency 'autotest-rails-pure', '~> 4.1', '>= 4.1.2'
|
||||
s.add_development_dependency 'autotest-growl', '~> 0.2', '>= 0.2.16'
|
||||
s.add_development_dependency 'autotest-fsevent', '~> 0.2', '>= 0.2.10'
|
||||
|
||||
s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? }
|
||||
s.test_files = `find spec/*`.split("\n")
|
||||
s.executables = []
|
||||
s.require_paths = ["lib"]
|
||||
s.files = `find *`.split("\n").uniq.sort.select{|f| !f.empty? }
|
||||
s.test_files = `find spec/*`.split("\n")
|
||||
s.executables = []
|
||||
s.require_paths = ["lib"]
|
||||
end
|
||||
|
@ -9,17 +9,17 @@ require '{{gemName}}/swagger/version'
|
||||
# Models
|
||||
require '{{modelPackage}}/base_object'
|
||||
{{#models}}
|
||||
require '{{importPath}}'
|
||||
require '{{importPath}}'
|
||||
{{/models}}
|
||||
|
||||
# APIs
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
require '{{importPath}}'
|
||||
{{/apis}}
|
||||
{{#apis}}
|
||||
require '{{importPath}}'
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
|
||||
module {{moduleName}}
|
||||
# Initialize the default configuration
|
||||
Swagger.configuration ||= Swagger::Configuration.new
|
||||
# Initialize the default configuration
|
||||
Swagger.configuration ||= Swagger::Configuration.new
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user