krg7880 / json-schema-generator

Generates draft v4 schema from a local file or a remote JSON url.
MIT License
174 stars 53 forks source link

json-schema-generator doesn't handle arrays of primitives correctly #13

Open dgileadi opened 9 years ago

dgileadi commented 9 years ago

When given an object like:

{myArray: ['one', 'two']}

The generator creates a schema like the following:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "",
    "properties": {
        "myArray": {
            "type": "array",
            "items": {
                "required": [],
                "properties": {}
            }
        }
    },
    "required": ["myArray"],
    "type": "object"
}

The "items" should instead be something like:

"items": {
    "type": "string",
    "minLength": 1
}

The currently-generated schema breaks validators like ajv.

krg7880 commented 9 years ago

Thanks for the heads up. I'll take a look.

anil614sagar commented 8 years ago

+1 : Subscribing

AceMood commented 6 years ago

Occur the same problem. I think the priority of the problem could be p0, because mostly we use generator for output and ajv for input in a normal build process @krg7880

nissimlavy commented 6 years ago

@krg7880 Any updates on this?

rsrini7 commented 5 years ago

Yes. Same problem here. Fix available ?

But, the online version generates well. https://www.liquid-technologies.com/online-json-to-schema-converter

image

Mahandrisoa commented 4 years ago

I also faced the same issue recently by generating form from generated json schema, have you find any solution to this? thanks