Skip to content

fix: enforce conditional required fields in generated models - #69

Merged
damaz91 merged 1 commit into
Universal-Commerce-Protocol:mainfrom
FanouZeng-TT:fix/enforce-conditional-required
Aug 12, 2026
Merged

fix: enforce conditional required fields in generated models#69
damaz91 merged 1 commit into
Universal-Commerce-Protocol:mainfrom
FanouZeng-TT:fix/enforce-conditional-required

Conversation

@FanouZeng-TT

Copy link
Copy Markdown
Contributor

Description

pagination.json requires cursor when has_next_page is true, but datamodel-code-generator drops the schema's if/then rule and emits cursor as unconditionally optional. Response(has_next_page=True) therefore passed validation without a continuation cursor.

Fix: extract simple single-discriminator const/enum conditions with then.required and inject an idempotent Pydantic model validator. Required-field presence uses model_fields_set, preserving JSON Schema's key-presence semantics; complex conditions are skipped.

Category (Required)

  • Core Protocol
  • Governance/Contributing
  • Capability
  • Documentation
  • Infrastructure
  • Maintenance
  • SDK
  • Samples / Conformance
  • UCP Schema
  • Community Health (.github)

Related Issues

N/A

Checklist

  • I have followed the Contributing Guide and Code of Conduct.
  • I have updated the documentation (if applicable).
  • My changes pass all local linting and formatting checks.
  • I have added tests that prove the fix is effective.
  • New and existing unit tests pass locally with my changes.
  • I have included/updated the relevant JSON schemas (Core/Capability only).
  • I have regenerated Python Pydantic models by running generate_models.sh 2026-04-08.

Screenshots / Logs (if applicable)

  • Python unit tests: 61 passed
  • pre-commit run --all-files: passed
  • pinned regeneration: generated pagination model matches byte-for-byte

@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 12, 2026
@damaz91
damaz91 merged commit b0d4924 into Universal-Commerce-Protocol:main Aug 12, 2026
16 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