From 97d1dd2a9ac0d8c97bab175945550dcffa3aef9d Mon Sep 17 00:00:00 2001 From: Jon Ander Date: Fri, 12 Feb 2016 13:23:13 -0430 Subject: [PATCH] Allow objects inside items. --- lib/swagger/blocks.rb | 8 +++++++- spec/lib/swagger_v2_api_declaration.json | 14 ++++++++++++++ spec/lib/swagger_v2_blocks_spec.rb | 12 ++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/swagger/blocks.rb b/lib/swagger/blocks.rb index 491b0da..d6276b0 100644 --- a/lib/swagger/blocks.rb +++ b/lib/swagger/blocks.rb @@ -692,7 +692,13 @@ class ExampleNode < Node; end # v1.2: # v2.0: - class ItemsNode < Node; end + class ItemsNode < Node + def property(name, inline_keys = nil, &block) + self.data[:properties] ||= Swagger::Blocks::PropertiesNode.new + self.data[:properties].version = version + self.data[:properties].property(name, inline_keys, &block) + end + end # v1.2: http://goo.gl/PvwUXj#524-parameter-object # v2.0: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#parameter-object diff --git a/spec/lib/swagger_v2_api_declaration.json b/spec/lib/swagger_v2_api_declaration.json index b0d1e4c..1562b5e 100644 --- a/spec/lib/swagger_v2_api_declaration.json +++ b/spec/lib/swagger_v2_api_declaration.json @@ -251,6 +251,20 @@ "type": "string" } } + }, + "arrayOfObjects": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "age": { + "type": "integer" + } + } + } } } } diff --git a/spec/lib/swagger_v2_blocks_spec.rb b/spec/lib/swagger_v2_blocks_spec.rb index 85a6d67..dbe90ca 100644 --- a/spec/lib/swagger_v2_blocks_spec.rb +++ b/spec/lib/swagger_v2_blocks_spec.rb @@ -219,6 +219,18 @@ class PetV2 key :type, :string end end + property :arrayOfObjects do + key :type, :array + items do + key :type, :object + property :name do + key :type, :string + end + property :age do + key :type, :integer + end + end + end end end end