Skip to content

A resolved value is validated against the parameter schema, null included

The rule

Normative: this is the rule
  1. A resolved value MUST be validated against the parameter's schema as JSON Schema validates an instance, a null included.
  2. A null therefore MUST fail type unless the type admits null, and MUST fail enum unless the enumeration lists null.
  3. Constraints that apply only to strings, numbers, arrays or objects do not apply to a null, as in JSON Schema.
  4. Every resolved value MUST be validated, and any violation MUST fail the node execution with a validation error.
  5. The error MUST name every parameter whose value failed and, for each, every constraint that failed, in no defined order.
  6. For each value, type and enum MUST be checked first, and either one failing MUST end the check of that value there, so that it is the only constraint named for that parameter.
  7. A parameter absent from the resolved parameter set has no value, and is not validated.

What it means

A resolved value is validated exactly as a JSON Schema validator would validate it, and a null is no exception. null is a type of its own: it passes "type": "string" no more than a number would, and it passes only a schema whose type admits it, such as ["string", "null"]. A parameter that is meant to accept "nothing chosen" says so in its schema.

What a null is spared is only what JSON Schema spares it: a minimum length, a pattern or a format describe strings, so they have nothing to say about a null. enum is different: a null passes it only where the enumeration lists null.

Every value is checked, and a failure names all of them: each parameter whose value failed, with each constraint it failed, in no particular order. An author sees every problem at once, and the answer is the same in every language and whatever order the parameters were declared in. Only type and enum cut a value's check short, because the other constraints mean little for a value of the wrong type or outside the list.

A parameter that nothing supplied at all is not validated here. It has no value, and CFG-9 has already decided whether that is allowed.

Example

A schema that admits null, with an enum that lists it
{ "type": ["string", "null"], "enum": ["low", "high", null], "minLength": 3 }
What resolving an explicit null against it returnsvalid
null

The same null against { "type": "string" } fails the node with a type violation.

Why

Recorded under OPEN-25, OPEN-26, OPEN-42.

Fixtures

Test cases whose outcome this rule decides. A case compares absent, null and empty members exactly; the fixtures README defines each operation. Where a case and the rule disagree, the rule is right.

  • A null fails an enumeration that does not list it resolve-parameters
    {
      "given": {
        "parameters": {
          "x": {
            "schema": {
              "type": [
                "string",
                "null"
              ],
              "enum": [
                "a",
                "b"
              ]
            },
            "connectable": true,
            "exposed": true,
            "configurable": true
          }
        },
        "config": {
          "x": null
        }
      },
      "expect": {
        "failed": {
          "error": "validation",
          "constraints": {
            "x": [
              "enum"
            ]
          }
        }
      }
    }

    fixtures/presence/cfg-null-not-in-enum.json

  • A null is not held to string-only constraints resolve-parameters
    {
      "given": {
        "parameters": {
          "x": {
            "schema": {
              "type": [
                "string",
                "null"
              ],
              "minLength": 3,
              "pattern": "^[a-z]+$"
            },
            "connectable": true,
            "exposed": true,
            "configurable": true
          }
        },
        "config": {
          "x": null
        }
      },
      "expect": {
        "resolved": {
          "x": null
        }
      }
    }

    fixtures/presence/cfg-null-skips-string-bounds.json

  • An optional null is validated too resolve-parameters

    Optional means the parameter may be absent, not that a null skips its type.

    {
      "given": {
        "parameters": {
          "x": {
            "schema": {
              "type": "string"
            },
            "connectable": true,
            "exposed": true,
            "configurable": true
          }
        },
        "config": {
          "x": null
        }
      },
      "expect": {
        "failed": {
          "error": "validation",
          "constraints": {
            "x": [
              "type"
            ]
          }
        }
      }
    }

    fixtures/presence/cfg-optional-null-wrong-type.json

  • A null meets required, and passes where the type admits null resolve-parameters
    {
      "given": {
        "parameters": {
          "x": {
            "schema": {
              "type": [
                "string",
                "null"
              ]
            },
            "required": true,
            "connectable": true,
            "exposed": true,
            "configurable": true
          }
        },
        "config": {
          "x": null
        }
      },
      "expect": {
        "resolved": {
          "x": null
        }
      }
    }

    fixtures/presence/cfg-required-null-admitted.json

  • A null meets required, then fails a type that does not admit it resolve-parameters
    {
      "given": {
        "parameters": {
          "x": {
            "schema": {
              "type": "string"
            },
            "required": true,
            "connectable": true,
            "exposed": true,
            "configurable": true
          }
        },
        "config": {
          "x": null
        }
      },
      "expect": {
        "failed": {
          "error": "validation",
          "constraints": {
            "x": [
              "type"
            ]
          }
        }
      }
    }

    fixtures/presence/cfg-required-null-wrong-type.json

  • Every failing parameter and every failing constraint is named resolve-parameters

    y fails type, which ends its check, so minimum is not named for it.

    {
      "given": {
        "parameters": {
          "x": {
            "schema": {
              "type": "string",
              "pattern": "^a",
              "minLength": 5,
              "maxLength": 1
            },
            "connectable": true,
            "exposed": true,
            "configurable": true
          },
          "y": {
            "schema": {
              "type": "number",
              "minimum": 10
            },
            "connectable": true,
            "exposed": true,
            "configurable": true
          }
        },
        "config": {
          "x": "bb",
          "y": "text"
        }
      },
      "expect": {
        "failed": {
          "error": "validation",
          "constraints": {
            "x": [
              "maxLength",
              "minLength",
              "pattern"
            ],
            "y": [
              "type"
            ]
          }
        }
      }
    }

    fixtures/presence/cfg-validation-names-every-failure.json

Rule identifiers are permanent and are never renumbered. Each implementation publishes its own standing against these rules; this specification does not.spec 1.0 · CFG-10 · changed in spec 1.0