krg7880 / json-schema-generator

Generates draft v4 schema from a local file or a remote JSON url.
MIT License
174 stars 53 forks source link

Required does not properly work for arrays #30

Open furstenheim opened 4 years ago

furstenheim commented 4 years ago

In an array of items in the array, required is set even if it is not true.

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

In the previous example a cannot be required since it does not exist in the third element