Skip to content

feat: support URL mapping in resolve --bundle + validate --schema#27

Merged
igrigorik merged 2 commits intomainfrom
feat/resolve-remote
Apr 29, 2026
Merged

feat: support URL mapping in resolve --bundle + validate --schema#27
igrigorik merged 2 commits intomainfrom
feat/resolve-remote

Conversation

@igrigorik
Copy link
Copy Markdown
Contributor

3P extension authors write schemas that reference UCP core types via absolute URIs (e.g., $ref: "https://ucp.dev/schemas/shopping/types/variant.json"). This is the correct form for published schemas — the extension lives on a different host than the types it extends.

resolve --bundle and validate --schema currently reject --schema-remote-base/--schema-local-base flags for direct schema file input, making it impossible to bundle these schemas locally. The underlying infrastructure already supported URL mapping and HTTP fetch — it just wasn't wired up for these code paths. With this update...

Online works by default

# Fetches https://ucp.dev/... refs automatically
ucp-schema resolve my_extension.json --bundle --response --op read

Offline / CI — map URLs to local copies

ucp-schema resolve my_extension.json --bundle --response --op read \
  --schema-remote-base "https://ucp.dev/schemas" \
  --schema-local-base ./local-ucp-schemas

Validate with explicit schema

ucp-schema validate payload.json \
  --schema my_extension.json \
  --schema-remote-base "https://ucp.dev/schemas" \
  --schema-local-base ./local-ucp-schemas \
  --response --op read

Category (Required)

  • UCP Schema: Changes to the ucp-schema tool (resolver, linter, validator). (Requires Maintainer approval)
  • I have followed the Contributing Guide.
  • I have updated the documentation (if applicable).
  • My changes pass all local linting and formatting checks.
  • (For Core/Capability) I have included/updated the relevant JSON schemas.

  3P extension authors write schemas that reference UCP core types via
  absolute URIs (e.g., $ref: "https://ucp.dev/schemas/shopping/types/
  variant.json"). This is the correct form for published schemas — the
  extension lives on a different host than the types it extends.

  Previously, `resolve --bundle` and `validate --schema` explicitly
  rejected --schema-remote-base/--schema-local-base flags for direct
  schema file input (commit 6ab9252). The guard was added to prevent
  flags from being silently ignored, since at the time all development
  was in-repo with co-located files and relative refs. The underlying
  infrastructure (bundle_refs_with_url_mapping, bundle_refs_remote)
  already supported URL mapping and HTTP fetch — it just wasn't wired
  up for these code paths.

  Solution
  --------
  1. Remove the guards in resolve and validate that rejected base flags
     for schema file / explicit --schema input.

  2. Wire bundle_refs_with_url_mapping into resolve --bundle when
     --schema-remote-base/--schema-local-base are present. This maps
     absolute URL $ref values to local files during bundling.

  3. Add HTTP fetch fallback in bundle_refs_inner: when local path
     resolution fails for an absolute URL $ref and no URL mapping is
     configured, fall back to load_schema_url() to fetch over HTTP.
     This enables zero-config usage for online development.

  The result is two resolution modes for absolute URL refs:
  - Online (default): fetches referenced schemas from their URLs
  - Offline: --schema-remote-base/--schema-local-base maps URLs to
    local copies, same as compose already supported

  validate --schema inherits the same fix via bundle_local_refs(),
  which already dispatched to bundle_refs_with_url_mapping when flags
  were present — the guard was the only thing preventing it.
@igrigorik igrigorik self-assigned this Apr 25, 2026
@igrigorik igrigorik requested review from a team as code owners April 25, 2026 13:41
Copy link
Copy Markdown

@drewolson-google drewolson-google left a comment

Choose a reason for hiding this comment

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

LGTM, one small comment.

Comment thread src/bin/ucp-schema.rs Outdated
  Reuse bundle_local_refs() (already used by run_validate) and
  hoist the verbose log out of the if-let branches.
@igrigorik igrigorik merged commit be4400e into main Apr 29, 2026
11 checks passed
@igrigorik igrigorik deleted the feat/resolve-remote branch April 29, 2026 04:44
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.

3 participants