Skip to content

fix: enforce minProperties in generated schemas - #41

Merged
damaz91 merged 2 commits into
Universal-Commerce-Protocol:mainfrom
FanouZeng-TT:fix/enforce-min-properties
Aug 12, 2026
Merged

fix: enforce minProperties in generated schemas#41
damaz91 merged 2 commits into
Universal-Commerce-Protocol:mainfrom
FanouZeng-TT:fix/enforce-min-properties

Conversation

@FanouZeng-TT

Copy link
Copy Markdown
Contributor

Description

inject-schema-constraints.mjs restores JSON Schema constraints that quicktype's
typescript-zod target omits, but it did not handle minProperties. The pinned
UCP schema contains two affected shapes:

// common/types/description.json
{
  "properties": { "plain": {}, "html": {}, "markdown": {} },
  "minProperties": 1
}

// shopping/types/available_payment_instrument.json
{
  "constraints": {
    "type": "object",
    "additionalProperties": true,
    "minProperties": 1
  }
}

The generated schemas therefore accepted both an empty Description and an
empty, present constraints record:

DescriptionSchema.parse({});
AvailablePaymentInstrumentSchema.parse({ type: "card", constraints: {} });

Fix: index object-level and record-level minProperties constraints and
append a Zod refinement during generation. Object schemas retain additional
properties before counting them, matching JSON Schema's default behavior.
Regression tests cover rejection of empty objects, acceptance of non-empty
objects, optional constraints, and retention of additional description keys.

Category (Required)

  • Core Protocol: Changes to the base communication layer, global context, or breaking refactors. (Requires Technical Council approval)
  • Governance/Contributing: Updates to GOVERNANCE.md, CONTRIBUTING.md, or CODEOWNERS. (Requires Governance Council approval)
  • Capability: New schemas (Discovery, Cart, etc.) or extensions. (Requires Maintainer approval)
  • Documentation: Updates to README, or documentations regarding schema or capabilities. (Requires Maintainer approval)
  • Infrastructure: CI/CD, Linters, or build scripts. (Requires DevOps Maintainer approval)
  • Maintenance: Version bumps, lockfile updates, or minor bug fixes. (Requires DevOps Maintainer approval)
  • SDK: Language-specific SDK updates and releases. (Requires DevOps Maintainer approval)
  • Samples / Conformance: Maintaining samples and the conformance suite. (Requires Maintainer approval)
  • UCP Schema: Changes to the ucp-schema tool (resolver, linter, validator). (Requires Maintainer approval)
  • Community Health (.github): Updates to templates, workflows, or org-level configs. (Requires DevOps Maintainer approval)

Related Issues

N/A

Checklist

  • I have followed the Contributing Guide (including Conventional Commits title requirements and ! for breaking changes).
  • I have updated the documentation (if applicable).
  • My changes pass all local linting and formatting checks.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • (For Core/Capability) I have included/updated the relevant JSON schemas.
  • I have regenerated Python Pydantic models by running generate_models.sh under python_sdk.

Screenshots / Logs (if applicable)

  • npm test — 50 tests passed
  • npm run build:noEmit — passed
  • npm run build — passed
  • pre-commit run --all-files — passed
  • Regeneration from pinned UCP release/2026-04-08 produced the committed src/spec_generated.ts byte-for-byte after formatting.

@damaz91 damaz91 added status:needs-triage Signal that the PR is ready for human triage status:under-review and removed status:needs-triage Signal that the PR is ready for human triage labels Aug 11, 2026
@damaz91
damaz91 merged commit a50cab9 into Universal-Commerce-Protocol:main Aug 12, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants