Skip to content

Commit d0d3893

Browse files
authored
Merge pull request #19 from patch-technology/lovisa/fix-hash
Generate Class#openapi_nullable methods
2 parents e6f0167 + 231b723 commit d0d3893

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+568
-38
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.2.5] - 2020-01-08
11+
12+
### Fixed
13+
14+
- Fixes [issues/5](https://github.com/patch-technology/patch-ruby/issues/5). Adds method `.openapi_nullable` which returns a set with all nullable properties. This method is referenced in `#to_hash` which returns a hash representation of the resource.
15+
- Removes non-deterministic integration spec that is creating an Estimate with a specific project-id. Since we do not control the test data (yet) and make queries against our Test projects, we cannot be sure that we will have offsets available for a project ID. Instead we can rely on Patch core specs to cover this.
16+
- Fixes a spec that was failing due to a Patch core change.
17+
- Add spec factories and refactor generated method specs to shared examples.
18+
1019
## [1.2.4] - 2020-10-14
1120

1221
### Added

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ group :development, :test do
66
gem 'rake', '~> 13.0.1'
77
gem 'pry-byebug'
88
gem 'rubocop'
9+
gem 'factory_bot'
910
end

Gemfile.lock

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
PATH
22
remote: .
33
specs:
4-
patch_ruby (1.2.4)
4+
patch_ruby (1.2.5)
55
json (~> 2.1, >= 2.1.0)
66
typhoeus (~> 1.0, >= 1.0.1)
77

88
GEM
99
remote: https://rubygems.org/
1010
specs:
11+
activesupport (6.1.1)
12+
concurrent-ruby (~> 1.0, >= 1.0.2)
13+
i18n (>= 1.6, < 2)
14+
minitest (>= 5.1)
15+
tzinfo (~> 2.0)
16+
zeitwerk (~> 2.3)
1117
ast (2.4.1)
1218
byebug (11.1.3)
1319
coderay (1.1.3)
20+
concurrent-ruby (1.1.7)
1421
diff-lcs (1.4.3)
1522
ethon (0.12.0)
1623
ffi (>= 1.3.0)
24+
factory_bot (6.1.0)
25+
activesupport (>= 5.0.0)
1726
ffi (1.13.1)
18-
json (2.3.1)
27+
i18n (1.8.7)
28+
concurrent-ruby (~> 1.0)
29+
json (2.4.1)
1930
method_source (1.0.0)
31+
minitest (5.14.3)
2032
parallel (1.19.2)
2133
parser (2.7.1.4)
2234
ast (~> 2.4.1)
@@ -57,12 +69,16 @@ GEM
5769
ruby-progressbar (1.10.1)
5870
typhoeus (1.4.0)
5971
ethon (>= 0.9.0)
72+
tzinfo (2.0.4)
73+
concurrent-ruby (~> 1.0)
6074
unicode-display_width (1.7.0)
75+
zeitwerk (2.4.2)
6176

6277
PLATFORMS
6378
ruby
6479

6580
DEPENDENCIES
81+
factory_bot
6682
patch_ruby!
6783
pry-byebug
6884
rake (~> 13.0.1)

lib/patch_ruby/models/allocation.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414

1515
module Patch
1616
class Allocation
17+
# A unique uid for the record. UIDs will be prepended by all_prod or all_test depending on the mode it was created in.
1718
attr_accessor :id
1819

20+
# A boolean indicating if this project is a production or test mode project.
1921
attr_accessor :production
2022

23+
# The amount (in grams) of allocated carbon offsets.
2124
attr_accessor :mass_g
2225

2326
# Attribute mapping from ruby-style variable name to JSON key.
@@ -38,6 +41,13 @@ def self.openapi_types
3841
}
3942
end
4043

44+
# Set with nullable attributes.
45+
def self.openapi_nullable
46+
nullable_properties = Set.new
47+
48+
nullable_properties
49+
end
50+
4151
# Allows models with corresponding API classes to delegate API operations to those API classes
4252
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
4353
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/create_mass_estimate_request.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def self.openapi_types
3434
}
3535
end
3636

37+
# Set with nullable attributes.
38+
def self.openapi_nullable
39+
nullable_properties = Set.new
40+
41+
nullable_properties
42+
end
43+
3744
# Allows models with corresponding API classes to delegate API operations to those API classes
3845
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
3946
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/create_order_request.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ def self.openapi_types
4242
}
4343
end
4444

45+
# Set with nullable attributes.
46+
def self.openapi_nullable
47+
nullable_properties = Set.new
48+
49+
nullable_properties
50+
end
51+
4552
# Allows models with corresponding API classes to delegate API operations to those API classes
4653
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
4754
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/create_preference_request.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def self.openapi_types
3030
}
3131
end
3232

33+
# Set with nullable attributes.
34+
def self.openapi_nullable
35+
nullable_properties = Set.new
36+
37+
nullable_properties
38+
end
39+
3340
# Allows models with corresponding API classes to delegate API operations to those API classes
3441
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
3542
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/error_response.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41+
# Set with nullable attributes.
42+
def self.openapi_nullable
43+
nullable_properties = Set.new
44+
45+
nullable_properties.add("data")
46+
47+
nullable_properties
48+
end
49+
4150
# Allows models with corresponding API classes to delegate API operations to those API classes
4251
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
4352
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/estimate.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
module Patch
1616
class Estimate
17+
# A unique uid for the record. UIDs will be prepended by est_prod or est_test depending on the mode it was created in.
1718
attr_accessor :id
1819

20+
# A boolean indicating if this estimate is a production or test mode estimate.
1921
attr_accessor :production
2022

23+
# The type of estimate. Currently mass is the only supported value.
2124
attr_accessor :type
2225

26+
# An object returning the order associated with this estimate. See the [Order section](/?id=orders) for the full schema.
2327
attr_accessor :order
2428

2529
# Attribute mapping from ruby-style variable name to JSON key.
@@ -42,6 +46,15 @@ def self.openapi_types
4246
}
4347
end
4448

49+
# Set with nullable attributes.
50+
def self.openapi_nullable
51+
nullable_properties = Set.new
52+
53+
nullable_properties.add("order")
54+
55+
nullable_properties
56+
end
57+
4558
# Allows models with corresponding API classes to delegate API operations to those API classes
4659
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
4760
# Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -226,7 +239,7 @@ def to_hash
226239
is_nullable = self.class.openapi_nullable.include?(attr)
227240
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
228241
end
229-
242+
230243
hash[param] = _to_hash(value)
231244
end
232245
hash

lib/patch_ruby/models/estimate_list_response.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ def self.openapi_types
4242
}
4343
end
4444

45+
# Set with nullable attributes.
46+
def self.openapi_nullable
47+
nullable_properties = Set.new
48+
49+
nullable_properties.add("error")
50+
51+
nullable_properties
52+
end
53+
4554
# Allows models with corresponding API classes to delegate API operations to those API classes
4655
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
4756
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/estimate_response.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41+
# Set with nullable attributes.
42+
def self.openapi_nullable
43+
nullable_properties = Set.new
44+
45+
nullable_properties.add("error")
46+
47+
nullable_properties
48+
end
49+
4150
# Allows models with corresponding API classes to delegate API operations to those API classes
4251
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
4352
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/meta_index_object.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ def self.openapi_types
3434
}
3535
end
3636

37+
# Set with nullable attributes.
38+
def self.openapi_nullable
39+
nullable_properties = Set.new
40+
41+
nullable_properties.add("prev_page")
42+
43+
nullable_properties.add("next_page")
44+
45+
nullable_properties
46+
end
47+
3748
# Allows models with corresponding API classes to delegate API operations to those API classes
3849
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
3950
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/order.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,31 @@
1414

1515
module Patch
1616
class Order
17+
# A unique uid for the record. UIDs will be prepended by ord_prod or ord_test depending on the mode it was created in.
1718
attr_accessor :id
1819

20+
# The amount of carbon offsets in grams purchased through this order.
1921
attr_accessor :mass_g
2022

23+
# A boolean indicating if this order is a production or test mode order.
2124
attr_accessor :production
2225

26+
# The current state of the order.
2327
attr_accessor :state
2428

29+
# The current state of the allocated carbon offsets of the order.
2530
attr_accessor :allocation_state
2631

32+
# The total price in cents USD of the carbon offsets purchased through this order.
2733
attr_accessor :price_cents_usd
2834

35+
# The Patch Fee in cents USD for this order.
2936
attr_accessor :patch_fee_cents_usd
3037

38+
# An array containing the inventory allocations for this order.
3139
attr_accessor :allocations
3240

41+
# An optional JSON object containing metadata for this order.
3342
attr_accessor :metadata
3443

3544
class EnumAttributeValidator
@@ -84,6 +93,17 @@ def self.openapi_types
8493
}
8594
end
8695

96+
# Set with nullable attributes.
97+
def self.openapi_nullable
98+
nullable_properties = Set.new
99+
100+
nullable_properties.add("price_cents_usd")
101+
102+
nullable_properties.add("patch_fee_cents_usd")
103+
104+
nullable_properties
105+
end
106+
87107
# Allows models with corresponding API classes to delegate API operations to those API classes
88108
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
89109
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/order_list_response.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ def self.openapi_types
4242
}
4343
end
4444

45+
# Set with nullable attributes.
46+
def self.openapi_nullable
47+
nullable_properties = Set.new
48+
49+
nullable_properties.add("error")
50+
51+
nullable_properties
52+
end
53+
4554
# Allows models with corresponding API classes to delegate API operations to those API classes
4655
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
4756
# Eg. Order.create_order delegates to OrdersApi.new.create_order

lib/patch_ruby/models/order_response.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ def self.openapi_types
3838
}
3939
end
4040

41+
# Set with nullable attributes.
42+
def self.openapi_nullable
43+
nullable_properties = Set.new
44+
45+
nullable_properties.add("error")
46+
47+
nullable_properties
48+
end
49+
4150
# Allows models with corresponding API classes to delegate API operations to those API classes
4251
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
4352
# Eg. Order.create_order delegates to OrdersApi.new.create_order

0 commit comments

Comments
 (0)