Skip to content

refactor(python/builder,cli)!: omit unset schema defaults in builders - #4532

Merged
jacobsimionato merged 1 commit into
macros/2-checks-a11y-paramsfrom
macros/5-omit-builder-defaults
Dec 3, 2026
Merged

jacobsimionato merged 1 commit into
macros/2-checks-a11y-paramsfrom
macros/5-omit-builder-defaults

Conversation

@jacobsimionato

@jacobsimionato jacobsimionato commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Generated Python component builders in a2ui.builder.v0_9.catalogs.basic and a2ui.builder.v1_0.catalogs.basic previously wrote JSON Schema default values (such as variant="body" on Text or justify="start" on Column) onto every serialized wire message even when the caller never set them. That bloated wire payloads, diverged from a2ui-core and the typesafe builder spec, and prevented clean wire-to-builder round-tripping with hand-authored or LLM-generated messages.

Summary

  1. Default optional builder fields to None: Update dart/a2ui_cli's PythonEmitter so optional component properties default to None and store the JSON Schema default in Pydantic field metadata (json_schema_extra["default"]) instead of materializing unauthored defaults onto the wire.
  2. Regenerate basic catalogs and golden fixtures: Regenerate v0_9/catalogs/basic.py, v1_0/catalogs/basic.py, all 22 builder conformance goldens, and all 34 macro conformance goldens, validating every regenerated golden against a2ui-core's wire validator (MessageProcessor).

Breaking & behavior changes

Warning

Serialized wire payloads from generated component builders no longer include optional schema defaults unless explicitly passed by the caller.

  1. Omitted unauthored defaults: Calling Text(text="Hi") now serializes {"id": "...", "component": "Text", "text": "Hi"} without "variant": "body". Callers or tests that expect specific default keys in serialized JSON should pass them explicitly (e.g. Text(text="Hi", variant="body")). Schema defaults remain inspectable via Pydantic field metadata.

Diff breakdown & where to review

Category Files Diff Summary
Production logic 1 +5 / -3 dart/a2ui_cli/lib/src/emitters/python/python_emitter.dart (default=None + schema default metadata)
Generated builders & goldens 56 +365 / -280 Regenerated v0_9/v1_0 basic.py catalogs, 22 builder goldens, and 34 macro goldens
Tests & conformance 4 +13 / -12 Updated codegen_test.dart, 1 macro fixture that expected materialized defaults, and 3 unit assertions
Docs & changelogs 1 +9 / -0 **BREAKING CHANGE**: entry at top of python/a2ui_agent/CHANGELOG.md
Total 62 +392 / -295 Only 1 production file (+5 / -3); 56 files are regenerated catalogs & goldens

Start here

  1. Python emitter (dart/a2ui_cli/lib/src/emitters/python/python_emitter.dart): Review the 8-line change switching optional properties to default=None while preserving schema defaults in json_schema_extra.
  2. Generated basic catalog spot-check (python/a2ui_agent/src/a2ui/builder/v1_0/catalogs/basic.py): Verify optional fields with schema defaults (such as Text.variant and Column.justify) omit defaults when unset while keeping metadata inspectable.
Implementation details
  • dart/a2ui_cli/lib/src/emitters/python/python_emitter.dart: Adds hasSchemaDefault = !prop.isRequired && defaultLiteral != null; emits Field(default=None, json_schema_extra={"default": <literal>}) for optional properties with JSON Schema defaults.
  • Regenerated python/a2ui_agent/src/a2ui/builder/v0_9/catalogs/basic.py and python/a2ui_agent/src/a2ui/builder/v1_0/catalogs/basic.py.
  • Regenerated all 22 builder conformance goldens (conformance/agent/builder/golden/) and 34 macro conformance goldens (conformance/agent/macros/golden/), verified through MessageProcessor.
  • Updated conformance/agent/macros/macros.yaml Case 33, dart/a2ui_cli/test/codegen_test.dart, python/a2ui_agent/tests/test_macros.py, and python/a2ui_agent/tests/test_pydantic_builders.py.
Verification — 114 Dart CLI tests, mypy (0 errors), and 247 builder & macro conformance tests passed
  • cd dart/a2ui_cli && dart format --output=none --set-exit-if-changed lib/ test/ && dart analyze --fatal-infos && dart test: 114 passed
  • uv run mypy .: 0 errors across 246 source files
  • uv run pytest python/a2ui_agent/tests/conformance/test_builder_conformance.py python/a2ui_agent/tests/conformance/test_macro_conformance.py python/a2ui_agent/tests/test_pydantic_builders.py python/a2ui_agent/tests/test_pydantic_builders_v1_0.py python/a2ui_agent/tests/test_macros.py: 247 passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a breaking change to the Python and Dart code generators, ensuring that generated catalog component builders no longer materialize unauthored JSON Schema defaults onto wire payloads. Optional fields now default to None with their schema defaults recorded in json_schema_extra["default"]. Consequently, numerous golden conformance files, tests, and basic catalog builder files have been updated to omit default properties (such as variant: "body" or justify: "start") from serialized payloads. No review comments were provided for this pull request, so there is no additional feedback to address.

@jacobsimionato jacobsimionato changed the title refactor(python/builder,cli)!: omit unauthored schema defaults in generated builders refactor(python/builder,cli)!: omit unset schema defaults in builders Dec 2, 2026
@jacobsimionato
jacobsimionato removed this pull request from stack #4536 December 2, 2026 23:18
…erated builders

Signed-off-by: Jacob Simionato <jsimionato@google.com>
@jacobsimionato
jacobsimionato removed this pull request from stack #4552 December 3, 2026 12:03
@jacobsimionato
jacobsimionato force-pushed the macros/4-typed-function-calls branch from d44dcd6 to 8b946e3 Compare December 3, 2026 12:04
@jacobsimionato
jacobsimionato force-pushed the macros/5-omit-builder-defaults branch from 72def38 to 64020df Compare December 3, 2026 12:04
Base automatically changed from macros/4-typed-function-calls to macros/2-checks-a11y-params December 3, 2026 12:04
@jacobsimionato
jacobsimionato merged commit 64020df into macros/2-checks-a11y-params Dec 3, 2026
1 check passed
@jacobsimionato
jacobsimionato deleted the macros/5-omit-builder-defaults branch December 3, 2026 12:04
@jacobsimionato

Copy link
Copy Markdown
Collaborator Author

GitHub marked this PR as merged when I reordered the stack: its commit became reachable from the old base branch. Nothing landed on main. The change continues in #4566, part of the reordered macros stack (https://github.com/a2ui-project/a2ui/stack/4568).

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