json-schema-generator icon indicating copy to clipboard operation
json-schema-generator copied to clipboard

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

Open dgileadi opened this issue 9 years ago • 6 comments

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.

dgileadi avatar Sep 11 '15 23:09 dgileadi

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

krg7880 avatar Sep 14 '15 17:09 krg7880

+1 : Subscribing

anil614sagar avatar Dec 21 '15 06:12 anil614sagar

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

AceMood avatar Mar 14 '18 08:03 AceMood

@krg7880 Any updates on this?

nissimlavy avatar Apr 24 '18 20:04 nissimlavy

Yes. Same problem here. Fix available ?

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

image

rsrini7 avatar Feb 23 '19 09:02 rsrini7

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

Mahandrisoa avatar Sep 22 '20 05:09 Mahandrisoa