json-schema_builder
json-schema_builder copied to clipboard
Avoid create empty "required" property
When you have an object and you force required: false on at least one attribute, but none are required : true, it will still creates a "required" property with an empty array
schema = object do
string :my_key, required: false
string :my_other_key, required: true
end.as_json
# => {"type"=>"object", "required"=>["my_other_key"], "properties"=>{"my_key"=> {"type"=>"string"}, "my_other_key"=>{"type"=>"string"}}}
schema = object do
string :my_key
string :my_other_key
end.as_json
# => {"type"=>"object", "properties"=>{"my_key"=>{"type"=>"string"}, "my_other_key"=>{"type"=>"string"}}}
schema = object do
string :my_key
string :my_other_key, required: false
end.as_json
# => {"type"=>"object", "required"=>[], "properties"=>{"my_key"=>{"type"=>"string"}, "my_other_key"=>{"type"=>"string"}}}