Skip to content

fix: preserve array-root request variants#52

Open
ShuoRen-TT wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
ShuoRen-TT:fix/preserve-array-root-request-variants
Open

fix: preserve array-root request variants#52
ShuoRen-TT wants to merge 1 commit into
Universal-Commerce-Protocol:mainfrom
ShuoRen-TT:fix/preserve-array-root-request-variants

Conversation

@ShuoRen-TT

@ShuoRen-TT ShuoRen-TT commented Jul 11, 2026

Copy link
Copy Markdown

Description

Fix request variant generation for array-root schemas such as totals.json.

_create_single_variant previously injected empty properties and required
members into every generated variant. For an array-root schema,
datamodel-code-generator interpreted the resulting mixed array/object shape as
a union between the intended list and an empty BaseModel. The function also
did not apply nested ucp_request rules under items and its allOf branches.

This change:

  • extracts object property filtering into a reusable helper;
  • preserves the root shape of array schemas;
  • applies request rules to object schemas nested below array items;
  • regenerates the create and update totals request models; and
  • adds regression coverage for schema preprocessing and generated model
    validation.

The generated totals request aliases are now lists of Total. They no longer
contain a spurious empty model or expose the nested response-only lines
field as a typed request field.

Relationship to #35

This PR and #35 are complementary rather than competing fixes.

Both changes touch _create_single_variant, so the PR merged second may need a
small mechanical rebase. This PR intentionally does not include #35's
whole-variant $ref rewrite or its generated fulfillment model changes.

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

Fixes #37

Related: #35

Checklist

  • 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.
  • I have regenerated Python Pydantic models by running generate_models.sh 2026-04-08.

Validation

  • bash generate_models.sh 2026-04-08
  • python -m unittest preprocess_schemas_test.py (2 tests passed)
  • python -m compileall -q preprocess_schemas.py preprocess_schemas_test.py src/ucp_sdk
  • pre-commit on all changed files
  • full pre-commit excluding ShellCheck, which requires Docker locally; this PR does not modify shell files

@ShuoRen-TT ShuoRen-TT marked this pull request as ready for review July 12, 2026 03:32
@damaz91 damaz91 added the status:needs-triage Signal that the PR is ready for human triage label Jul 12, 2026
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.

_create_single_variant emits empty BaseModel union for array-root schemas (totals)

2 participants