Skip to content

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

Closed

Description

@leoafarias

Problem

Models generated by @AckInfer() expose their model-valued schema as Model.$ack.modelSchema. When you pass a model schema to another API, or nest it in a list, you write this a lot, and it reads awkwardly. From a downstream app:

parameters: TaskScreen.$ack.modelSchema,
schema: Ack.list(Task.$ack.modelSchema),
parameters: CreateTaskInput.$ack.modelSchema,

Class-first models already have a short form: AccountSchema.schema is the typed model codec.

Proposal

Generate a static schema on every @AckInfer() model (object, value, union base, and union branch), so the code above becomes:

parameters: TaskScreen.schema,
schema: Ack.list(Task.schema),
parameters: CreateTaskInput.schema,

It would be emitted as static final schema = $ack.modelSchema;. It has the same type as $ack.modelSchema (for an object model, AckSchema<Map<String, Object?>, Task>), it is created once, and it equals Task.$ack.modelSchema.

Collision rule

In Dart, a class can't declare a static and an instance member with the same name, so the generator skips the shorthand when:

  • the model has a field whose Dart name is schema;
  • the union's discriminator key is schema, because the base declares it as a getter and every branch inherits it;
  • the annotated schema variable is itself named schema, because a static schema would shadow the variable the adapter reads.

In those cases Model.$ack.modelSchema still works. The generator neither fails nor renames the member, so no existing model stops generating.

Compatibility

The change is additive and non-breaking. $ack, $ack.schema, and $ack.modelSchema stay as they are. @AckModel() already has XSchema.schema, and the deprecated @AckType() is frozen, so neither changes. The validated value models that the JSON Schema builder generates already declare User.schema as the source validator, and they're unchanged too.

Activity

  1. leoafarias commented on Oct 8, 2026

    @leoafarias
    CollaboratorAuthor

    Closed by #174 (shipped in 1.7.0-beta.2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions