Skip to content

fix(core): preserve primitive validation in JSON Schema unions - #8267

Open
黄耀鑫(Huang Yaoxin) (YaoxinHuang) wants to merge 2 commits into
microsoft:mainfrom
YaoxinHuang:fix/primitive-union-validation
Open

黄耀鑫(Huang Yaoxin) (YaoxinHuang) wants to merge 2 commits into
microsoft:mainfrom
YaoxinHuang:fix/primitive-union-validation

Conversation

@YaoxinHuang

Copy link
Copy Markdown

Why are these changes needed?

schema_to_pydantic_model() drops numeric bounds, string constraints, and formats from primitive anyOf/oneOf branches. For example, an integer-or-null field with minimum: 0 accepts -1 after conversion.

Use the existing field-type conversion for string, integer, and number union branches, preserving their validation. Array, reference, enum, and object handling stays the same. Add regression cases for numeric bounds, string lengths/patterns, and email format, including valid boundary values and null.

Related issue number

No existing issue found for primitive union validation. This is separate from #6925, which handled array branches.

Validation

  • The 16 new cases fail against the unchanged implementation.
  • pytest packages/autogen-core/tests/test_json_to_pydantic.py -q: 91 passed.
  • Ruff formatting/lint, Mypy, and Pyright passed for both changed files.
  • Full workspace, documentation, and integration checks were not run locally.

Checks

  • I've included any doc changes needed (no public API or documentation changes).
  • I've added tests corresponding to the changes introduced in this PR.
  • I've made sure all auto checks have passed (upstream CI pending).

This change and its regression tests were prepared with Codex.

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.

1 participant