Skip to content

Export an OpenAPI 3.1 description of the project's HTTP operations (#845) - #879

Merged
jimhoyd merged 3 commits into
mainfrom
claude/openapi-export
Sep 29, 2026
Merged

jimhoyd merged 3 commits into
mainfrom
claude/openapi-export

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Covers #845's acceptance that "OpenAPI output validates with an independent standard tool, supports a generated client and one contract-testing run", and #861 item 2.

What it does

urlcode openapi [--project] [--origin] [--out] [--host-file] [--policy], MCP get_openapi, and the SDK functions buildOpenApi/renderOpenApi all go through one function in packages/core/src/openapi.ts. The document is built from the compiled configuration: nothing executes, no binding is read, and the output is deterministic.

  • Header: openapi: 3.1.1, with jsonSchemaDialect set to 2020-12.
  • Operations: one per declared method, HEAD included. Parameters are carried over as written.
  • Request bodies: each method's request.body.<METHOD> becomes that operation's requestBody. The author's 2020-12 schema goes into components.schemas, and each $defs entry is lifted into its own component so its $ref resolves.
  • Responses: only what URLCode knows: redirects with Location, a respond body as a const schema, page/download statuses, conditional branches, the runtime's own 400/413/415/422 in the route's error format, and throttle 429 or agents 403.
  • Unknown answers: function, proxy, middleware and extension answers get a default response with a description and no invented schema.
  • Opaque mounts: extension, static and /** mounts are listed in x-urlcode.opaqueMounts and never enumerated. A store OpenAPI contribution is scoped out: its vocabulary is still private (JSON Schema profile follow-ups: store/forms vocabularies, OpenAPI export, shared HTTP+MCP+form schema, formats, workerd CI #861 item 1), and its full surface wasn't small.
  • Auth: auth: true gets a generic cookie security scheme, urlcodeSession, with a placeholder cookie name.
  • Never emitted: env or secret names and values, proxy, signal and redirect targets, module paths, operator policy, extension config.
  • x-urlcode: runtime version, revision, handler kind, execution mode, middleware count, error format and target support.

Validation evidence (test/openapi.test.ts)

  • Standard validator: the output validates against the official OAS 3.1 schema (2025-09-15), vendored with its source and Apache-2.0 license, using Ajv 2020. Every Schema Object is also checked against the 2020-12 meta-schema.
    • One workaround: Ajv mis-scopes the schema file's $dynamicRef: "#meta", so the test rewrites it to the equivalent static $ref. Formats are not checked.
  • Generated client: new devDependency @hey-api/[email protected] (openapi-typescript needs TypeScript 5; this repo is on 6).
    • The test generates a fetch client offline, typechecks it, including a @ts-expect-error proving the schema's required reached the types, and runs it against the served examples/body-validation: 201, 422 /title, 201, 200.
    • An overrides entry pins js-yaml to 4.3.2 over the vulnerable 4.2.0 it pulled in. npm audit reports 0 vulnerabilities.
  • Contract run: each operation gets a valid request plus each declared refusal (400, 413, 415, 422). The status, media type and schema of every answer are checked against the document.
  • Leaks: a synthetic project asserts that no operator names appear in the output.
  • Agreement: the CLI stdout, --out and MCP return identical documents.
  • npm run verify and npm run test:package pass.
  • The core size budget is raised; it may need re-measuring against whichever of Stage shadcn registry items and Agent Skills as data; opt-in materialization (#844) #878 and this PR merges second.

Gaps (filed)

  • Response schemas for function routes.
  • Store and extension contributions to the document.
  • The runtime's automatic 405 and always-present headers are not described.
  • Auth 401/403 are listed for every method.
  • site.errors scopes are matched by pattern.
  • The contract run covers only one example.

🤖 Generated with Claude Code

`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]>
@jimhoyd
jimhoyd merged commit 500a06b into main Sep 29, 2026
29 checks passed
@jimhoyd
jimhoyd deleted the claude/openapi-export branch September 29, 2026 00:45
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.

1 participant