json-schema_builder icon indicating copy to clipboard operation
json-schema_builder copied to clipboard

Avoid create empty "required" property

Open ngouy opened this issue 4 years ago • 0 comments

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"}}}

ngouy avatar May 07 '21 18:05 ngouy