File tree Expand file tree Collapse file tree
spec/lib/openapi3_parser/node_factory/schema Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ then - single schema - done
8181else - single schema - done
8282dependentSchemas - map of schemas - somewhat complex, is it related to dependentRequired ?
8383
84- prefixItems: array of schema
84+ prefixItems: array of schema - done
8585items: array of schema - in 3.0
8686contains: schema
8787
Original file line number Diff line number Diff line change @@ -69,6 +69,11 @@ def then
6969 def else
7070 self [ "else" ]
7171 end
72+
73+ # @return [Node::Array<Schema>]
74+ def prefix_items
75+ self [ "prefixItems" ]
76+ end
7277 end
7378 end
7479 end
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ class V3_1 < NodeFactory::Object # rubocop:disable Naming/ClassAndModuleCamelCas
3232 field "if" , factory : :referenceable_schema
3333 field "then" , factory : :referenceable_schema
3434 field "else" , factory : :referenceable_schema
35+ field "prefixItems" , factory : :prefix_items_factory
3536
3637 def build_node ( data , node_context )
3738 Node ::Schema ::V3_1 . new ( data , node_context )
@@ -77,6 +78,13 @@ def validate_type(validatable)
7778 validatable . add_error ( "type must be a string or an array" )
7879 end
7980 end
81+
82+ def prefix_items_factory ( context )
83+ NodeFactory ::Array . new (
84+ context ,
85+ value_factory : NodeFactory ::Schema . factory ( context )
86+ )
87+ end
8088 end
8189 end
8290 end
Original file line number Diff line number Diff line change 167167 . with_message ( '"not a media type" is not a valid media type' )
168168 end
169169 end
170+
171+ describe "prefixItems field" do
172+ it "is valid with an array with schema values" do
173+ instance = described_class . new (
174+ create_node_factory_context ( { "prefixItems" => [ { "type" => "string" } ] } )
175+ )
176+
177+ expect ( instance ) . to be_valid
178+ end
179+
180+ it "is invalid for a type other than array" do
181+ instance = described_class . new (
182+ create_node_factory_context ( { "prefixItems" => "string" } )
183+ )
184+
185+ expect ( instance ) . not_to be_valid
186+ expect ( instance )
187+ . to have_validation_error ( "#/prefixItems" )
188+ . with_message ( "Invalid type. Expected Array" )
189+ end
190+
191+ it "is invalid for values other than objects" do
192+ instance = described_class . new (
193+ create_node_factory_context ( { "prefixItems" => %w[ string ] } )
194+ )
195+
196+ expect ( instance ) . not_to be_valid
197+ expect ( instance )
198+ . to have_validation_error ( "#/prefixItems/0" )
199+ . with_message ( "Invalid type. Expected Object" )
200+ end
201+ end
170202end
You can’t perform that action at this time.
0 commit comments