feat(genui): support ref schema resolution and validation via SchemaRegistry#998
Open
gspencergoog wants to merge 9 commits into
Open
feat(genui): support ref schema resolution and validation via SchemaRegistry#998gspencergoog wants to merge 9 commits into
gspencergoog wants to merge 9 commits into
Conversation
…egistry - Changed `SurfaceDefinition.validate` and validation APIs to be asynchronous to support resolving `$ref` schemas. - Integrated `SchemaRegistry` to validate component schemas using local assets or filesystem. - Exported `SchemaRegistry` in `json_schema_builder`. - Updated CHANGELOG.md for the breaking change. - Fixed a button widget stream test issue where manual subscription cancellation caused test runner hangs.
- Created `packages/genui/tool/generate_embedded_schemas.dart` script to compile schema JSONs to Dart string constants. - Generated `packages/genui/lib/src/primitives/embedded_schemas.dart` containing embedded A2UI schemas. - Updated `SurfaceController._getSchemaRegistry` to load the common types schema synchronously from the embedded string literal. - Unregistered the assets from `packages/genui/pubspec.yaml` and deleted the local asset files. - Removed unused assets-related constants from `packages/genui/lib/src/primitives/constants.dart`.
- Integrated schema compilation into the standard Dart `build_runner` framework. - Created `packages/genui/tool/schema_builder.dart` implementing the `Builder` interface to copy schemas from submodules at build time. - Configured `packages/genui/build.yaml` to trigger `schema_builder` on `pubspec.yaml` changes. - Added `build` and `build_runner` as dev_dependencies in `packages/genui/pubspec.yaml`. - Deleted the temporary standalone `generate_embedded_schemas.dart` script.
Package publishingIf you have publishing permissions, you can use the links below to publish the changes after merging this PR.
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
- Renamed generated schemas file extension to `.g.dart` to follow Dart builder conventions. - Updated SchemaBuilder implementation and build.yaml configurations to output to `.g.dart`. - Updated import references in surface_controller.dart.
1f6e743 to
2c43d36
Compare
…dation - Updated button event handler to use StreamIterator to prevent synchronous race conditions. - Configured schema builder to throw a descriptive StateError if the A2UI submodule is not checked out. - Simplified button test mock stream to use Stream.error and wrapped test execution inside tester.runAsync. - Optimized _getSchemaRegistry() in SurfaceController to be synchronous and removed redundant await calls. - Bumped json_schema_builder version to 0.1.6 and documented public SchemaRegistry export in CHANGELOG.md.
…a builder - Changed schema builder's auto_apply policy to none in build.yaml to prevent breaking dependents. - Added check during directory traversal in schema_builder.dart to throw a descriptive StateError if .gitmodules is not found. - Updated missing schema source files handling to throw a StateError directly instead of failing silently.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR enables validation of component definitions containing
$refschemas (such as references tocommon_types.json) by integrating aSchemaRegistryto compile and resolve external schema references.Changes
Schema Validation & Reference Resolution:
packages/genui/lib/src/model/schema_validation.dartto usejson_schema_builder's robust schema validation (Schema.validate) instead of a basic hand-rolled implementation.validateComponents(inschema_validation.dart) andSurfaceDefinition.validate(inui_models.dart) to be asynchronous to support the asynchronous reference validation interface ofjson_schema_builder.SchemaRegistryinpackages/json_schema_builder/lib/json_schema_builder.dartto make it publicly accessible.Embedded Schemas &
build_runnerBuilder:buildandbuild_runnerdev-dependencies topackages/genui/pubspec.yaml.build_runnerbuilder inpackages/genui/tool/schema_builder.dartand registered it inpackages/genui/build.yaml. The builder automatically embedscommon_types.jsonandserver_to_client.jsonfrom thea2uispecification submodule into static string literals inlib/src/primitives/embedded_schemas.g.dart.SurfaceController._getSchemaRegistryto synchronously load and populate the registry with the embedded common types schema.Testing and Bug Fixes:
packages/genui/test/catalog/core_widgets/button_test.dartwhere manual subscription cancellation on closed stream controllers caused the test runner to hang in FakeAsync zones. Refactored the test to useSurfaceController.dispose()for listener cleanup.surface_controller_test.dartandui_models_test.dartto align with the new asynchronous validation signature.Impact & Risks
SurfaceDefinition.validatemethod now returns aFuture<void>instead ofvoid. Since this is primarily an internal component representation validation helper, the public integration surface impact is low, but tests that manually validate schemas must be updated toawaitthe validation.CHANGELOG.mdentry inpackages/genuidocumenting this change.Testing
Automatic Verification:
flutter test packages/genuiRe-generating Schemas:
embedded_schemas.g.dartis correctly regenerated.