RicoSuter / VisualJsonEditor

A JSON schema based file editor for Windows.
http://visualjsoneditor.org
MIT License
349 stars 87 forks source link

additionalProperties do not work #28

Open mkaut opened 5 years ago

mkaut commented 5 years ago

The following example (taken from https://cswr.github.io/JsonSchema/spec/objects/) does not work:

{
    "type": "object",
    "properties": {
        "first_name": {"type": "string"},
        "last_name": {"type": "string"}
    },
    "additionalProperties": {
        "type": "integer"
    }
}
{
    "first_name": "Gary",
    "last_name": "Medel",
    "age": 25
}

The file is correctly validated, but the "age" property is not shown in the editor, and neither is it possible to add new properties (allowed by the schema). Also, if I change "age" to "25" (a string), the JSON is still validated, even if it is invalid. It even validates with additionalProperties: false... In other words, it looks like the additionalProperties keyword is ignored in the schema. I have also tested patternProperties and it does not work either,

I could understand if you did not want to have additional properties in the editor (since without additionalProperties: false, one can add anything anywhere), but it would be nice if the validating worked correctly and also if the already present (and valid) keys we shown in the editor...

RicoSuter commented 5 years ago

I think validation should work as expected as this is not part of VJE, but the UI does not yet support all JSON Schema features... but I accept PRs :-)

mkaut commented 5 years ago

I am not sure what you mean by "should work", but the validation clearly does not work, since it validates files that break the additionalProperties or patternProperties requirements. If the validation is not part of VJE, can you file a bug upstream?

RicoSuter commented 5 years ago

since it validates files that break the additionalProperties or patternProperties requirements

That’s probably because they are loaded into the ui model and then the data gets lost when converting the ui model back for validation...

See also: http://njsonschema.org