Skip to content

Commit 1158cfd

Browse files
committed
1 parent 8733278 commit 1158cfd

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

lib/openapi3_parser/node/schema/v3_1.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ def examples
5050
self["examples"]
5151
end
5252

53+
# @return [Node::Map<String, Node::Array<String>>]
54+
def dependent_required
55+
self["dependentRequired"]
56+
end
57+
5358
# @return [String, nil]
5459
def content_encoding
5560
self["contentEncoding"]

lib/openapi3_parser/node_factory/schema/v3_1.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class V3_1 < NodeFactory::Object # rubocop:disable Naming/ClassAndModuleCamelCas
2424
field "exclusiveMinimum", input_type: Numeric
2525
field "maxContains", input_type: Integer
2626
field "minContains", input_type: Integer, default: 1
27-
# dependentRequired - map with basic validation rules
2827
field "examples", factory: NodeFactory::Array
28+
field "dependentRequired", factory: :dependent_required_factory
2929
field "contentEncoding", input_type: String
3030
field "contentMediaType",
3131
input_type: String,
@@ -83,6 +83,17 @@ def validate_type(validatable)
8383
end
8484
end
8585

86+
def dependent_required_factory(context)
87+
value_factory = lambda do |value_context|
88+
NodeFactory::Array.new(value_context, value_input_type: String)
89+
end
90+
91+
NodeFactory::Map.new(
92+
context,
93+
value_factory:
94+
)
95+
end
96+
8697
def prefix_items_factory(context)
8798
NodeFactory::Array.new(
8899
context,

spec/integration/open_v3.1_examples_spec.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,19 @@
4545
end
4646

4747
it "can access a referenced schema" do
48-
expect(document.components.schemas["DoubleReferencedSchema"]["required"])
48+
expect(document.components.schemas["DoubleReferencedSchema"].required)
4949
.to match_array(%w[id name])
50-
expect(document.components.schemas["DoubleReferencedSchema"]["description"])
50+
expect(document.components.schemas["DoubleReferencedSchema"].description)
5151
.to eq("My double referenced schema")
5252
end
53+
54+
it "can parse and navigate a dependentRequired field" do
55+
schema = document.components.schemas["DependentRequired"]
56+
57+
expect(schema.dependent_required).to be_a(Openapi3Parser::Node::Map)
58+
expect(schema.dependent_required.keys).to match_array(%w[credit_card])
59+
expect(schema.dependent_required["credit_card"]).to be_a(Openapi3Parser::Node::Array)
60+
expect(schema.dependent_required["credit_card"]).to match_array(%w[billing_address])
61+
end
5362
end
5463
end

spec/support/examples/v3.1/changes.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ components:
7979
type: string
8080
exp:
8181
type: string
82+
DependentRequired:
83+
type: object
84+
properties:
85+
name:
86+
type: string
87+
credit_card:
88+
type: number
89+
billing_address:
90+
type: string
91+
required:
92+
- name
93+
dependentRequired:
94+
credit_card:
95+
- billing_address
8296
Number:
8397
type: integer
8498
multipleOf: 5
@@ -112,6 +126,7 @@ components:
112126
patternProperties:
113127
/^test/:
114128
type: string
129+
# Boolean: true
115130
# Add content types
116131
# Add $ref usage (plain, merged, defs)
117132
# Add compound things: anyOf, oneOf, not, if, then, else

0 commit comments

Comments
 (0)