72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/genny/json_schema.rb', line 72
def self.genny(opts = {})
opts = Genny.symbolize(opts)
opts[:additional_properties_n] ||= 3
raise "additional_properties_n must be an integer" unless opts[:additional_properties_n] >= 0
opts[:properties] ||= {}
if opts[:additionalProperties].is_a?(::Hash)
(opts[:additional_properties_n] * @@additional_properties).round.times do |i|
opts[:properties]["gennyAdditionalProperty#{i + 1}"] ||= opts[:additionalProperties]
end
end
::Hash[opts[:properties].map { |key, schema_object|
next nil if !(opts[:required] || []).include?(key) && Random.rand > @@additional_properties
[
key,
JSONSchema.new(
schema_object.merge(
hint: [key, opts[:hint]].compact.join(" ")
),
definitions: opts[:definitions],
validate: false
).genny
]
}.compact]
end
|