Skip to content

fix: support current UCP schema generation#16

Merged
wry-ry merged 3 commits intoUniversal-Commerce-Protocol:mainfrom
sakinaroufid:fix/ucp-schema-generation-clean
Apr 24, 2026
Merged

fix: support current UCP schema generation#16
wry-ry merged 3 commits intoUniversal-Commerce-Protocol:mainfrom
sakinaroufid:fix/ucp-schema-generation-clean

Conversation

@sakinaroufid
Copy link
Copy Markdown
Contributor

@sakinaroufid sakinaroufid commented Mar 24, 2026

Summary

Fix js-sdk model generation so it works with the current upstream UCP schema layout while keeping the existing generated SDK API intact.

Context

The SDK generator was built around the older split schema layout (*.create_req, *.update_req, *_resp). Upstream UCP has moved to unified schemas under source/, so generation in this repo had drifted away from the actual source of truth.

This change brings the generator back in line with upstream without forcing a consumer-facing API rewrite in js-sdk.

What changed

  • updated generate_models.sh to handle both the legacy split layout and the current upstream source/ layout
  • added a projection step that derives the legacy request/update/response inputs from the unified upstream schemas
  • kept the existing quicktype-based generation flow in place after that projection step
  • normalized duplicated quicktype output so the generated export surface stays stable
  • regenerated src/spec_generated.ts

Why this approach

There were two obvious ways to deal with the upstream schema changes:

  1. switch the SDK over to the unified upstream model directly
  2. preserve the SDK’s current generated surface and adapt the generator

This takes the second approach. The problem here is generator drift, not that the SDK suddenly needs a new public API.

Validation

Ran locally:

  • npm run generate -- /tmp/ucp-spec-test
  • npm run build:noEmit
  • npm run build

Notes

The largest part of the change is the projection layer. That is where the compatibility logic now lives, and it is what allows js-sdk to keep generating the same kind of output from the current upstream schema model.

Project the current upstream UCP source schemas into the legacy split request and response shapes this SDK exports, then normalize quicktype output to keep the generated API stable.
@sakinaroufid
Copy link
Copy Markdown
Contributor Author

sakinaroufid commented Mar 24, 2026

@wry-ry tagging you here as I have submitted PR to fix schema generation

@sakinaroufid
Copy link
Copy Markdown
Contributor Author

Clarification: this PR fixes the repo-side schema generation issues that were causing drift against the current upstream UCP schema model while preserving the legacy generated API shape.

Thanks!

@artemii-karkusha
Copy link
Copy Markdown

We hit this in production while integrating with real merchants from https://merchants.awesomeucp.com/ (Everlane, Monos, etc.). The current spec_generated.ts breaks capability detection — capabilities parsed as an array returns empty when merchants send the spec-compliant object format, so checkout/fulfillment/discount are never detected.

Filed #19 with details and reproduction steps.

Would be great to get this merged — it's currently the main blocker for any JS client connecting to live UCP merchants.

@ptiper ptiper requested review from cusell-google and removed request for aksbro-gpu, jingyli, ptiper and westeezy April 17, 2026 12:50
@matijagrcic
Copy link
Copy Markdown

Can this be merged and new version of the package published. @igrigorik @westeezy

wrong spec -

js-sdk/src/spec_generated.ts

Lines 1074 to 1078 in fd95d6f

export const UcpClassSchema = z.object({
capabilities: z.array(CapabilityDiscoverySchema),
services: z.record(z.string(), UcpServiceSchema),
version: z.string(),
});

schema - https://github.com/Universal-Commerce-Protocol/ucp/blob/release/2026-04-08/source/schemas/ucp.json

Copy link
Copy Markdown

@cusell-google cusell-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at the styling/lint errors on https://github.com/Universal-Commerce-Protocol/js-sdk/actions/runs/24565943451/job/72880712623?pr=16 and fix them. Otherwise LG. Thanks @sakinaroufid for fixing the js-sdk!

Matches pre-commit/mirrors-prettier (v4.0.0-alpha.8) per linter workflow.
Copy link
Copy Markdown
Contributor Author

@sakinaroufid sakinaroufid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! Thank you for your review! @cusell-google

@wry-ry wry-ry merged commit 229cc31 into Universal-Commerce-Protocol:main Apr 24, 2026
4 checks passed
@sakinaroufid
Copy link
Copy Markdown
Contributor Author

Terrific! Thanks for merging @wry-ry

@matijagrcic
Copy link
Copy Markdown

can we get a new release/package published?

@sakinaroufid sakinaroufid mentioned this pull request Apr 25, 2026
2 tasks
@wcielen
Copy link
Copy Markdown

wcielen commented Apr 30, 2026

this is exactly what I've been looking for

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.

7 participants