From 45f891c0bda5769264875421943d9040b62fed74 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 21:38:25 +0000 Subject: [PATCH 1/2] fix(generator): export the class-owned schema from facades XSchema.toJsonSchema() and toSchemaModel() exported the generated backing schema while parse and encode used the class-owned X.schema, so a .describe(...) or exportable constraint on X.schema was dropped from the export. Use the same schema for both. Regenerate the example. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QEFHxK274pLvHpTn3qqhJG --- example/lib/class_first_models.g.dart | 4 ++-- packages/ack_generator/CHANGELOG.md | 5 +++++ .../lib/src/builders/class_model_emitter.dart | 4 ++-- .../ack_infer_runtime_build_test.dart | 16 ++++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/example/lib/class_first_models.g.dart b/example/lib/class_first_models.g.dart index 977d3783..bb2c30a0 100644 --- a/example/lib/class_first_models.g.dart +++ b/example/lib/class_first_models.g.dart @@ -394,11 +394,11 @@ abstract final class AccountSchema { }) => Account.schema.safeEncode(value, debugName: debugName); /// The JSON Schema that describes [Account]. - static Map toJsonSchema() => _accountSchema.toJsonSchema(); + static Map toJsonSchema() => Account.schema.toJsonSchema(); /// The schema model that describes [Account]. static AckSchemaModel toSchemaModel() => - AckSchemaModelExtension(_accountSchema).toSchemaModel(); + AckSchemaModelExtension(Account.schema).toSchemaModel(); } Account _$AccountFromRuntime(Map $ackValue) => Account( diff --git a/packages/ack_generator/CHANGELOG.md b/packages/ack_generator/CHANGELOG.md index 9d10f7ca..13d27b12 100644 --- a/packages/ack_generator/CHANGELOG.md +++ b/packages/ack_generator/CHANGELOG.md @@ -71,6 +71,11 @@ ### Fixed +* Generated `toJsonSchema()` and `toSchemaModel()` on a class-first facade + export the class-owned `schema`, the same schema `parse` and `encode` use. + A `.describe(...)` or an exportable constraint on that schema now appears in + the export. + * Report a build error when `normalize_unicode: true` is enabled and `unorm_dart` is missing from the package resolution. diff --git a/packages/ack_generator/lib/src/builders/class_model_emitter.dart b/packages/ack_generator/lib/src/builders/class_model_emitter.dart index 5478387c..bd7fabb5 100644 --- a/packages/ack_generator/lib/src/builders/class_model_emitter.dart +++ b/packages/ack_generator/lib/src/builders/class_model_emitter.dart @@ -232,11 +232,11 @@ abstract final class ${metadata.facadeName} { /// The JSON Schema that describes [$className]. static Map toJsonSchema() => - ${metadata.backingName}.toJsonSchema(); + $validationSchema.toJsonSchema(); /// The schema model that describes [$className]. static ${_ack('AckSchemaModel')} toSchemaModel() => - ${_ack('AckSchemaModelExtension')}(${metadata.backingName}).toSchemaModel(); + ${_ack('AckSchemaModelExtension')}($validationSchema).toSchemaModel(); }'''; } diff --git a/packages/ack_generator/test/integration/ack_infer_runtime_build_test.dart b/packages/ack_generator/test/integration/ack_infer_runtime_build_test.dart index d94bc380..90d07eb2 100644 --- a/packages/ack_generator/test/integration/ack_infer_runtime_build_test.dart +++ b/packages/ack_generator/test/integration/ack_infer_runtime_build_test.dart @@ -256,6 +256,16 @@ final class RefinedWindow with _$RefinedWindowAck { ); } +@Schemable() +final class DescribedWindow with _$DescribedWindowAck { + const DescribedWindow({required this.start, required this.end}); + final int start; + final int end; + static final schema = DescribedWindowSchema.schema + .refine((window) => window.start <= window.end) + .describe('A time window'); +} + @Schemable() final class RefinedBooking with _$RefinedBookingAck { const RefinedBooking({required this.window}); @@ -658,6 +668,12 @@ void main() { expect(RefinedBookingSchema.safeParse({'window': json}).isFail, isTrue); }); + test('facade exports describe the class-owned schema', () { + expect(DescribedWindowSchema.toJsonSchema()['description'], 'A time window'); + expect(DescribedWindowSchema.toSchemaModel().description, 'A time window'); + expect(DescribedWindowSchema.schema.description, isNull); + }); + test('union branches inherit the base style and honor explicit overrides', () { expect(const StyleCat(livesLeft: 9).toJson(), {'kind': 'cat', 'lives_left': 9}); expect( From 5efea95903c677497f9a4c3eeb06592d2ad7583c Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 2 Dec 2026 22:25:11 +0000 Subject: [PATCH 2/2] docs(generator): note the initializer migration for facade exports A class-owned schema initializer that read XSchema.toJsonSchema() or toSchemaModel() now recurses because those read X.schema. Point to XSchema.schema.toJsonSchema() instead, and keep the class-owned schema non-nullable because the typed facade parse never returns null. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QEFHxK274pLvHpTn3qqhJG --- packages/ack_generator/CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/ack_generator/CHANGELOG.md b/packages/ack_generator/CHANGELOG.md index 13d27b12..57a5f3be 100644 --- a/packages/ack_generator/CHANGELOG.md +++ b/packages/ack_generator/CHANGELOG.md @@ -74,7 +74,11 @@ * Generated `toJsonSchema()` and `toSchemaModel()` on a class-first facade export the class-owned `schema`, the same schema `parse` and `encode` use. A `.describe(...)` or an exportable constraint on that schema now appears in - the export. + the export. A class-owned `schema` initializer that reads the facade's + `toJsonSchema()` or `toSchemaModel()` now recurses; read + `XSchema.schema.toJsonSchema()` or `XSchema.schema.toSchemaModel()` there + instead. Keep a class-owned `schema` non-nullable: the facade's typed `parse` + never returns `null`. * Report a build error when `normalize_unicode: true` is enabled and `unorm_dart` is missing from the package resolution.