Skip to content

Pointed body schema diagnostics for contradictory schemas and Ajv refusals (#861) - #871

Merged
jimhoyd merged 1 commit into
mainfrom
claude/body-schema-diagnostics
Sep 28, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
claude/body-schema-diagnostics

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Fixes #861 item 8. Ajv strict-mode refusals no longer surface as a truncated generic message. Every refusal is now a profile diagnostic, Body schema <pointer>: <problem>, with a hint.

Behaviour change: stricter

With the current Ajv options, Ajv itself refused only the properties/patternProperties overlap. The other conditions below used to compile silently even though no request could satisfy them, or the keyword could never apply. They are now refused at load:

  1. A properties name that a patternProperties pattern on the same schema also matches (this replaces the raw Ajv message).
  2. A required name forbidden by additionalProperties: false, so no object could ever pass.
  3. A type-specific keyword beside a type it cannot apply to, such as minLength on number.
  4. A const value or an enum entry not of the declared type. The value is never echoed.
  5. items: false with a minItems larger than prefixItems allows.

Ordinary JSON Schema still compiles: keywords with no type, open tuples, and required without additionalProperties: false.

Any remaining Ajv compile error goes through bodySchemaRefusal:

  • The pointer comes from Ajv's own error location, then from a path in its message, else /.
  • An unresolvable $ref gets a fixed message.
  • Quoted text, URLs and # references are removed, control characters are replaced, and the text is capped at 160 characters.

Evidence (macOS, Node 26)

  • npm test: 1128/1128.
  • npm run verify and npm run test:package pass.
  • Eight new refused fixtures. assertBodySchema and compileBodySchema must give identical messages for each.
  • The overlap refusal is checked on Node and in the Cloudflare build.
  • Real Ajv refusals are tested for redaction, including a $ref URL with credentials.
  • workerd was not run for this change.
  • The core unpacked size budget goes from 3460 to 3470 KiB (measured 3,543,842 bytes).

Docs: docs/HTTP.md profile section and RIM-BODY-SCHEMA-001.

🤖 Generated with Claude Code

…als (#861)

Item 8 of #861: a schema the profile admitted but Ajv strict mode refused
surfaced as a truncated "refused by the JSON Schema 2020-12 validator"
message with no pointer.

The profile walk now refuses, with a JSON pointer and a hint, profile
keywords combined into a mistake:
- a properties name also matched by a patternProperties pattern (the one
  strict-mode refusal reachable under the current Ajv options);
- a required name that additionalProperties: false forbids;
- a type-specific keyword beside a type it cannot apply to;
- a const value or enum entry outside the declared type (never echoed);
- items: false with minItems past prefixItems.

Anything Ajv still refuses goes through bodySchemaRefusal: the pointer
comes from Ajv's meta-schema instancePath or its message path (else the
root), and its wording is redacted (quoted text, URLs and # references
elided, control characters replaced, length capped). An unresolvable $ref
is never echoed.

The core package's unpacked budget rises from 3460 to 3470 KiB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 28, 2026 23:25
@jimhoyd
jimhoyd merged commit ae3d4ea into main Sep 28, 2026
29 checks passed
@jimhoyd
jimhoyd deleted the claude/body-schema-diagnostics branch September 28, 2026 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON Schema profile follow-ups: store/forms vocabularies, OpenAPI export, shared HTTP+MCP+form schema, formats, workerd CI

1 participant