nijikokun / generate-schema

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

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

Open i-break-codes opened 5 years ago

i-break-codes commented 5 years ago

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