From 5853103d6849490ae8ba94158f73631c1fd121a8 Mon Sep 17 00:00:00 2001 From: Tomasz Gieniusz Date: Tue, 20 Jun 2023 14:22:08 +1000 Subject: [PATCH 1/2] Fix type of objects nested under arrays. Fixes #400 --- .../extensions/json_schema/schema_compiler.rb | 2 +- spec/extensions/json_schema/schema_spec.rb | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/dry/schema/extensions/json_schema/schema_compiler.rb b/lib/dry/schema/extensions/json_schema/schema_compiler.rb index 55812be7..275cbbb5 100644 --- a/lib/dry/schema/extensions/json_schema/schema_compiler.rb +++ b/lib/dry/schema/extensions/json_schema/schema_compiler.rb @@ -90,7 +90,7 @@ def visit(node, opts = EMPTY_HASH) def visit_set(node, opts = EMPTY_HASH) target = (key = opts[:key]) ? self.class.new(loose: loose?) : self - node.map { |child| target.visit(child, opts) } + node.map { |child| target.visit(child, opts.except(:member)) } return unless key diff --git a/spec/extensions/json_schema/schema_spec.rb b/spec/extensions/json_schema/schema_spec.rb index b717631a..66f0b9f8 100644 --- a/spec/extensions/json_schema/schema_spec.rb +++ b/spec/extensions/json_schema/schema_spec.rb @@ -27,6 +27,10 @@ required(:roles).array(:hash) do required(:name).value(:string, min_size?: 12, max_size?: 36) + + required(:metadata).hash do + required(:assigned_at).value(:time) + end end optional(:address).hash do @@ -59,9 +63,19 @@ type: "string", minLength: 12, maxLength: 36 + }, + metadata: { + type: "object", + properties: { + assigned_at: { + format: "time", + type: "string", + }, + }, + required: %w[assigned_at] } }, - required: ["name"] + required: %w[name metadata] } }, address: { From a7cb37e7f66e4ff95faa31ea4374b08996131325 Mon Sep 17 00:00:00 2001 From: Tomasz Gieniusz Date: Tue, 20 Jun 2023 15:01:42 +1000 Subject: [PATCH 2/2] :cop: --- spec/extensions/json_schema/schema_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/extensions/json_schema/schema_spec.rb b/spec/extensions/json_schema/schema_spec.rb index 66f0b9f8..c766aba6 100644 --- a/spec/extensions/json_schema/schema_spec.rb +++ b/spec/extensions/json_schema/schema_spec.rb @@ -69,8 +69,8 @@ properties: { assigned_at: { format: "time", - type: "string", - }, + type: "string" + } }, required: %w[assigned_at] }