jdorn / json-editor

JSON Schema Based Editor
MIT License
5.8k stars 1.08k forks source link

Validation schema - only defined elements #830

Closed presto41 closed 5 years ago

presto41 commented 5 years ago

Hi,

I wonder if exists any way to return error if user will try to put into json-editor not defined schema element?

For example this is some schema:

var job = {
    "title": "Job description",
    "type": "object",
    "required": ["address"],
    "properties": {
      "company": {
        "type": "string",
        "examples": [
          "ACME",
          "Dexter Industries"
        ]
      },
      "role": {
        "description": "Job title.",
        "type": "string",
        "examples": [
          "Human Resources Coordinator",
          "Software Developer"
        ],
        "default": "Software Developer"
      },
      "address": {
        "type": "string"
      },
      "salary": {
        "type": "number",
        "minimum": 120,
        "examples": [100, 110, 120]
      }
    }
  };

and now user into json-editor is writing: "asd": "asd". "asd" is not defined element of schema so I want to get a error of that.

Any ideas?

presto41 commented 5 years ago

I found the answer. I should to use "additionalProperties": false in schema 👍