Repository navigation
Backlog
Labels
enhancementNew feature or request
Description
Follow-up to the 2.0.0 release-readiness PR #274. Do this after the 2.0.0 PRs merge. Each item is internal: generated output must stay byte-identical (cd example && dart run build_runner build && git diff --exit-code), and error messages must not change unless noted. Paths are under packages/ack_generator/lib/src; search by symbol.
Dead checks after the single tokenizer
After schema-first key tokenization, a Dart field name never contains _ or $ and always starts lowercase. These checks can no longer fire:
- the
_check and the$ack,_fromAckRuntime,_toAckRuntimeentries inackSchemaFirstFieldNameProblemand its reserved set; if (name != node.className) return;inanalyzer/schema_model_graph_builder.dart;- class-first
_reservedMembers, whose only remaining use tests the wire discriminator key.
Duplicated logic
- Discriminator name: computed in six places through
ackSchemaFirstDiscriminatorName(an alias ofackSchemaFirstDartFieldName) and validated three times. This is whybuilders/model_emitter.dartimportsanalyzer/. Store the discriminator's Dart name onAckUnionModelNodeand validate it once. - Set codec text is written in
inference/schema_inference.dartandanalyzer/class_model_graph_builder.dart. Export onesetCodecExpression(list, type). - Fallback type names:
uniqueNameinjson_schema/json_schema_emitter.dartproduces the same result asackSchemaFirstTypeNameSegment. - Member name validation:
_rejectInvalidMemberNamenow only checks the capture field; reuseackSchemaFirstFieldNameProblem. - Static
schemalookups: four separategetGetter('schema')?.isStaticlookups (_validateStaticSchema,_validateUnionStaticSchema,hasStaticSchema,analyzer/custom_schema_resolver.dart). Resolve once into the model metadata. - Configured-options list with
index(...)is duplicated inmodel_generator.dartandanalyzer/schema_model_graph_builder.dart.
Smaller output and consistency
- Pass-through class schemas:
static final schema = XSchema.schema(the documented pattern) now routes the facade throughX.schemafor no gain. Detect the pass-through the way the union check already does and keep usingXSchema.schemadirectly. TypeChecker.typeNamedLiterally('AckRule')is inconsistent with the othertypeNamed(...)checkers.
Diagnostics worth adding
- Generated code uses null-aware collection elements (language 3.8 or later) but the generator does not check the input library's language version. Report a clear error instead of emitting code that fails to compile.
- Library-level declarations named
identical,override, ordeepUnmodifiableJsonMapcan shadow names the generated code uses; only some helper names are checked today.
Done when
The dead checks and duplicates are gone, the example regenerates with no diff, and dart run melos run test:gen --no-select passes (run it once at a time; see AGENTS.md).
Generated by Claude Code
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
leoafarias commentedon Dec 2, 2026
These items come from a review of the generator against
v2.0.0-beta.3. They add to the list above; the review also found theSetcodec duplication, the discriminator-name alias, and the stale_reservedMemberscheck, which the issue already lists. Every item here is internal or affects only generated code, so none of them blocks 2.0.0. Paths are underpackages/ack_generator/lib/src; search by symbol.Names reserved more broadly than needed
_generatedReferences(inanalyzer/schema_first_names.dart) always reservesbool,double,int, andnum. A schema-first key such asdoubleornumis rejected even when no generated field uses that type, and beta.3 accepted it. Reserve a type name only when the generated class refers to it. Accepting these keys later only allows more input, so the change is not breaking.Emitted style hidden by
// ignore_for_file: type=lintIf the ignore is removed and
package:lints/recommendedis applied, the generated output raises these lints:curly_braces_in_flow_control_structures: the bracelessif (...) return false;in the generatedoperator ==(builders/data_class_emitter.dart).unnecessary_this:this.on every field (builders/model_emitter.dart,builders/data_class_emitter.dart).no_leading_underscores_for_local_identifiers:_ackDeclaredKeys(builders/model_emitter.dart). The class-first path names the same thing$ackDeclared(builders/class_model_emitter.dart); use one name in both..map((item) => item)andMapEntry(key, item).Done when the generated example passes
package:lints/recommendedwithout the ignore. Keep the ignore itself; it protects consumers' own lint settings.Small cleanups
ackModelBuilder(builder.dart) is no longer exported, and only tests use it. Move it to the test utilities._ack()is copied in four classes (class_model_emitter.dart,data_class_emitter.dart,model_emitter.dart,schema_inference.dart). Share one helper.RegExps are built on every call (class_model_graph_builder.dart,schema_first_names.dart). Make them top-levelfinals, like_nonAsciiLetter.Diagnostics
@IsUrl,@Validate.*) produces source_gen's generic resolution error with no hint. Name the replacement (@IsUri, theIs…/Has…rules) when one of these names fails to resolve.schemathat calls the facade's ownparse/encode, for example in a codec callback, recurses until aStackOverflowErrorat runtime. Beta.3 accepted this. docs: prepare 2.0 documentation and pin naming conventions #281 documents the rule. A build error is optional, because detecting a call inside a callback needs flow analysis.caseStyleends with an unrelated hint about.describe(...)..schema.jsonfalls back to a value model, the generated comment explains only property-name causes. Other causes, such as a missing$defsentry, get no explanation (same at beta.3).Note on "Pass-through class schemas" above
#282 makes the facade's
toJsonSchema()andtoSchemaModel()useX.schema, the same schemaparseandencodeuse. That fixes a dropped.describe(...)on class-owned schemas. If the pass-through detection lands, apply it to all six facade methods together, so they never use different schemas.Generated by Claude Code
leoafarias commentedon Dec 2, 2026
One more diagnostic, found while reviewing #282:
Nullable class-owned root. Suppose a class declares
static final schema = XSchema.schema.nullable(). ThenXSchema.toJsonSchema()admitsnullandsafeParse(null)succeeds, but the typedXSchema.parse(null)throws aTypeErrorat its!. Theparsefailure also happens onmain. Since fix(generator): export the class-owned schema from facades #282, the export advertisesnullas well. The fix(generator): export the class-owned schema from facades #282 changelog now says to keep a class-ownedschemanon-nullable.A blanket runtime
isNullableguard would be wrong:schema.nullable().withDefault(model)reportsisNullable == true, yetparse(null)correctly returns the default model. A useful check must either reject a root that acceptsnullwithout a default, or recognise.nullable()at build time on a statically resolvable initializer.Generated by Claude Code