generate-schema icon indicating copy to clipboard operation
generate-schema copied to clipboard

[Issue] Nested object under an array returns wrong number of items

Open i-break-codes opened this issue 6 years ago • 0 comments

Basic Object

const sampleObj = {
  randomnumber: 2,
  arr: [
    1, 
    2,
    "hello"
  ]
};

console.log(JSON.stringify(GenerateSchema.json(sampleObj), null, 2));

Above returns wrong validation for the array, I have 3 items in the array and it returns 4... am I missing something obvious here?

Output of the above:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "randomnumber": {
      "type": "number"
    },
    "arr": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "number"
          },
          {
            "type": "number"
          },
          {
            "type": "number"
          },
          {
            "type": "string"
          }
        ]
      }
    }
  }
}

Thanks

i-break-codes avatar Dec 23 '18 15:12 i-break-codes