brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
606 stars 168 forks source link

Nested json rendering #128

Open ctippur opened 6 years ago

ctippur commented 6 years ago

I have a dynamically generated nested json that needs to be rendered as form. For certain edge cases, I get an error:

jsonform.js:3170 Uncaught Error: The JSONForm contains an element that links to an element in the JSON schema (key: "statements") and that should not based on its type ("none")

I have checked the code and I seem to have followed the convention. Wondering what could be wrong.

{
    "statement_ids": {
        "items": {
            "title": "items",
            "type": "string"
        },
        "title": "statement_ids",
        "type": "array"
    },
    "statements": {
        "items": {
            "properties": {
                "Action": {
                    "anyOf": [{
                        "type": "string"
                    }, {
                        "type": "array"
                    }],
                    "title": "Action",
                    "type": "string"
                },
                "Condition": {
                    "title": "Condition",
                    "type": "object"
                },
                "Effect": {
                    "enum": ["Allow", "Deny"],
                    "title": "Effect",
                    "type": "string"
                },
                "NotAction": {
                    "anyOf": [{
                        "type": "string"
                    }, {
                        "type": "array"
                    }],
                    "title": "NotAction",
                    "type": "string"
                },
                "NotPrincipal": {
                    "anyOf": [{
                        "type": "object"
                    }, {
                        "type": "array"
                    }],
                    "title": "NotPrincipal",
                    "type": "string"
                },
                "NotResource": {
                    "anyOf": [{
                        "type": "string"
                    }, {
                        "type": "array"
                    }],
                    "title": "NotResource",
                    "type": "string"
                },
                "Principal": {
                    "anyOf": [{
                        "type": "string"
                    }, {
                        "type": "object"
                    }, {
                        "type": "array"
                    }],
                    "title": "Principal",
                    "type": "string"
                },
                "Resource": {
                    "anyOf": [{
                        "type": "string"
                    }, {
                        "type": "array"
                    }],
                    "title": "Resource",
                    "type": "string"
                },
                "Sid": {
                    "title": "Sid",
                    "type": "string"
                },
                "title": "properties",
                "type": "string"
            },
            "required": ["Effect"],
            "title": "items",
            "type": "object"
        },
        "title": "statements",
        "type": "array"
    },
    "type": {
        "enum": ["has-statement"],
        "title": "type",
        "type": "string"
    }
}

I would also like to propose a enhancement to include anyOf types for validation.