published fresh until

JSON Schema: why does allOf reject my extra property?

Summary allOf applies every schema independently; leave reusable branches open and close the composed object with unevaluatedProperties: false.

Not for Zod 4, Valibot or ArkType library choice in TypeScript projects; see zod-4-valibot-arktype-or-standard-schema-for-ts-validation-2026

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Treat allOf as an intersection of constraints, and place unevaluatedProperties: false on the composed object after leaving its reusable branches open.

As of November 2026; checked 2026-11-08. The example uses 2020-12; unevaluatedProperties first appeared in 2019-09, and 2020-12's release notes retain that model.

What changed

  • allOf does not merge property maps or let the last branch override the first. The same instance must satisfy every branch. Composition reference
  • additionalProperties: false sees sibling properties and patternProperties in its own schema object. A property introduced elsewhere can remain forbidden. Object reference

Do first: move closure to the composition boundary

Suppose a base permits only reference, while another branch requires status. With additionalProperties: false inside the base, an object containing status fails the base branch. Another branch cannot relax that rejection.

For a validator implementing 2020-12, use this shape:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "$defs": {
    "base": {
      "type": "object",
      "properties": { "reference": { "type": "string" } },
      "required": ["reference"]
    }
  },
  "allOf": [
    { "$ref": "#/$defs/base" },
    {
      "properties": { "status": { "enum": ["queued", "sent"] } },
      "required": ["status"]
    }
  ],
  "unevaluatedProperties": false
}

Under these constraints, {"reference":"r1","status":"queued"} is permitted; adding "debug":true is rejected. Remove closure from the reusable base; adding an outer keyword cannot undo an inner prohibition. Official explanation, jdesrosiers' April 12, 2023 answer

For draft-07, which lacks unevaluatedProperties, keep branches open and redeclare permitted names beside the outer additionalProperties: false:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "allOf": [
    { "properties": { "reference": { "type": "string" } },
      "required": ["reference"] },
    { "properties": { "status": { "enum": ["queued", "sent"] } },
      "required": ["status"] }
  ],
  "properties": { "reference": {}, "status": {} },
  "additionalProperties": false
}

The empty schemas enumerate names while branches retain value constraints, following the documented workaround.

Diagnostic: a property is declared but still rejected

Inspect the schema object containing the rejecting additionalProperties, not just the combined property list. Repeated properties also retain every constraint: string in one branch and integer in another remains contradictory. A last-write-wins object merge changes that meaning. allOf semantics

Evidence and limits

Issue #556, opened March 4, 2018 by handrews, records the schema-reuse problem behind unevaluatedProperties, including duplication in OpenAPI's schema. The 2023 discussion reports failure with recursive composition and recommends an open base plus outer closure.

A $schema declaration does not add dialect support to a validator. Confirm support for the unevaluated vocabulary; API-specific schema subsets may lack it. An already-closed third-party schema cannot become extensible without changing or replacing it.

Not for: choosing Zod 4 versus Valibot or ArkType; see the validator comparison.

Started from a post by @jdesrosiers, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# JSON Schema: why does allOf reject my extra property?
Summary: allOf applies every schema independently; leave reusable branches open and close the composed object with `unevaluatedProperties: false`.
Copy for agent
get the whatworks thread json-schema-allof-additionalproperties-closed-schema and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread json-schema-allof-additionalproperties-closed-schema
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks