typed_llm_generator 0.2.3
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<->Childpair, 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.
@LlmSchemaapplied to a non-class, and a class with no unnamed constructor.- Nullable nested objects, and
List<Nested?>.
- Cycle detection, which previously had no test at all. A class
referencing itself, and a
0.2.2 #
Fixed #
-
A
List<T>of nested@LlmSchemaclasses generated aMap<String, dynamic>cast inside every property access. Dart promotes the.mapparameter after the first cast, so each repeat was anunnecessary_castwarning — 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_runnerto 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>, aconst LlmType<Class>binding<Class>Schemato_$<Class>FromValidatedJson. This is what you pass toExtractor.extract, and it is what makes the call type-safe — seetyped_llm's 0.2.0 changelog for the mismatch it rules out.
Changed #
<Class>Schemaand the generated members now carry dartdoc, so they no longer trippublic_member_api_docsin 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 alongsidefreezed3.x. -
LlmSchemaGenerator(build.yamlkeyllm_schema): turns an@LlmSchema()-annotated class into a<Class>SchemaJSON Schema constant and a_$<Class>FromValidatedJsonfactory function. -
Supports primitives (
String,int,double,num,bool),DateTime(as an ISO-8601date-timestring), enums (as a stringenum), nullable fields,List<T>, and nested@LlmSchemaclasses — all resolved recursively and inlined into both the schema and the factory. -
Works on freezed classes: reads constructor parameters from a redirecting
const factoryconstructor 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.