RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.38k stars 532 forks source link

Converting a Json array containing multiple types return only the first element. #1593

Closed e-gauthier closed 9 months ago

e-gauthier commented 1 year ago

Description

Passing a JSON array with multiple types to JsonSchema.FromSampleJson return only the first element of the array a JsonSchema.

Executing this line JsonSchema.FromSampleJson([1, { "a": "b"}, "value"] )

Actual result :

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "array",
  "items": {
    "type": "integer"
  }
}

Expected Result :

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "array",
  "items": {
        "anyOf": [
            {
            "type": "integer"
            },
            {
            "type": "object"
            },
            { 
            "type": "string"
            }
        ]
  }
}

The problem may be there. https://github.com/RicoSuter/NJsonSchema/blob/master/src/NJsonSchema/Generation/SampleJsonSchemaGenerator.cs#:~:text=schema.Item%20%3D%20itemSchemas.First()%3B