Skip to content

feat(codegen): add capability reachability, composition, and generate_types() API - #83

Open
gsmith85 wants to merge 8 commits into
feat/codegen-slicingfrom
feat/codegen-compile-types
Open

gsmith85 wants to merge 8 commits into
feat/codegen-slicingfrom
feat/codegen-compile-types

Conversation

@gsmith85

@gsmith85 gsmith85 commented Oct 1, 2026 •

Copy link
Copy Markdown

Summary

Implements Task 3 (PR 1c) of the two-layer ucp-schema code-generation pipeline: capability/extension reachability discovery, $defs hoisting & collision qualification, extension composition, and the public compile_types() / generate_types() library API.

Pipeline Stages Added

  • Stage 1 (src/codegen/reachability.rs):
    • Discovers all .json schemas in --schema-dir using schema structure (name/version capability identity, extends metadata, ucp_request/ucp_response directional annotations, and $defs reverse-domain parent inference), supports short-name (checkout) and reverse-domain (dev.ucp.shopping.checkout) matching, reclassifies extension schemas passed via --capability, seeds ambient protocol roots (profile, ucp, capability, service, payment_handler, error_response), and computes the transitive $ref closure while pruning inactive extension $defs.
  • Stage 2 (src/codegen/hoist.rs):
    • Classifies and hoists $defs entries into the top-level $defs bundle, skips pure re-exports, extracts self-named capability role schemas (*PlatformSchema, *BusinessSchema, *ResponseSchema), and parent-qualifies colliding local $defs (PaymentAp2MandateErrorCode, JsonrpcErrorResponse, A2aMessageMessage).
  • Stage 3 (src/codegen/compose.rs):
    • Composes active extensions into root capabilities (resolving root definitions via schema structure or self-named definitions), in-place standalone sub-type overlays (Buyer, Payment, PaymentInstrument, Cart -> Checkout), and container capability operations (CatalogSearch*, CatalogLookup*, supporting both nested $defs and oneOf/allOf extension shapes).
  • Stages 5, 6, 8 & Public API (src/codegen/mod.rs, src/lib.rs):
    • Orchestrates directional slicing, $ref alignment, and empty-object pruning (retaining ErrorResponse and definitions referenced via $ref anywhere in $defs or root properties), and exposes GenerateTypesOptions, TypesBundleDoc, CompiledTypes, CodegenError, compile_types(), and generate_types().

Stacked PR Series Roadmap

  1. PR 1a (feat(codegen): add identifier naming, UCP keyword stripping, and $defs ref rewriting #81): Identifier qualification, UCP keyword stripping, $ref rewriting (src/codegen/normalizer.rs)
  2. PR 1b (feat(codegen): add directional schema slicing and $ref alignment #82): Directional schema slicing & $ref alignment (src/codegen/normalizer.rs)
  3. PR 1c (this PR): Capability/extension reachability, composition & generate_types() library API (src/codegen/{mod,reachability,hoist,compose}.rs)
  4. PR 1d (feat(cli): add generate-types subcommand #84): CLI generate-types subcommand (src/bin/ucp-schema.rs, tests/generate_types_test.rs)
  5. PR 2 (feat(codegen): add self-contained .well-known/ucp profile scoping for generate-types #85): Self-contained .well-known/ucp --profile scoping (src/codegen/profile.rs)
  6. PR 3a (feat(codegen): add AST shape normalizers and inline conditional variant hoisting #86): Codegen AST shape normalizers & inline conditional variant hoisting (src/codegen/normalizer.rs, src/codegen/reify.rs)
  7. PR 3b (feat(codegen): lower open string discriminator unions into ordered anyOf with <Union>Base #87): Open string discriminator union lowering (<Union>Base) (src/codegen/reify.rs)
  8. PR 3c (feat(codegen): discover and register decentralized extended subtypes into open unions #88): Cross-file extended subtype discovery & registration (src/codegen/reify.rs)
  9. PR 4a (python-sdk#101): Python SDK direct JSON Schema codegen (generate_models.sh, postprocess_models.py, src/ucp_sdk/models/)
  10. PR 4b (js-sdk#87): JS/TS SDK direct JSON Schema codegen (generate_models.sh, scripts/generate-zod-from-types.mjs, src/spec_generated.ts)
  11. PR 5 (feat(openapi): add profile-driven OpenAPI 3.1 service and type binding (generate-openapi) #89): OpenAPI 3.1 REST service & type binding (ucp-schema generate-openapi, src/openapi/mod.rs)

Test Plan

  • cargo fmt --check
  • cargo test --all-targets
  • cargo clippy --all-targets -- -D warnings

@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Oct 1, 2026
gsmith85 added a commit that referenced this pull request Oct 1, 2026
Implement Task 4 (PR 1d) of the ucp-schema codegen pipeline:
- Wire Commands::GenerateTypes in src/bin/ucp-schema.rs with --profile, --capability, --extension, --schema-dir (alias --schema-local-base), --schema-remote-base, --output, and --pretty.
- Implement CliExitCode for CodegenError and generalize write_json_output to <T: serde::Serialize + ?Sized>.
- Add CLI integration tests in tests/generate_types_test.rs covering stdout pretty/compact output, file output, repeatable/comma-delimited flags, and error exit codes.

Stacked PR Roadmap:
- PR 1a (#81): Identifier qualification, UCP keyword stripping, $ref rewriting
- PR 1b (#82): Directional schema slicing and $ref alignment
- PR 1c (#83): Capability/extension reachability, composition, and generate_types() library API
- PR 1d (this PR): CLI generate-types subcommand
- PR 2: Self-contained .well-known/ucp --profile scoping
- PR 3: Inline conditional variant hoisting and ordered anyOf union lowering
- PR 4: OpenAPI 3.1 REST binding assembly (generate-openapi)
gsmith85 added a commit that referenced this pull request Oct 1, 2026
Implement Task 4 (PR 1d) of the ucp-schema codegen pipeline:
- Wire Commands::GenerateTypes in src/bin/ucp-schema.rs with --profile, --capability, --extension, --schema-dir (alias --schema-local-base), --schema-remote-base, --output, and --pretty.
- Implement CliExitCode for CodegenError and generalize write_json_output to <T: serde::Serialize + ?Sized>.
- Add CLI integration tests in tests/generate_types_test.rs covering stdout pretty/compact output, file output, repeatable/comma-delimited flags, and error exit codes.

Stacked PR Roadmap:
- PR 1a (#81): Identifier qualification, UCP keyword stripping, $ref rewriting
- PR 1b (#82): Directional schema slicing and $ref alignment
- PR 1c (#83): Capability/extension reachability, composition, and generate_types() library API
- PR 1d (this PR): CLI generate-types subcommand
- PR 2: Self-contained .well-known/ucp --profile scoping
- PR 3: Inline conditional variant hoisting and ordered anyOf union lowering
- PR 4: OpenAPI 3.1 REST binding assembly (generate-openapi)
gsmith85 added a commit that referenced this pull request Oct 1, 2026
Implement Task 4 (PR 1d) of the ucp-schema codegen pipeline:
- Wire Commands::GenerateTypes in src/bin/ucp-schema.rs with --profile, --capability, --extension, --schema-dir (alias --schema-local-base), --schema-remote-base, --output, and --pretty.
- Implement CliExitCode for CodegenError and generalize write_json_output to <T: serde::Serialize + ?Sized>.
- Add CLI integration tests in tests/generate_types_test.rs covering stdout pretty/compact output, file output, repeatable/comma-delimited flags, and error exit codes.

Stacked PR Roadmap:
- PR 1a (#81): Identifier qualification, UCP keyword stripping, $ref rewriting
- PR 1b (#82): Directional schema slicing and $ref alignment
- PR 1c (#83): Capability/extension reachability, composition, and generate_types() library API
- PR 1d (this PR): CLI generate-types subcommand
- PR 2: Self-contained .well-known/ucp --profile scoping
- PR 3: Inline conditional variant hoisting and ordered anyOf union lowering
- PR 4: OpenAPI 3.1 REST binding assembly (generate-openapi)
@gsmith85
gsmith85 force-pushed the feat/codegen-slicing branch from b6fcada to 88c578b Compare October 1, 2026 23:45
gsmith85 added a commit that referenced this pull request Oct 1, 2026
Implement Task 4 (PR 1d) of the ucp-schema codegen pipeline:
- Wire Commands::GenerateTypes in src/bin/ucp-schema.rs with --profile, --capability, --extension, --schema-dir (alias --schema-local-base), --schema-remote-base, --output, and --pretty.
- Implement CliExitCode for CodegenError and generalize write_json_output to <T: serde::Serialize + ?Sized>.
- Add CLI integration tests in tests/generate_types_test.rs covering stdout pretty/compact output, file output, repeatable/comma-delimited flags, and error exit codes.

Stacked PR Roadmap:
- PR 1a (#81): Identifier qualification, UCP keyword stripping, $ref rewriting
- PR 1b (#82): Directional schema slicing and $ref alignment
- PR 1c (#83): Capability/extension reachability, composition, and generate_types() library API
- PR 1d (this PR): CLI generate-types subcommand
- PR 2: Self-contained .well-known/ucp --profile scoping
- PR 3: Inline conditional variant hoisting and ordered anyOf union lowering
- PR 4: OpenAPI 3.1 REST binding assembly (generate-openapi)
@gsmith85
gsmith85 force-pushed the feat/codegen-compile-types branch from 19346d4 to 1ab4348 Compare October 1, 2026 23:45
gsmith85 added a commit that referenced this pull request Oct 2, 2026
Implement Task 4 (PR 1d) of the ucp-schema codegen pipeline:
- Wire Commands::GenerateTypes in src/bin/ucp-schema.rs with --profile, --capability, --extension, --schema-dir (alias --schema-local-base), --schema-remote-base, --output, and --pretty.
- Implement CliExitCode for CodegenError and generalize write_json_output to <T: serde::Serialize + ?Sized>.
- Add CLI integration tests in tests/generate_types_test.rs covering stdout pretty/compact output, file output, repeatable/comma-delimited flags, and error exit codes.

Stacked PR Roadmap:
- PR 1a (#81): Identifier qualification, UCP keyword stripping, $ref rewriting
- PR 1b (#82): Directional schema slicing and $ref alignment
- PR 1c (#83): Capability/extension reachability, composition, and generate_types() library API
- PR 1d (this PR): CLI generate-types subcommand
- PR 2: Self-contained .well-known/ucp --profile scoping
- PR 3: Inline conditional variant hoisting and ordered anyOf union lowering
- PR 4: OpenAPI 3.1 REST binding assembly (generate-openapi)
gsmith85 added a commit that referenced this pull request Oct 2, 2026
Implement Task 4 (PR 1d) of the ucp-schema codegen pipeline:
- Wire Commands::GenerateTypes in src/bin/ucp-schema.rs with --profile, --capability, --extension, --schema-dir (alias --schema-local-base), --schema-remote-base, --output, and --pretty.
- Implement CliExitCode for CodegenError and generalize write_json_output to <T: serde::Serialize + ?Sized>.
- Add CLI integration tests in tests/generate_types_test.rs covering stdout pretty/compact output, file output, repeatable/comma-delimited flags, and error exit codes.

Stacked PR Roadmap:
- PR 1a (#81): Identifier qualification, UCP keyword stripping, $ref rewriting
- PR 1b (#82): Directional schema slicing and $ref alignment
- PR 1c (#83): Capability/extension reachability, composition, and generate_types() library API
- PR 1d (this PR): CLI generate-types subcommand
- PR 2: Self-contained .well-known/ucp --profile scoping
- PR 3: Inline conditional variant hoisting and ordered anyOf union lowering
- PR 4: OpenAPI 3.1 REST binding assembly (generate-openapi)
@gsmith85
gsmith85 force-pushed the feat/codegen-compile-types branch from a85a726 to 8cac42b Compare October 2, 2026 16:37
@gsmith85
gsmith85 force-pushed the feat/codegen-slicing branch from 88c578b to 4ed1ea1 Compare October 2, 2026 16:37
@gsmith85
gsmith85 force-pushed the feat/codegen-slicing branch from 4ed1ea1 to 7b74335 Compare October 7, 2026 06:00
@gsmith85
gsmith85 force-pushed the feat/codegen-compile-types branch from 8cac42b to 9d93d16 Compare October 7, 2026 06:00
@gsmith85
gsmith85 force-pushed the feat/codegen-slicing branch from 7b74335 to 9380b3c Compare October 7, 2026 22:04
@gsmith85
gsmith85 force-pushed the feat/codegen-compile-types branch from 9d93d16 to 33ec2f4 Compare October 7, 2026 22:04
…_types() API

Implement Task 3 (PR 1c) of the ucp-schema codegen pipeline:
- Stage 1 (src/codegen/reachability.rs): Schema discovery, short/reverse-domain capability and extension selection, extension reclassification, ambient protocol root seeding, and transitive $ref reachability closure with inactive extension $defs pruning.
- Stage 2 (src/codegen/hoist.rs): Upfront $defs hoisting, pure re-export skipping, self-named role container extraction (*PlatformSchema, *BusinessSchema, *ResponseSchema), and collision-aware parent qualification.
- Stage 3 (src/codegen/compose.rs): Active extension composition into root capabilities, in-place standalone sub-type overlays (Buyer, Payment, PaymentInstrument, Cart->Checkout), and container capability operations (both nested $defs and oneOf/allOf shapes).
- Stages 5, 6, 8 & Public API (src/codegen/mod.rs, src/lib.rs): Directional slicing, $ref alignment, empty-object pruning (retaining ErrorResponse), and public GenerateTypesOptions, TypesBundleDoc, CompiledTypes, CodegenError, compile_types(), and generate_types() APIs.

Stacked PR Roadmap:
- PR 1a (#81): Identifier qualification, UCP keyword stripping, $ref rewriting
- PR 1b (#82): Directional schema slicing and $ref alignment
- PR 1c (this PR): Capability/extension reachability, composition, and generate_types() library API
- PR 2: CLI generate-types subcommand and --profile loading
- PR 3: Inline conditional variant hoisting and ordered anyOf union lowering
- PR 4: OpenAPI 3.1 REST binding assembly (generate-openapi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:needs-triage Signal that the PR is ready for human triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants