feat: add export-openapi subcommand (RFC companion) - #73
Draft
gsmith85 wants to merge 1 commit into
Draft
Conversation
gsmith85
force-pushed
the
feat/export-openapi
branch
2 times, most recently
from
September 2, 2026 21:53
db7343b to
7529723
Compare
Add `export-openapi` subcommand and library API to compile canonical UCP
JSON Schemas (Draft 2020-12) into valid, self-contained OpenAPI 3.1.0 specifications.
Key capabilities:
- Capability extension composition (`compose_extension_into_root`, `merge_extension_object`)
prior to directional slicing, seamlessly merging extensions (e.g. discounts, fulfillment)
- Directional Request & Response model slicing (`CreateRequest`, `UpdateRequest`, etc.)
- Dynamic container capability inspection (`{op}_request`/`{op}_response`) and routing
- Transitive `$ref` reachability graph calculation with canonical URL resolution for down-scoping
- Two-pass `$defs` hoisting with `<Parent><Def>` namespacing, eliminating collision race conditions
- Synthesizes polymorphic `discriminator` mappings from `allOf` + `if`/`then` conditionals
- Distributes properties across bare `anyOf` branches (e.g. `ValueConstraint`)
- Zero domain hardcoding: schema-driven `x-ucp-path` routing and `x-ucp-lifecycle` action synthesis
- Projects normative REST operations (`POST`, `GET`, `PUT`) with standard UCP headers and RFC 9421 security
- Supports declarative `x-ucp-path` overrides and RFC 8615 well-known discovery (`GET /.well-known/ucp`)
- Provides declarative `--check` mode to enforce zero drift in CI
- Public library ergonomics (`OpenApiExportOptions` alias, safe error typing, CLI exit codes)
gsmith85
force-pushed
the
feat/export-openapi
branch
from
September 2, 2026 22:35
7529723 to
8b7b27f
Compare
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.
Summary
Companion RFC: Universal-Commerce-Protocol/ucp#800
This PR introduces the
export-openapisubcommand and library API toucp-schema, providing the reference compiler implementation for the UCP Interface-Definition Strategy RFC.It compiles raw UCP JSON Schemas (Draft 2020-12) into a canonical, self-contained OpenAPI 3.1.0 specification. This provides the ecosystem with standardized client/server stubs and strongly-typed DTOs, retiring >3,500 lines of brittle AST preprocessing scripts currently maintained across language SDKs (
python-sdk,js-sdk).Core Compiler Pipeline (5 Lowering Passes)
$defsHoisting (mod.rs,normalizer.rs):components.schemaswith<Parent><Def>qualification, eliminating naming collisions while rewriting#self-refs and distributing properties into bareanyOfconstraint unions.mod.rs,normalizer.rs):discount.json,fulfillment.json) into root resources (checkout.json,cart.json).(direction, op)into explicit models (CheckoutCreateRequest,CheckoutUpdateRequest,CheckoutCompleteRequest,Checkout).CatalogLookup,CatalogSearch,Pagination) from the registry.mod.rs):oneOfunions, anddiscriminator.mappingdictionaries (e.g. updatingLocationDestinationtoLocationDestinationCreateRequest).discriminator.rs):discriminator.mappingtables from conditionalallOf+if/thenbranches.operations.rs):/checkout-sessions,/carts,/orders,/catalog) driven byx-ucp-pathandx-ucp-lifecycle.UCP-Agent,Idempotency-Key) and RFC 9421 HTTP Message Signature security schemes.Built for Zero-Maintenance Extensibility
To eliminate ongoing maintenance overhead as UCP evolves,
export-openapiis 100% schema-driven:is_container_schema,is_extension_schema,{op}_requestconventions). Adding new verticals (Lodging, Services) requires zero Rust compiler code edits."x-ucp-path"(e.g."x-ucp-path": "/checkout-sessions"), decoupling route authorship from compiler code.--profile shopping) compute transitive$refdependency closures rather than static file allowlists, ensuring new schema properties are automatically resolved.export-openapi --checkverifies byte-for-byte spec parity in GitHub Actions, preventing schema drift with zero human review overhead.Verification & Test Status
tests/export_openapi_test.rs).cargo clippy --all-targets -- -D warnings).Universal-Commerce-Protocol/ucpwith byte-for-byte identical SHA-256 (02668cd8...), zero broken$refs across 447 references, 172 component schemas, and 12 canonical REST routes.