/ack:build-data-classes-with-ackfrom ack
Generates Dart data classes using Ack 2.0's @Schemable and ack_generator, including JSON mapping, copyWith, equality, and validation rules.
Ships in ack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The class is the source of truth: you write a final class and the generator writes its schema, JSON mapping, copyWith, and equality. The fluent schema API itself (presence, constraints, codecs, errors) belongs to the using-ack skill.
Follow the Ack version check before changing dependencies or source.
If needed, run dart pub add 'ack:<constraint>' 'dev:ack_generator:<constraint>' dev:build_runner, substituting the same chosen 2.x constraint for both Ack packages.
In a large package, optionally scope the generator in build.yaml:
targets:
$default:
builders:
ack_generator:ack_generator:
generate_for: [lib/models/**.dart]
Done when dart pub deps shows ack and ack_generator on the same supported 2.x release.
import 'package:ack/ack.dart';
part 'invoice.g.dart';
@Schemable(caseStyle: AckCaseStyle.snake, description: 'A customer invoice.')
final class const Invoice({
@HasMinLength(1) required final String invoiceId,
@IsEmail() required final String customerEmail,
@IsPositive() required final double amount,
final String? notes, // may be omitted or null
final String currency = 'usd', // omitted -> 'usd'; null fails
final JsonMaybe<double> discount = const JsonMaybe.absent(), // keeps omitted vs null
@AckKey('due') required final DateTime dueAt, // ISO string on the wire
required final DateTime issuedAt,
}) with _$InvoiceAck {
static final schema = InvoiceSchema.schema.refine(
(i) => !i.dueAt.isBefore(i.issuedAt),
message: 'due must not be before issued_at',
);
}
The rules that make it build:
part '<file>.g.dart';, a final class (or sealed class for a union) with only final fields, an unnamed or primary constructor, and with _$<Class>Ack. The examples use Dart 3.13 primary constructors; a classic constructor with annotated fields generates identical code.required T means required and non-null. required T? means required, but may be null. Optional T? may be omitted and drops the key on encode when null. A default becomes withDefault. Change only the wire contract with @IsOptional(), @IsRequired(), @IsNotNull().Is… / Has… annotations from package:ack/ack.dart: @HasMin, @HasMax, @IsPositive, @IsNegative, @IsMultipleOf, @HasMinLength, @HasMaxLength, @HasMatch (unanchored), @IsEmail, @IsUrl, @IsUri, @IsUuid, @IsDate, @IsDateTime, @IsIp, @IsNotEmpty, @HasMinItems, @HasMaxItems, @HasUniqueItems. Write these; @Validate.* is deprecated and goes away at 2.0.0.caseStyle: for the whole model (snake, kebab, pascal, screamingSnake), @AckKey('wire') for one field. Use @AckKey, not @JsonKey.@Schemable(description:) or a one-line /// @description ... doc tag.@Schemable(unknownProperties: AckUnknownPropertyPolicy.capture) with a Map<String, Object?> additionalProperties field when you need to round-trip them.String, bool, int, double, num, DateTime (UTC ISO string), Uri, Duration (ms), enums, List<T>, Set<T>, Map<String, T>, Object/Object? (any JSON), nested @Schemable classes, JsonMaybe<T>. Any other type needs a schema: read references/custom-types.md.@Schemable(discriminatorKey: 'type') sealed class with final class branches in the same library (@Schemable(discriminatorValue: 'x') fixes a wire value; otherwise the class name is used).Run dart run build_runner build. For a class-first model the build writes <file>.g.dart with a public <Class>Schema facade (schema, wireSchema, parse, safeParse, fromJson, encode, safeEncode, toJsonSchema, toSchemaModel) and the _$<Class>Ack mixin (toJson, safeToJson, typed copyWith, deep ==/hashCode). A misplaced @Schemable option or an unsupported type fails the build with a message. Fix the source and rebuild; never hand-edit a .g.dart. An analyzer language-version warning in the build log is harmless. build_runner 2.16 has no --delete-conflicting-outputs flag, so a plain build is the whole command.
Invoice.schema.safeParse(json) (or InvoiceSchema.safeParse when there is no refine) and handle Fail. fromJson / parse throw AckException.InvoiceSchema.parse, InvoiceSchema.fromJson, and anything wired to them skip it. Route every load through Invoice.schema when the class has a refine. A refine failure is a SchemaValidationError at path #.Invoice(amount: -1, ...) compiles and runs. For invalid fields, toJson() throws and safeToJson() returns Fail. Until #263 lands, both encode through InvoiceSchema and skip a class-level refine. Use Invoice.schema.safeEncode(invoice) to check both field rules and the refine before storing a form or user edit.JsonMaybe fields with const JsonMaybe.absent() (key omitted), JsonMaybe.value(0.1), or JsonMaybe<double>.value(null) (explicit null on the wire).copyWith(notes: null) clears a nullable field; leaving the argument out keeps it.Ack.list(Invoice.schema), or a field typed Invoice inside another @Schemable class.@Schemable() on a top-level Ack.object / Ack.discriminated), value or scalar roots, recursion with Ack.lazy, or generating models from lib/**.schema.json: read references/schema-first.md.dart run build_runner build succeeds and dart analyze reports no issues and no ack deprecations.toJson() back through Model.schema.parse to an equal value; and, for each rule annotation, presence choice, and refine, parse a payload that breaks it and assert isFail with the expected leaf path (walk SchemaNestedError.errors, see using-ack; the top error.path is #). Watch each failing case actually fail.Model.schema; every encode path that must enforce the refine uses Model.schema.encode / .safeEncode until #263 is fixed.Siblings: using-ack (fluent schemas, errors, JSON Schema, migration), ack-provider-schemas (schemas for MCP and Gemini).
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub btwld/ack --plugin ack3 skills in this plugin
/ack-provider-schemasHand Ack 2.0 schemas to AI providers and validate what comes back. Use when exposing an MCP tool from Dart with ack_mcp_dart (registerAckTool, tool input or output schemas), requesting Gemini structured output through Firebase AI (ack_firebase_ai, responseJsonSchema), or building plain Gemini API function declarations (parametersJsonSchema) or responseJsonSchema from an Ack schema's toJsonSchema()./using-ackAck 2.0 runtime schemas for Dart. Use when validating JSON or maps with package:ack (Ack.object, Ack.string, parse/safeParse, SchemaError), choosing optional/nullable/withDefault, writing refine or codecs, exporting or importing JSON Schema, installing or pinning ack, or migrating Ack 1.x code (@AckModel, @AckInfer, ack_annotations, .ack.dart parts) to 2.0.Other plugins' skills for the same job