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
6 changes: 6 additions & 0 deletions packages/ack_generator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

### Fixed

* Preserve schema-first presence, nullability, and default-wrapper behavior
through aliases and explicit constant flag overrides. Apply the outermost
strict/passthrough policy to object models and aliases.
* Reject object shape-changing methods that cannot be modeled statically,
instead of generating fields that disagree with the authored schema.

* Allow built-in and contextual Dart keywords such as `required` as generated
field, discriminator, and capture-member names without changing their JSON
keys. Reserved words such as `class` remain rejected. Member validation now
Expand Down
9 changes: 9 additions & 0 deletions packages/ack_generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ Named model references work through direct imports, prefixes, and re-exports.
Nested conversion uses each model's public `$ack` adapter so codec runtime
values aren't parsed twice.

Schema-first fields retain optional, nullable, and default behavior through
named schema variables and getters. Explicit constant flag overrides such as
`.optional(value: false)` are honored, as is the outermost `.strict()` or
`.passthrough()` object policy. Shape-changing object methods (`extend`,
`partial`, `merge`, `pick`, `omit`, or `copyWith(properties: ...)`) are rejected
when generating an object model; write its final properties in an
`Ack.object({...})` map literal instead. An outer bidirectional codec can still
wrap such a schema as a value model.

## Generated part

Every annotated library declares a single `.g.dart` part:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ final class SchemaChain {
const SchemaChain({
required this.base,
required this.reference,
required this.optional,
required this.nullable,
required this.defaulted,
required this.hasTransform,
required this.hasCodec,
});

final MethodInvocation? base;
final Expression? reference;
final bool optional;
final bool nullable;
final bool defaulted;
final bool hasTransform;
final bool hasCodec;
}
Expand Down Expand Up @@ -677,26 +671,17 @@ abstract base class ModelGraphBuilderBase {
return SchemaChain(
base: null,
reference: expression,
optional: false,
nullable: false,
defaulted: false,
hasTransform: false,
hasCodec: false,
);
}
MethodInvocation? current = expression;
MethodInvocation? base;
Expression? reference;
var optional = false;
var nullable = false;
var defaulted = false;
var transform = false;
var codec = false;
while (current != null) {
final name = current.methodName.name;
optional |= name == 'optional';
nullable |= name == 'nullable';
defaulted |= name == 'withDefault';
transform |= oneWayTransformMethods.contains(name);
codec |= name == 'codec';
if (current.methodName.element is TopLevelFunctionElement ||
Expand All @@ -719,9 +704,6 @@ abstract base class ModelGraphBuilderBase {
return SchemaChain(
base: base,
reference: reference,
optional: optional,
nullable: nullable,
defaulted: defaulted,
hasTransform: transform,
hasCodec: codec,
);
Expand Down
Loading
Loading