typed_llm_generator 0.2.3 copy "typed_llm_generator: ^0.2.3" to clipboard
typed_llm_generator: ^0.2.3 copied to clipboard

build_runner code generator that turns @LlmSchema-annotated classes into JSON Schemas and validated-JSON factories for the typed_llm package.

0.2.3 #

Test-only release: no change to generated output. Nothing in lib/ differs from 0.2.2, so upgrading is optional.

  • Line coverage 89.7% -> 98.4%, via tests for paths that had none:
    • Cycle detection, which previously had no test at all. A class referencing itself, and a Parent <-> Child pair, must both fail with an actionable build error rather than recursing until the stack blows.
    • A class used twice as a sibling (two fields of the same nested type) must still generate — the guard tracks the current path, not every class ever seen, and a regression here would break legal diamond-shaped models.
    • @LlmSchema applied to a non-class, and a class with no unnamed constructor.
    • Nullable nested objects, and List<Nested?>.

0.2.2 #

Fixed #

  • A List<T> of nested @LlmSchema classes generated a Map<String, dynamic> cast inside every property access. Dart promotes the .map parameter after the first cast, so each repeat was an unnecessary_cast warning — appearing in the analyzer output of any project that analyzes generated files, from code the user did not write. The cast is now hoisted into a local:

    // before — one unnecessary_cast per property after the first
    .map((e) => LineItem(
          sku: (e as Map<String, dynamic>)['sku'] as String,
          quantity: ((e as Map<String, dynamic>)['quantity'] as num).toInt(),
        ))
    
    // after
    .map((e) {
      final map = e as Map<String, dynamic>;
      return LineItem(
        sku: map['sku'] as String,
        quantity: (map['quantity'] as num).toInt(),
      );
    })
    

    Only affects generated output; regenerate with build_runner to pick it up.

0.2.1 #

No functional changes.

  • Add an example/ walking through the generator's input and its generated output. pub.dev scored this package 150/160 without one — "Package has an example" was the only deduction; every other section was already full marks.
  • Add a library-level dartdoc to builder.dart.

0.2.0 #

Requires typed_llm ^0.2.0.

Added #

  • Every @LlmSchema() class now also generates $<Class>, a const LlmType<Class> binding <Class>Schema to _$<Class>FromValidatedJson. This is what you pass to Extractor.extract, and it is what makes the call type-safe — see typed_llm's 0.2.0 changelog for the mismatch it rules out.

Changed #

  • <Class>Schema and the generated members now carry dartdoc, so they no longer trip public_member_api_docs in projects that lint generated code.

Existing output is otherwise unchanged: <Class>Schema and _$<Class>FromValidatedJson keep their names and shapes, so a fromValidatedJson wrapper you already wrote still compiles. It is now redundant, though — $<Class> points at the factory directly.

0.1.0 #

Initial release.

  • Requires Dart 3.9 or newer, and builds on the analyzer 2.0 element model (analyzer >=9.0.0 <15.0.0, source_gen ^4, build ^4). The analyzer range is deliberately wide so this generator co-resolves with whatever other codegen packages — freezed, json_serializable — pin in the same app. Verified against analyzer 10.2.0 and 12.1.0, including a resolve alongside freezed 3.x.

  • LlmSchemaGenerator (build.yaml key llm_schema): turns an @LlmSchema()-annotated class into a <Class>Schema JSON Schema constant and a _$<Class>FromValidatedJson factory function.

  • Supports primitives (String, int, double, num, bool), DateTime (as an ISO-8601 date-time string), enums (as a string enum), nullable fields, List<T>, and nested @LlmSchema classes — all resolved recursively and inlined into both the schema and the factory.

  • Works on freezed classes: reads constructor parameters from a redirecting const factory constructor the same way it reads a plain generative one.

  • Clear, actionable build-time errors for unsupported field types, positional constructor parameters, and @LlmField(optional: true) on a non-nullable field.

0
likes
160
points
174
downloads

Documentation

API reference

Publisher

verified publisherdiyalotech.com

Weekly Downloads

build_runner code generator that turns @LlmSchema-annotated classes into JSON Schemas and validated-JSON factories for the typed_llm package.

Repository (GitHub)
View/report issues
Contributing

Topics

#llm #json-schema #build-runner #code-generation

License

MIT (license)

Dependencies

analyzer, build, source_gen, typed_llm

More

Packages that depend on typed_llm_generator