nijikokun / generate-schema

🧞 Convert JSON Objects to MySQL, JSON Schema, Mongoose, Google BigQuery, Swagger, and more.
MIT License
1.04k stars 135 forks source link

Required field not properly set #53

Open furstenheim opened 4 years ago

furstenheim commented 4 years ago

Required is wrongly set for arrays of items

> var generator = require('generate-schema')
> generator.json([{a: 1, b: 2}, {a: 2, b: 3}, {b: 5}])
{
  '$schema': 'http://json-schema.org/draft-04/schema#',
  type: 'array',
  items: {
    type: 'object',
    properties: { a: [Object], b: [Object] },
    required: [ 'a', 'b' ]
  }
}

a cannot be required since it is not in the last item. It might be related to https://github.com/nijikokun/generate-schema/issues/32

Thanks