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

Nested array with incomplete objects leads to type being lost #22

Closed
coli opened this issue Jan 26, 2017 · 2 comments
Closed

Nested array with incomplete objects leads to type being lost #22

coli opened this issue Jan 26, 2017 · 2 comments

Comments

@coli
Copy link

coli commented Jan 26, 2017

If an array contains a empty or partial object, the type inferred is lost. Example:

require("generate-schema").json(
{array:[
    {"a2":[{something:""}]},
    {"a2":[]},
]})

The object inside a2 array should have the "something" field. But the result is now

{"a2":{"type":"array","items":{}}}

vs

require("generate-schema").json(
{array:[
    {"a2":[{something:""}]}
]})

which correctly infers

{"a2":{"type":"array","items":{"type":"object","properties":{"something":{"type":"string"}}}}}

The current code handles non nested array nicely though.

require("generate-schema").json(
{array:[
    {"a2":[{something:""}]},
    {}

]})

generates

{"a2":{"type":"array","items":{"type":"object","properties":{"something":{"type":"string"}}}
@coli coli changed the title Nested array is not handled well Array with incomplete objects leads to type being lost Jan 26, 2017
@coli coli changed the title Array with incomplete objects leads to type being lost Nested array with incomplete objects leads to type being lost Jan 26, 2017
@nijikokun
Copy link
Owner

Great catch, added fix for this, and a fix for different types in the nested array. This also handles mixed objects & types properly as well now

@nijikokun
Copy link
Owner

Released in v2.4.0

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

No branches or pull requests

2 participants