Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
e-gauthier opened this issue May 3, 2023 · 0 comments · May be fixed by #1632
Closed

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

e-gauthier opened this issue May 3, 2023 · 0 comments · May be fixed by #1632

Comments

@e-gauthier
Copy link

e-gauthier commented May 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants