Skip to content

Commit 3f4dc7b

Browse files
committed
Add pathItems to components for OpenAPI 3.1
1 parent e2e4056 commit 3f4dc7b

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

lib/openapi3_parser/node_factory/components.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class Components < NodeFactory::Object
1515
field "securitySchemes", factory: :security_schemes_factory
1616
field "links", factory: :links_factory
1717
field "callbacks", factory: :callbacks_factory
18+
field "pathItems",
19+
factory: :path_items_factory,
20+
allowed: ->(context) { context.openapi_version >= "3.1" }
1821

1922
def build_node(data, node_context)
2023
Node::Components.new(data, node_context)
@@ -62,6 +65,10 @@ def callbacks_factory(context)
6265
referenceable_map_factory(context, NodeFactory::Callback)
6366
end
6467

68+
def path_items_factory(context)
69+
referenceable_map_factory(context, NodeFactory::PathItem)
70+
end
71+
6572
def referenceable_map_factory(context, factory)
6673
NodeFactory::Map.new(
6774
context,

spec/lib/openapi3_parser/node_factory/components_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,30 @@
131131
expect(instance).to have_validation_error("#/responses")
132132
end
133133
end
134+
135+
describe "pathItems field" do
136+
it "accepts this field for OpenAPI >= 3.1" do
137+
factory_context = create_node_factory_context(
138+
{
139+
"pathItems" => { "key" => { "summary" => "Item summary" } }
140+
},
141+
document_input: { "openapi" => "3.1.0" }
142+
)
143+
144+
instance = described_class.new(factory_context)
145+
expect(instance).to be_valid
146+
end
147+
148+
it "rejects this field for OpenAPI < 3.1" do
149+
factory_context = create_node_factory_context(
150+
{
151+
"pathItems" => { "key" => { "summary" => "Item summary" } }
152+
},
153+
document_input: { "openapi" => "3.0.0" }
154+
)
155+
156+
instance = described_class.new(factory_context)
157+
expect(instance).not_to be_valid
158+
end
159+
end
134160
end

0 commit comments

Comments
 (0)