Skip to content

feat(generator): add a static schema shorthand to AckInfer models - #174

Merged
leoafarias merged 0 commit into
release/1.7from
feat/short-model-schema-accessor
Sep 29, 2026
Merged

leoafarias merged 0 commit into
release/1.7from
feat/short-model-schema-accessor

Conversation

@leoafarias

@leoafarias leoafarias commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • @AckInfer() models now declare static final schema = $ack.modelSchema. This applies to object models, value models, union bases, and union branches, so Ack.list(Task.schema) replaces Ack.list(Task.$ack.modelSchema). The shorthand has the same type as $ack.modelSchema, is created once, and equals $ack.modelSchema. It can't be identical, because AckModelAdapter.modelSchema builds a new codec on each call.
  • Collision rule: Dart doesn't allow a static and an instance member with the same name, so the generator omits the shorthand when the model has a field named schema or its union discriminator is schema. It also omits it when the annotated declaration is named schema, because the static would shadow the variable the adapter reads. In those cases the generator neither fails nor renames the member, and $ack.modelSchema still works. It also omits the shorthand when the library imports a prefix named schema (for example import 'package:ack/ack.dart' as schema;), because the static would shadow that prefix inside the generated class.
  • The change is additive and non-breaking. $ack, @AckModel() (which already has XSchema.schema), and the frozen @AckType() are unchanged.
  • The regenerated example/lib/*.ack.dart files, docs, llms.txt, and changelogs are updated.

Closes #173

Stack

Rebuilt on the 1.7 release baseline. It no longer inherits #171 or #167, which move to 2.0. Base: release/1.7 (#168). Next in the stack: #164, then #176. After typed copyWith returned to 1.7, one conflict in model_emitter.dart was resolved: the value-model shorthand check uses the existing _valueField helper. Review fix dc85ba8f adds the import-prefix check.

Validation

Validated locally on the combined 1.7 tree (feat/ackmodel-class-description, head 2d632300), which includes every PR in the stack:

  • dart run melos run test --no-select passed. Strict analysis (--fatal-infos) found no issues in all seven packages. Tests passed: ack 1,311, ack_generator 347, ack_firebase_ai 98, ack_mcp_dart 63, ack_json_schema_builder 51, ack_annotations 8, plus the root and example suites.
  • A clean regeneration (delete *.ack.dart/*.g.dart, then melos run build) reproduced the committed output exactly.
  • dart scripts/api_check.dart 1.6.2 reported no breaking changes in any of the six packages. It cannot inspect generated consumer code, so it does not flag the typed copyWith getter; the ack_generator changelog documents that under Breaking.
  • dart scripts/publish_dry_run.dart reported 0 warnings for all six packages. verify_release_tag v1.7.0-beta.1 --skip-ancestry, dart format --set-exit-if-changed, and git diff --check passed.
  • No feat(ack): support Draft 2020-12 runtime import and export #171 or feat(generator): generate models from Draft 2020-12 schemas #167 commit is an ancestor of the stack.
  • Each PR was reviewed by an Opus 5.5 agent (AI-slop review, adversarial change review, and a description check). The blocking findings (constrained Set codegen in chore(release): prepare Ack 1.7.0-beta.2 #168, schema import prefix in feat(generator): add a static schema shorthand to AckInfer models #174) and the non-blocking fixes are included.

New tests:

  • ack_infer_contract_test.dart checks that every model kind emits the shorthand, that each collision case omits it, and that a schema import prefix suppresses it.
  • ack_infer_runtime_build_test.dart builds, analyzes (--fatal-infos), and runs a real consumer. It asserts Node.schema is stable across reads, equals Node.$ack.modelSchema, has the expected static type, composes in Ack.list, and works on value, union, and branch models. It also checks that the colliding models compile and parse through $ack.modelSchema, and that Rule and Draft encode back.

@leoafarias
leoafarias force-pushed the feat/short-model-schema-accessor branch from af76401 to 53e8d0f Compare September 29, 2026 14:09
@leoafarias
leoafarias added this pull request to stack #178 September 29, 2026 14:11
@leoafarias
leoafarias force-pushed the feat/short-model-schema-accessor branch 2 times, most recently from 15974c5 to 6a1337d Compare September 29, 2026 14:55
@leoafarias
leoafarias marked this pull request as ready for review September 29, 2026 15:06
@leoafarias
leoafarias force-pushed the feat/short-model-schema-accessor branch from 6a1337d to dc85ba8 Compare September 29, 2026 15:43
@leoafarias
leoafarias removed this pull request from stack #178 September 29, 2026 16:53
leoafarias added a commit that referenced this pull request Sep 29, 2026
Align the six publishable packages at 1.7.0-beta.1 and move unreleased
notes into the 1.7.0-beta.1 changelog sections. The release includes
shared inference, model adapter schemas, CodecSchema.canEncode, typed
copyWith, stricter constrained-Set validation, the @AckInfer schema
shorthand (#174), generated string-literal escaping (#164), and explicit
schema descriptions (#176). Update PUBLISHING.md for this candidate.

The Draft 2020-12 runtime (#171), JSON Schema-to-Dart generation (#167),
and the decoder error contract (#163) are deferred to 2.0.
@leoafarias leoafarias closed this Sep 29, 2026
@leoafarias
leoafarias force-pushed the feat/short-model-schema-accessor branch from dc85ba8 to edbedc2 Compare September 29, 2026 16:53
@leoafarias
leoafarias merged commit edbedc2 into release/1.7 Sep 29, 2026
@leoafarias
leoafarias deleted the feat/short-model-schema-accessor branch September 29, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generator: add a Model.schema shorthand for Model.$ack.modelSchema

1 participant