Skip to content

Standard string formats in the body schema profile (#861) - #880

Merged
jimhoyd merged 1 commit into
mainfrom
claude/body-schema-formats
Sep 29, 2026
Merged

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

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Fixes #861 item 6. request.body.<METHOD>.schema (and MCP input schemas, which use the same profile) now accept format: date, time, date-time, email, uri, hostname, ipv4, ipv6, plus uuid. Any other format is still refused at load with a pointed diagnostic.

Decision: core-owned checks, not ajv-formats

ajv-formats 3.0.1 was ruled out for three reasons:

  • Its documented standalone setup reaches the formats through require, which the Cloudflare build refuses.
  • Its email/uri regexes repeat groups, which the pattern guard refuses.
  • It would add a dependency.

packages/core/src/body-formats.ts holds one set of functions:

  • Node registers them with Ajv.
  • The Cloudflare build pastes the same function source into body-validators.js through Ajv's code.formats. The output was checked for no new Function, eval, require or import.

Implied length caps: uuid 36, date 10, time 24, date-time 35, email 254, uri 2048, hostname 253, ipv4 15, ipv6 45. Longer values fail before any regex runs, so no maxLength is needed beside a format.
Bounded time: every regex passes assertSafePattern, and the rest is a linear scan.

Semantics and limits are documented in HTTP.md:

  • Dates and times: RFC 3339 with a required offset. A leap second is accepted only at 23:59 UTC and is not checked against the leap-second table.
  • email: ASCII only.
  • uri: absolute URIs only.
  • hostname: xn-- labels are accepted without decoding, and U-labels are refused.
  • ipv6: no zone id.

Evidence (macOS, Node 26)

Remaining gaps

  • IDN formats, uri-reference, duration and regex are still refused.
  • Punycode is not decoded.
  • 5-digit ports above 65535 pass.
  • Parameter formats are uuid-only.

🤖 Generated with Claude Code

…item 6)

`request.body.<METHOD>.schema` (and every consumer of the profile, such as MCP
input schemas) now accepts `format` date, time, date-time, email, uri,
hostname, ipv4 and ipv6 beside uuid. Any other format is still refused at load,
naming the supported list.

The checks are core-owned (packages/core/src/body-formats.ts), not
ajv-formats: no new dependency, no `require` in the Cloudflare standalone
output, and bounded cost. Each format refuses a value over its published
length cap before any regex runs, every regex it uses passes the pattern
admission guard, and the rest is a linear scan, so no maxLength is needed
beside a format. Node registers the functions with Ajv; the Cloudflare build
inlines the same self-contained function into body-validators.js through
Ajv's code.formats, keeping the Worker eval-free and import-free.

Tests: per-format accepted/refused values (leap years, leap seconds and
offsets, quoted local parts and address literals, xn-- labels, IPv6
compression and IPv4 tails), caps, guard admission of every regex, timing on
4 KB pathological inputs, and a formats fixture run on Node and through the
Cloudflare build. workerd parity gains three format cases (33/33 identical).
Docs: HTTP.md format table and decision, RIM-BODY-SCHEMA-001, capability
text, schema description and regenerated references. Core package budget
raised to 875/3490 KiB (measured 893513 / 3561513 bytes).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 29, 2026 00:24
@jimhoyd
jimhoyd merged commit 29c5302 into main Sep 29, 2026
30 checks passed
@jimhoyd
jimhoyd deleted the claude/body-schema-formats branch September 29, 2026 00:30
jimhoyd added a commit that referenced this pull request Sep 29, 2026
jimhoyd added a commit that referenced this pull request Sep 29, 2026
) (#879)

* feat(core): urlcode openapi exports an OpenAPI 3.1 document (#845, #861)

`urlcode openapi [--project] [--origin] [--out] [--host-file] [--policy]`,
MCP `get_openapi` and the SDK's `buildOpenApi` return one document from the
compiled configuration: one operation per declared method, the route's
parameters, each method's request.body policy as its requestBody (the 2020-12
schema as written; local $defs hoisted to components with their $refs
rewritten), and only responses URLCode itself writes or the YAML fixes
(redirect status + Location, respond values, asset statuses, 400/413/415/422
in the route's error format, enforced throttle/agents refusals, the auth
extension's 401/403). Handler-defined answers are a `default` response with
no schema. Extension, static and /** mounts are listed under
x-urlcode.opaqueMounts, never enumerated. Bindings, egress/redirect targets,
module paths, operator policy and cookie names are never emitted; auth: true
uses a generic cookie scheme with a placeholder name.

test/openapi.test.ts validates the output against the vendored official
OAS 3.1 schema (2025-09-15) plus the 2020-12 meta-schema for every Schema
Object, generates a client with @hey-api/openapi-ts (new devDependency,
js-yaml overridden to 4.3.2 for its advisories) that typechecks and calls
examples/body-validation, and runs a contract pass of derived requests
against that example. Core package budget raised to 880 KiB packed /
3500 KiB unpacked (measured 897639 / 3572415).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(openapi): follow #880's format: email in the example; sample standard formats

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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