Skip to content

Commit

Permalink
Merge pull request #462 from tomgi/fix_nested_array_object
Browse files Browse the repository at this point in the history
[changelog]

fixed: Fix json-schema type of objects nested under arrays. Fixes #400
  • Loading branch information
solnic authored May 22, 2024
2 parents 85a9e0b + a7cb37e commit 8f9c073
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/dry/schema/extensions/json_schema/schema_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion spec/extensions/json_schema/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: {
Expand Down

0 comments on commit 8f9c073

Please sign in to comment.