Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/lib/class_first_models.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions packages/ack_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@

### 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. 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ abstract final class ${metadata.facadeName} {

/// The JSON Schema that describes [$className].
static Map<String, Object?> 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();
}''';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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(
Expand Down
Loading