Skip to content

Commit 860631f

Browse files
authored
Improve automatic generation (#37)
* Remove the ignore list in code gen * Remove unused models * Bump version
1 parent 4c8f0f5 commit 860631f

8 files changed

+1232
-3
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
patch_ruby (1.10.0)
4+
patch_ruby (1.10.1)
55
typhoeus (~> 1.0, >= 1.0.1)
66

77
GEM

lib/patch_ruby.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
require 'patch_ruby/models/allocation'
2121
require 'patch_ruby/models/create_bitcoin_estimate_request'
2222
require 'patch_ruby/models/create_ethereum_estimate_request'
23+
require 'patch_ruby/models/create_flight_estimate_request'
2324
require 'patch_ruby/models/create_mass_estimate_request'
2425
require 'patch_ruby/models/create_order_request'
2526
require 'patch_ruby/models/create_preference_request'
27+
require 'patch_ruby/models/create_shipping_estimate_request'
28+
require 'patch_ruby/models/create_success_response'
29+
require 'patch_ruby/models/create_vehicle_estimate_request'
2630
require 'patch_ruby/models/error_response'
2731
require 'patch_ruby/models/estimate'
2832
require 'patch_ruby/models/estimate_list_response'

lib/patch_ruby/api_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ApiClient
3131
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
3232
def initialize(config = Configuration.default)
3333
@config = config
34-
@user_agent = "patch-ruby/1.10.0"
34+
@user_agent = "patch-ruby/1.10.1"
3535
@default_headers = {
3636
'Content-Type' => 'application/json',
3737
'User-Agent' => @user_agent
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
=begin
2+
#Patch API V1
3+
4+
#The core API used to integrate with Patch's service
5+
6+
The version of the OpenAPI document: v1
7+
8+
Generated by: https://openapi-generator.tech
9+
OpenAPI Generator version: 5.2.1
10+
11+
=end
12+
13+
require 'date'
14+
require 'time'
15+
16+
module Patch
17+
class CreateFlightEstimateRequest
18+
attr_accessor :distance_m
19+
20+
attr_accessor :project_id
21+
22+
attr_accessor :create_order
23+
24+
# Attribute mapping from ruby-style variable name to JSON key.
25+
def self.attribute_map
26+
{
27+
:'distance_m' => :'distance_m',
28+
:'project_id' => :'project_id',
29+
:'create_order' => :'create_order'
30+
}
31+
end
32+
33+
# Returns all the JSON keys this model knows about
34+
def self.acceptable_attributes
35+
attribute_map.values
36+
end
37+
38+
# Attribute type mapping.
39+
def self.openapi_types
40+
{
41+
:'distance_m' => :'Integer',
42+
:'project_id' => :'String',
43+
:'create_order' => :'Boolean'
44+
}
45+
end
46+
47+
# List of attributes with nullable: true
48+
def self.openapi_nullable
49+
Set.new([
50+
:'project_id',
51+
:'create_order'
52+
])
53+
end
54+
55+
56+
# Allows models with corresponding API classes to delegate API operations to those API classes
57+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
58+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
59+
def self.method_missing(message, *args, &block)
60+
if Object.const_defined?('Patch::CreateFlightEstimateRequestsApi::OPERATIONS') && Patch::CreateFlightEstimateRequestsApi::OPERATIONS.include?(message)
61+
Patch::CreateFlightEstimateRequestsApi.new.send(message, *args)
62+
else
63+
super
64+
end
65+
end
66+
67+
# Initializes the object
68+
# @param [Hash] attributes Model attributes in the form of hash
69+
def initialize(attributes = {})
70+
if (!attributes.is_a?(Hash))
71+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateFlightEstimateRequest` initialize method"
72+
end
73+
74+
# check to see if the attribute exists and convert string to symbol for hash key
75+
attributes = attributes.each_with_object({}) { |(k, v), h|
76+
if (!self.class.attribute_map.key?(k.to_sym))
77+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateFlightEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
78+
end
79+
h[k.to_sym] = v
80+
}
81+
82+
if attributes.key?(:'distance_m')
83+
self.distance_m = attributes[:'distance_m']
84+
end
85+
86+
if attributes.key?(:'project_id')
87+
self.project_id = attributes[:'project_id']
88+
end
89+
90+
if attributes.key?(:'create_order')
91+
self.create_order = attributes[:'create_order']
92+
end
93+
end
94+
95+
# Show invalid properties with the reasons. Usually used together with valid?
96+
# @return Array for valid properties with the reasons
97+
def list_invalid_properties
98+
invalid_properties = Array.new
99+
if @distance_m.nil?
100+
invalid_properties.push('invalid value for "distance_m", distance_m cannot be nil.')
101+
end
102+
103+
if @distance_m > 400000000
104+
invalid_properties.push('invalid value for "distance_m", must be smaller than or equal to 400000000.')
105+
end
106+
107+
if @distance_m < 0
108+
invalid_properties.push('invalid value for "distance_m", must be greater than or equal to 0.')
109+
end
110+
111+
invalid_properties
112+
end
113+
114+
# Check to see if the all the properties in the model are valid
115+
# @return true if the model is valid
116+
def valid?
117+
return false if @distance_m.nil?
118+
return false if @distance_m > 400000000
119+
return false if @distance_m < 0
120+
true
121+
end
122+
123+
# Custom attribute writer method with validation
124+
# @param [Object] distance_m Value to be assigned
125+
def distance_m=(distance_m)
126+
if distance_m.nil?
127+
fail ArgumentError, 'distance_m cannot be nil'
128+
end
129+
130+
if distance_m > 400000000
131+
fail ArgumentError, 'invalid value for "distance_m", must be smaller than or equal to 400000000.'
132+
end
133+
134+
if distance_m < 0
135+
fail ArgumentError, 'invalid value for "distance_m", must be greater than or equal to 0.'
136+
end
137+
138+
@distance_m = distance_m
139+
end
140+
141+
# Checks equality by comparing each attribute.
142+
# @param [Object] Object to be compared
143+
def ==(o)
144+
return true if self.equal?(o)
145+
self.class == o.class &&
146+
distance_m == o.distance_m &&
147+
project_id == o.project_id &&
148+
create_order == o.create_order
149+
end
150+
151+
# @see the `==` method
152+
# @param [Object] Object to be compared
153+
def eql?(o)
154+
self == o
155+
end
156+
157+
# Calculates hash code according to all attributes.
158+
# @return [Integer] Hash code
159+
def hash
160+
[distance_m, project_id, create_order].hash
161+
end
162+
163+
# Builds the object from hash
164+
# @param [Hash] attributes Model attributes in the form of hash
165+
# @return [Object] Returns the model itself
166+
def self.build_from_hash(attributes)
167+
new.build_from_hash(attributes)
168+
end
169+
170+
# Builds the object from hash
171+
# @param [Hash] attributes Model attributes in the form of hash
172+
# @return [Object] Returns the model itself
173+
def build_from_hash(attributes)
174+
return nil unless attributes.is_a?(Hash)
175+
self.class.openapi_types.each_pair do |key, type|
176+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
177+
self.send("#{key}=", nil)
178+
elsif type =~ /\AArray<(.*)>/i
179+
# check to ensure the input is an array given that the attribute
180+
# is documented as an array but the input is not
181+
if attributes[self.class.attribute_map[key]].is_a?(Array)
182+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
183+
end
184+
elsif !attributes[self.class.attribute_map[key]].nil?
185+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
186+
end
187+
end
188+
189+
self
190+
end
191+
192+
# Deserializes the data based on type
193+
# @param string type Data type
194+
# @param string value Value to be deserialized
195+
# @return [Object] Deserialized data
196+
def _deserialize(type, value)
197+
case type.to_sym
198+
when :Time
199+
Time.parse(value)
200+
when :Date
201+
Date.parse(value)
202+
when :String
203+
value.to_s
204+
when :Integer
205+
value.to_i
206+
when :Float
207+
value.to_f
208+
when :Boolean
209+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
210+
true
211+
else
212+
false
213+
end
214+
when :Object
215+
# generic object (usually a Hash), return directly
216+
value
217+
when /\AArray<(?<inner_type>.+)>\z/
218+
inner_type = Regexp.last_match[:inner_type]
219+
value.map { |v| _deserialize(inner_type, v) }
220+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
221+
k_type = Regexp.last_match[:k_type]
222+
v_type = Regexp.last_match[:v_type]
223+
{}.tap do |hash|
224+
value.each do |k, v|
225+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
226+
end
227+
end
228+
else # model
229+
# models (e.g. Pet) or oneOf
230+
klass = Patch.const_get(type)
231+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
232+
end
233+
end
234+
235+
# Returns the string representation of the object
236+
# @return [String] String presentation of the object
237+
def to_s
238+
to_hash.to_s
239+
end
240+
241+
# to_body is an alias to to_hash (backward compatibility)
242+
# @return [Hash] Returns the object in the form of hash
243+
def to_body
244+
to_hash
245+
end
246+
247+
# Returns the object in the form of hash
248+
# @return [Hash] Returns the object in the form of hash
249+
def to_hash
250+
hash = {}
251+
self.class.attribute_map.each_pair do |attr, param|
252+
value = self.send(attr)
253+
if value.nil?
254+
is_nullable = self.class.openapi_nullable.include?(attr)
255+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
256+
end
257+
258+
hash[param] = _to_hash(value)
259+
end
260+
hash
261+
end
262+
263+
# Outputs non-array value in the form of hash
264+
# For object, use to_hash. Otherwise, just return the value
265+
# @param [Object] value Any valid value
266+
# @return [Hash] Returns the value in the form of hash
267+
def _to_hash(value)
268+
if value.is_a?(Array)
269+
value.compact.map { |v| _to_hash(v) }
270+
elsif value.is_a?(Hash)
271+
{}.tap do |hash|
272+
value.each { |k, v| hash[k] = _to_hash(v) }
273+
end
274+
elsif value.respond_to? :to_hash
275+
value.to_hash
276+
else
277+
value
278+
end
279+
end
280+
end
281+
end

0 commit comments

Comments
 (0)