thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

JSON schema negation

β€’ 107 words β€’ 1 min β€’ updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

JSON Schema is a powerful validation tool to enforce a given structure and/or data type in JSON and YAML files.

Problem statement: Disallow aws.iam_role1, with the implicit goal of allowing aws.iamRole. Because naming and sticking to conventions is hard.

Illustration:

yaml
aws:
  iamRole: fooArn
  iam_role: barArn  # <-- disallow

We can accomplish this with the following schema (% cat values.schema.json):

json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Schema that disallows aws.iam_role",
  "type": "object",
  "additionalProperties": true,
  "properties": {
    "aws": {
      "type": "object",
      "additionalProperties": true,
      "not": {
        "required": ["iam_role"]
      }
    }
  }
}

Test: helm lint should fail that schema validation with the aforementioned input.


  1. This is for a helm chart↩︎