josdejong / jsoneditor

A web-based tool to view, edit, format, and validate JSON
http://jsoneditoronline.org
Apache License 2.0
11.63k stars 2.04k forks source link

Why is a validation of this schema not indicated? #920

Closed neilyoung closed 4 years ago

neilyoung commented 4 years ago

I'm believing to have a valid schema:

"$schema": "http://json-schema.org/draft-04/schema#",
                            "type": "object",
                            "properties": {
                                "geo_refs": {
                                    "type": "array",
                                    "items": {}
                                },
                                "loading": {
                                    "type": "object",
                                    "properties": {
                                        "enabled": {
                                            "type": "boolean"
                                        },
                                        "file_name": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "enabled",
                                        "file_name"
                                    ]
                                },
                                "recording": {
                                    "type": "object",
                                    "properties": {
                                        "enabled": {
                                            "type": "boolean"
                                        },
                                        "file_name": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "enabled",
                                        "file_name"
                                    ]
                                },
                                "saving": {
                                    "type": "object",
                                    "properties": {
                                        "enabled": {
                                            "type": "boolean"
                                        },
                                        "file_name": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "enabled",
                                        "file_name"
                                    ]
                                },
                                "reset": {
                                    "type": "boolean"
                                },
                                "position_update_rate": {
                                    "type": "integer"
                                },
                                "deliver_raw_poses": {
                                    "type": "boolean"
                                },
                                "world_reference_frame": {
                                    "type": "string",
                                    "enum": ["ned", "enu"],
                                    "default": "enu"
                                },
                                "strict_pose_checking": {
                                    "type": "boolean"
                                },
                                "start_orientation": {
                                    "type": "string"
                                }
                            },
                            "required": [
                                "geo_refs",
                                "loading",
                                "recording",
                                "saving",
                                "reset",
                                "position_update_rate",
                                "deliver_raw_poses",
                                "world_reference_frame",
                                "strict_pose_checking",
                                "start_orientation"
                            ]
                        }

If I put that into your new online tool, schema validations are indicated properly.

However, at runtime I neither get a "onValidate" callback nor violations (e.g. the enum thing) are indicated.

                        let container = document.getElementById("jsoneditor")
                        let options = {
                            "mode": "form",
                            "name": "start_configuration",
                            "statusBar": false,
                            "mainMenuBar": false,
                            "navigationBar": false,
                            "schema": config_schema,
                            onValidate: (json) => {
                                debugger
                            }
                        }
                        _configEditor.current = new JSONEditor(container, options) 

The editor is coming up, I can edit and "onHide" there is no validation problem indicated.

So the question is, why is there no error, if I e.g. enter "hallo" for "world_reference_frame"?

neilyoung commented 4 years ago

Disregard, my bad

josdejong commented 4 years ago

👍

neilyoung commented 4 years ago

Great component BTW

neilyoung commented 4 years ago

...but would be awesome, if the "readOnly" attribute would be recognized.

josdejong commented 4 years ago

Thanks Neil.

Reckoning with the readOnly attribute sounds interesting, I've created a separate issue for it: #922