Repository navigation
Standard string formats in the body schema profile (#861) - #880
Merged
Merged
Conversation
…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
enabled auto-merge (squash)
September 29, 2026 00:24
jimhoyd
added a commit
that referenced
this pull request
Sep 29, 2026
…ndard formats Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #861 item 6.
request.body.<METHOD>.schema(and MCP input schemas, which use the same profile) now acceptformat:date,time,date-time,email,uri,hostname,ipv4,ipv6, plusuuid. Any other format is still refused at load with a pointed diagnostic.Decision: core-owned checks, not
ajv-formatsajv-formats3.0.1 was ruled out for three reasons:require, which the Cloudflare build refuses.email/uriregexes repeat groups, which the pattern guard refuses.packages/core/src/body-formats.tsholds one set of functions:body-validators.jsthrough Ajv'scode.formats. The output was checked for nonew 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
maxLengthis needed beside aformat.Bounded time: every regex passes
assertSafePattern, and the rest is a linear scan.Semantics and limits are documented in HTTP.md:
xn--labels are accepted without decoding, and U-labels are refused.Evidence (macOS, Node 26)
npm run verifyandnpm run test:packagepass.test/body-schema-formats.test.ts:npm run test:workerdwith Wrangler 4.143.0: 33/33 identical, including three new format cases.examples/body-validationusesemailanddate-time(27/27).Remaining gaps
uri-reference,durationandregexare still refused.🤖 Generated with Claude Code