Disallowing Undefined Properties

Without preventing it, JSON schemas for an Object Type in Contextual allow for the creation and storage of Recordsarrow-up-right that include properties and values that are not explicitly defined in the schema. To prevent this from happening, include additionalProperties: false in your schema, as shown in this example:

Data Schema Example
{
  "primaryKey": "orderNumber",
  "type": "object",
  "properties": {
    "orderNumber": {
      "type": "number",
      "minLength": 3
    },
    "customerName": {
      "type": "string",
      "minLength": 1
    },
    "beverage": {
      "type": "string",
      "enum": [
        "coffee",
        "tea",
        "juice",
        "soda"
      ]
    },
    "food": {
      "type": "string",
      "enum": [
        "bagel",
        "donut",
        "pastry",
        "muffin"
      ]
    }
  },
  "required": [
    "orderNumber", 
    "customerName"
  ],
  "additionalProperties: false
}

Last updated

Was this helpful?