diff --git a/packages/genui/lib/src/model/catalog.dart b/packages/genui/lib/src/model/catalog.dart index 0c00b2074..6b7953256 100644 --- a/packages/genui/lib/src/model/catalog.dart +++ b/packages/genui/lib/src/model/catalog.dart @@ -271,17 +271,6 @@ class CatalogItemNotFoundException implements Exception { } } -class _CatalogItemComponentApi implements core.ComponentApi { - _CatalogItemComponentApi(this._item); - final CatalogItem _item; - - @override - String get name => _item.name; - - @override - Schema get schema => _item.dataSchema; -} - /// Builds the `a2ui_core` [core.Catalog] for [catalog], used when constructing /// a [core.SurfaceModel] so `a2ui_core` lookups see real component metadata /// instead of an empty stub. @@ -289,7 +278,5 @@ class _CatalogItemComponentApi implements core.ComponentApi { core.Catalog coreCatalogFor(Catalog catalog) => core.Catalog( id: catalog.effectiveCatalogId, - components: catalog.items - .map(_CatalogItemComponentApi.new) - .toList(growable: false), + components: catalog.items.toList(growable: false), ); diff --git a/packages/genui/lib/src/model/catalog_item.dart b/packages/genui/lib/src/model/catalog_item.dart index 715f335eb..b63eaecab 100644 --- a/packages/genui/lib/src/model/catalog_item.dart +++ b/packages/genui/lib/src/model/catalog_item.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:a2ui_core/a2ui_core.dart' as core; import 'package:flutter/material.dart'; import 'package:json_schema_builder/json_schema_builder.dart'; @@ -81,7 +82,7 @@ final class CatalogItemContext { /// Defines a UI layout type, its schema, and how to build its widget. @immutable -final class CatalogItem { +final class CatalogItem implements core.ComponentApi { /// Creates a new [CatalogItem]. const CatalogItem({ required this.name, @@ -92,10 +93,15 @@ final class CatalogItem { }) : _originalSchema = dataSchema; /// The widget type name used in JSON, e.g., 'TextChatMessage'. + @override final String name; final Schema _originalSchema; + /// `core.ComponentApi` names this `schema`; genui exposes it as [dataSchema]. + @override + Schema get schema => dataSchema; + /// The schema definition for this widget's data. /// /// It should contain all of the component specific properties, but not the diff --git a/packages/genui/test/catalog_test.dart b/packages/genui/test/catalog_test.dart index 192404d47..54a147b60 100644 --- a/packages/genui/test/catalog_test.dart +++ b/packages/genui/test/catalog_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:a2ui_core/a2ui_core.dart' as core; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:genui/genui.dart'; @@ -220,4 +221,12 @@ void main() { expect(firstFunc.containsKey('parameters'), isTrue); }); }); + + group('CatalogItem', () { + test('is a core.ComponentApi whose schema is its dataSchema', () { + final CatalogItem item = BasicCatalogItems.text; + expect(item, isA()); + expect(item.schema.value, item.dataSchema.value); + }); + }); }