0
votes

I get an "Additional properties are not allowed" error on each and every key in the JSON item. Below is the schema and item.

Schema:

    {
      "additionalProperties": false,
      "category": {
        "admin": {"type": "boolean"}
      },
      "username": {"type": "string"},
      "password": {"type": "string"},
      "name": {"type": "string"},
      "email": {"type": "string", "format": "email"},
      "phone": {"type": "string"},
      "hours": {
        "type": "array",
        "items": {
          "start": {"type": "string", "format": "date-time"},
          "end": {"type": "string", "format": "date-time"}
        }
      }
    }

Item:

    {
        "username": "emanb29",
        "password": "$2a$10$THISISAPASSWORDHASH",
        "name": "Ethan Bell",
        "email": "[email protected]",
        "phone": "5555555555",
        "hours": [
            {
                "start": "1998-05-29T04:00:00Z",
                "end": "1999-05-29T04:00:00Z"
            },
            {
                "start": "2001-05-29T10:20:00Z",
                "end": "2001-05-29T22:20:00Z"
            }
        ],
        "category": {
            "admin": true
        }
    }
1
What are you using to validate this?user1864610
jsonschemalint.com for testing, but the plan is to use the npm jsonschema package in a node.js implementation (npmjs.org/package/jsonschema)emanb29

1 Answers

2
votes

Your schema seems suspect. Working from the samples on jsonschemalint.com I created a properties container in the root for your properties, added description and type at the root and moved additionalProperties to the root as well.

This validates your item on jsonschemalint.com:

{
    "description": "StackOverflow test schema", 
    "type": "object", 
    "additionalProperties": false,
    "properties":     {
      "category": {
        "admin": {"type": "boolean"}
      },
      "username": {"type": "string"},
      "password": {"type": "string"},
      "name": {"type": "string"},
      "email": {"type": "string", "format": "email"},
      "phone": {"type": "string"},
      "hours": {
        "type": "array",
        "items": {
          "start": {"type": "string", "format": "date-time"},
          "end": {"type": "string", "format": "date-time"}
        }
      }
    }
}