Skip to content

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

@e-gauthier

Description

@e-gauthier

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions