Skip to content

fix(generator): export the class-owned schema from facades - #282

Merged
leoafarias merged 2 commits into
mainfrom
claude/fix-facade-export
Dec 2, 2026
Merged

leoafarias merged 2 commits into
mainfrom
claude/fix-facade-export

Conversation

@leoafarias

Copy link
Copy Markdown
Collaborator

Summary

Some class-first models declare their own static schema, for example static final schema = RangeSchema.schema.refine(...).describe('...'). For these models, the generated facade's parse, safeParse, fromJson, encode, and safeEncode already use that class-owned X.schema. But toJsonSchema() and toSchemaModel() still exported the generated backing schema. So a .describe(...) or an exportable constraint on X.schema was dropped from the export, and the export described less than parse checks.

This PR makes both export methods use the same schema as parse and encode. XSchema.schema and wireSchema stay the unrefined building block on purpose: a class-owned schema is usually built from XSchema.schema, so returning X.schema there 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's toJsonSchema() and toSchemaModel() use X.schema when the class declares one. Otherwise they use the backing schema, as before.
  • packages/ack_generator/test/integration/ack_infer_runtime_build_test.dart: a new DescribedWindow model with .refine(...).describe('A time window'). The test checks that both exports carry the description and that XSchema.schema stays undescribed. It failed before the fix, with Expected: 'A time window', Actual: <null>.
  • example/lib/class_first_models.g.dart: regenerated. Account.schema is 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.
  • The full generator suite, dart run melos run test:gen --no-select, run once: 851 tests pass.
  • The root dart test test: 80 tests pass. This includes the public snippet compile test.
  • example: build_runner build gives only the one regenerated file above. dart test passes 114 tests, and dart analyze finds no issues.

Generated by Claude Code

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
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T21:55:54.552863Z 45f891c PR opened
🔒 Security Review ✅ Completed 2026-12-02T21:57:27.550053Z 45f891c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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
leoafarias merged commit aac57b8 into main Dec 2, 2026
11 checks passed
@leoafarias
leoafarias deleted the claude/fix-facade-export branch December 2, 2026 22:52
leoafarias pushed a commit that referenced this pull request Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants