Skip to content

Commit 975ade0

Browse files
committed
Fix values of false being converted to nil
Fixes #28 We previously checked for whether a hash value was truthy before setting a default to nil. This meant that valid usages of a `false` value would be ignored and set to nil.
1 parent f081c41 commit 975ade0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/openapi3_parser/node_factory/object.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def build_data(raw_input)
8484

8585
def process_data(raw_data)
8686
field_configs.each_with_object(raw_data.dup) do |(field, config), memo|
87-
memo[field] = nil unless memo[field]
87+
memo[field] = nil unless memo.key?(field)
8888
next unless config.factory?
8989

9090
next_context = Context.next_field(context, field, memo[field])

spec/lib/openapi3_parser/node_factory/schema_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@
120120
end
121121
end
122122

123+
describe "default field" do
124+
it "supports a default field of false" do
125+
node_factory_context = create_node_factory_context({ "default" => false })
126+
node_context = node_factory_context_to_node_context(node_factory_context)
127+
128+
instance = described_class.new(node_factory_context)
129+
130+
expect(instance).to be_valid
131+
expect(instance.node(node_context).default).to be(false)
132+
end
133+
end
134+
123135
describe "validating writeOnly and readOnly" do
124136
it "is invalid when both writeOnly and readOnly are true" do
125137
instance = described_class.new(

0 commit comments

Comments
 (0)