Repository navigation
fix(generator): export the class-owned schema from facades - #282
Merged
Merged
Conversation
XSchema.toJsonSchema() and toSchemaModel() exported the generated backing schema while parse and encode used the class-owned X.schema, so a .describe(...) or exportable constraint on X.schema was dropped from the export. Use the same schema for both. Regenerate the example. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QEFHxK274pLvHpTn3qqhJG
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
A class-owned schema initializer that read XSchema.toJsonSchema() or toSchemaModel() now recurses because those read X.schema. Point to XSchema.schema.toJsonSchema() instead, and keep the class-owned schema non-nullable because the typed facade parse never returns null. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QEFHxK274pLvHpTn3qqhJG
leoafarias
pushed a commit
that referenced
this pull request
Dec 2, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QEFHxK274pLvHpTn3qqhJG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some class-first models declare their own
static schema, for examplestatic final schema = RangeSchema.schema.refine(...).describe('...'). For these models, the generated facade'sparse,safeParse,fromJson,encode, andsafeEncodealready use that class-ownedX.schema. ButtoJsonSchema()andtoSchemaModel()still exported the generated backing schema. So a.describe(...)or an exportable constraint onX.schemawas dropped from the export, and the export described less thanparsechecks.This PR makes both export methods use the same schema as
parseandencode.XSchema.schemaandwireSchemastay the unrefined building block on purpose: a class-owned schema is usually built fromXSchema.schema, so returningX.schemathere would make that definition refer to itself.This changes generated code only. No public API changes.
Changes
packages/ack_generator/lib/src/builders/class_model_emitter.dart: the facade'stoJsonSchema()andtoSchemaModel()useX.schemawhen the class declares one. Otherwise they use the backing schema, as before.packages/ack_generator/test/integration/ack_infer_runtime_build_test.dart: a newDescribedWindowmodel with.refine(...).describe('A time window'). The test checks that both exports carry the description and thatXSchema.schemastays undescribed. It failed before the fix, withExpected: 'A time window', Actual: <null>.example/lib/class_first_models.g.dart: regenerated.Account.schemais a plain alias, so its exported JSON is unchanged.packages/ack_generator/CHANGELOG.md: a line under Unreleased › Fixed.The docs in #281 already describe the fixed behavior, in Model Code Generation › Custom schemas.
Verification
Run locally with Dart 3.14.0:
dart format --output=none --set-exit-if-changed .: pass.dart run melos run analyze --no-select: pass, no issues in any of the 6 packages.dart run melos run test:gen --no-select, run once: 851 tests pass.dart test test: 80 tests pass. This includes the public snippet compile test.example:build_runner buildgives only the one regenerated file above.dart testpasses 114 tests, anddart analyzefinds no issues.Generated by Claude Code