Skip to content

Generator: use the @AckModel class doc comment as the object schema description #175

Closed

Description

@leoafarias

Problem

@AckModel() turns each field's doc comment into that field's schema description, but it ignores the class doc comment. The generated object schema has no description:

/// A task the person can complete.   // not carried today
@AckModel()
final class Task with _$TaskAck {
  const Task({required this.id, required this.title});

  final String id;

  /// What to do.                      // carried today
  final String title;
}
TaskSchema.toJsonSchema()['description']; // null
TaskSchema.schema.description;            // null

@AckModel() has no other way to set an object description, and @AckField has no description: parameter. We pass these schemas to a language model to describe app state, so today we have to repeat each class description by hand next to the model.

Proposal

When an @AckModel() class has a doc comment, use it as the description of the generated object schema:

  • Normalize it the same way as field docs: /// and /** */, with the comment markers removed and the lines joined by spaces.
  • Apply it to the generated object schema and to the model codec, so XSchema.toJsonSchema(), XSchema.schema.description, XSchema.wireSchema.description, and toSchemaModel() all carry it.
  • Unions: the sealed base's doc comment describes the discriminated schema, and each branch's doc comment describes that branch's object in anyOf. Implicit, unannotated branches work the same way.
  • With no doc comment, no description is emitted. The output for undocumented classes doesn't change.
  • When a model is used as a field of another model and the field has its own doc comment, the field doc wins at that property, the same way .describe() layers today. Without a field doc, the nested model's class description appears there.

@AckInfer() needs no change, because its schema is authored directly and .describe() already covers it.

Compatibility

This is additive: no annotation or API changes. After regeneration, classes that already have doc comments gain a description in their generated schema, just as documented fields already do.

Activity

  1. leoafarias commented on Oct 8, 2026

    @leoafarias
    CollaboratorAuthor

    Closed by #176 (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