Repository navigation
refactor(python/builder,cli)!: omit unset schema defaults in builders - #4532
Conversation
There was a problem hiding this comment.
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.
…erated builders Signed-off-by: Jacob Simionato <jsimionato@google.com>
d44dcd6 to
8b946e3
Compare
72def38 to
64020df
Compare
|
GitHub marked this PR as merged when I reordered the stack: its commit became reachable from the old base branch. Nothing landed on |
Problem
Generated Python component builders in
a2ui.builder.v0_9.catalogs.basicanda2ui.builder.v1_0.catalogs.basicpreviously wrote JSON Schema default values (such asvariant="body"onTextorjustify="start"onColumn) onto every serialized wire message even when the caller never set them. That bloated wire payloads, diverged froma2ui-coreand the typesafe builder spec, and prevented clean wire-to-builder round-tripping with hand-authored or LLM-generated messages.Summary
None: Updatedart/a2ui_cli'sPythonEmitterso optional component properties default toNoneand store the JSON Schema default in Pydantic field metadata (json_schema_extra["default"]) instead of materializing unauthored defaults onto the wire.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 againsta2ui-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.
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
+5 / -3dart/a2ui_cli/lib/src/emitters/python/python_emitter.dart(default=None+ schema default metadata)+365 / -280v0_9/v1_0basic.pycatalogs, 22 builder goldens, and 34 macro goldens+13 / -12codegen_test.dart, 1 macro fixture that expected materialized defaults, and 3 unit assertions+9 / -0**BREAKING CHANGE**:entry at top ofpython/a2ui_agent/CHANGELOG.md+392 / -295+5 / -3); 56 files are regenerated catalogs & goldensStart here
dart/a2ui_cli/lib/src/emitters/python/python_emitter.dart): Review the 8-line change switching optional properties todefault=Nonewhile preserving schema defaults injson_schema_extra.python/a2ui_agent/src/a2ui/builder/v1_0/catalogs/basic.py): Verify optional fields with schema defaults (such asText.variantandColumn.justify) omit defaults when unset while keeping metadata inspectable.Implementation details
dart/a2ui_cli/lib/src/emitters/python/python_emitter.dart: AddshasSchemaDefault = !prop.isRequired && defaultLiteral != null; emitsField(default=None, json_schema_extra={"default": <literal>})for optional properties with JSON Schema defaults.python/a2ui_agent/src/a2ui/builder/v0_9/catalogs/basic.pyandpython/a2ui_agent/src/a2ui/builder/v1_0/catalogs/basic.py.conformance/agent/builder/golden/) and 34 macro conformance goldens (conformance/agent/macros/golden/), verified throughMessageProcessor.conformance/agent/macros/macros.yamlCase 33,dart/a2ui_cli/test/codegen_test.dart,python/a2ui_agent/tests/test_macros.py, andpython/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 passeduv run mypy .: 0 errors across 246 source filesuv 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