Skip to content

To fix the array of hash with different key in each postion of the array #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/json/schema_generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'json/schema_generator/statement_group'
require 'json/schema_generator/brute_force_required_search'

module JSON
class SchemaGenerator
DRAFT3 = 'draft-03'
Expand Down Expand Up @@ -72,7 +71,7 @@ def create_primitive(statement_group, key, value, required_keys)
raise "Unknown Primitive Type for #{key}! #{value.class}"
end

statement_group.add "\"type\": \"#{type}\""
statement_group.add "\"oneOf\": [{\"type\": \"#{type}\"}, {\"type\": \"null\"}]"
statement_group.add "\"required\": #{required}" if @version == DRAFT3
statement_group.add "\"default\": #{value.inspect}" if @defaults
end
Expand Down Expand Up @@ -128,8 +127,11 @@ def create_array(statement_group, data, required_keys)
statement_group.add '"minItems": 1'
end
statement_group.add '"uniqueItems": true'
statement_group.add create_values("items", data.first, required_keys, true)

if data.first.is_a? Hash
statement_group.add create_values("items", data.inject(:merge),required_keys, true)
else
statement_group.add create_values("items", data.first, required_keys, true)
end
statement_group
end

Expand Down