Skip to content

feat: add lazy-aware JSON Schema conversion and regression tests for zod integration#498

Merged
frontegg-david merged 2 commits into
release/1.5.xfrom
fix-zod-schema
Jun 22, 2026
Merged

feat: add lazy-aware JSON Schema conversion and regression tests for zod integration#498
frontegg-david merged 2 commits into
release/1.5.xfrom
fix-zod-schema

Conversation

@alexmercerpo

@alexmercerpo alexmercerpo commented Jun 21, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Fixed JSON Schema generation for lazy Zod schemas by ensuring lazy/proxy schemas are fully realized before conversion, preventing failures and preserving expected schema structure.
  • Tests
    • Added a new test suite covering lazy-aware toJSONSchema behavior, including optional/union handling, correct required fields for optional object properties, and idempotent conversion.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5825f627-7f15-4766-a682-62aa383efedd

📥 Commits

Reviewing files that changed from the base of the PR and between cba04d0 and ddb8a95.

📒 Files selected for processing (1)
  • libs/lazy-zod/src/__tests__/to-json-schema.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/lazy-zod/src/tests/to-json-schema.spec.ts

📝 Walkthrough

Walkthrough

toJSONSchema in libs/lazy-zod/src/index.ts is changed from a direct re-export of zod's function to a local wrapper that calls forceMaterialize(schema) before delegating to zod's converter. A new test file adds four tests covering optional unions, arrays of objects, idempotency, and plain schema conversion.

Changes

lazy-zod toJSONSchema wrapper and tests

Layer / File(s) Summary
toJSONSchema materialization wrapper
libs/lazy-zod/src/index.ts
Adds imports of toJSONSchema (aliased as zodToJSONSchema), ZodType, and forceMaterialize. Replaces the direct re-export with a locally defined export const toJSONSchema that calls forceMaterialize(schema) before delegating to zodToJSONSchema, with casting to preserve upstream typing.
Test suite for lazy-aware toJSONSchema
libs/lazy-zod/src/__tests__/to-json-schema.spec.ts
Adds a describe block with four tests: optional union conversion asserting anyOf shape and required fields; array-of-objects conversion asserting item required fields; idempotency of repeated calls; and baseline conversion of a plain Zod string schema.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A lazy proxy tried to sneak,
Through JSON Schema's parsing streak.
But forceMaterialize said "Not today!"
And turned that phantom schema real.
Now tests run true, no more ordeal! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add lazy-aware JSON Schema conversion and regression tests for zod integration' accurately describes the main changes: adding a lazy-aware wrapper for toJSONSchema and comprehensive test coverage for the lazy-zod integration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-zod-schema

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
libs/lazy-zod/src/index.ts (1)

39-43: 🧹 Nitpick | 🔵 Trivial

Clarify registry support: the wrapper does not auto-materialize lazy schemas within a registry parameter.

Zod v4's toJSONSchema does not have a registry overload; the registry is passed via the params object (second argument). The current wrapper materializes only the schema argument, not lazy schemas nested within a registry passed as params.registry. While no current code uses this pattern, add a test covering registry-based toJSONSchema() calls with lazy schemas, or document that registry support is intentionally unsupported if lazy schemas are present.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/lazy-zod/src/index.ts` around lines 39 - 43, The `toJSONSchema` wrapper
function at line 39-43 only materializes the schema argument via
forceMaterialize(), but does not handle lazy schemas that may be nested within a
registry object passed as part of the params parameter. Either add a test case
that calls `toJSONSchema` with a registry parameter containing lazy schemas to
demonstrate the current behavior, or add a JSDoc comment to the function
clarifying that lazy schemas within a registry are not automatically
materialized and documenting this as an intentional limitation.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@libs/lazy-zod/src/__tests__/to-json-schema.spec.ts`:
- Around line 26-32: Replace the `Record<string, any>` type cast with a stricter
type annotation (use `unknown` or a properly defined schema type) to maintain
strict TypeScript correctness. Additionally, update the test cases to use the
explicit eager Zod export `eagerZ` instead of the current schema definition for
the real-schema cases. Apply this strict-typing cleanup to all locations
mentioned in the comment (lines 26-32, 49-54, and 69-72) to ensure consistent
and type-safe test assertions throughout the file.

---

Nitpick comments:
In `@libs/lazy-zod/src/index.ts`:
- Around line 39-43: The `toJSONSchema` wrapper function at line 39-43 only
materializes the schema argument via forceMaterialize(), but does not handle
lazy schemas that may be nested within a registry object passed as part of the
params parameter. Either add a test case that calls `toJSONSchema` with a
registry parameter containing lazy schemas to demonstrate the current behavior,
or add a JSDoc comment to the function clarifying that lazy schemas within a
registry are not automatically materialized and documenting this as an
intentional limitation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5eda332f-e7a6-41a4-b321-418b4c470d77

📥 Commits

Reviewing files that changed from the base of the PR and between c1740dc and cba04d0.

📒 Files selected for processing (2)
  • libs/lazy-zod/src/__tests__/to-json-schema.spec.ts
  • libs/lazy-zod/src/index.ts

Comment thread libs/lazy-zod/src/__tests__/to-json-schema.spec.ts Outdated
@github-actions

github-actions Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Performance Test Results

Status: ✅ All tests passed

Summary

Project Tests Passed Warnings Failed Leaks
✅ demo-e2e-agents 4 4 0 0 0
✅ demo-e2e-cache 11 11 0 0 0
✅ demo-e2e-codecall 4 4 0 0 0
✅ demo-e2e-config 4 4 0 0 0
✅ demo-e2e-direct 3 3 0 0 0
✅ demo-e2e-elicitation 1 1 0 0 0
✅ demo-e2e-errors 4 4 0 0 0
✅ demo-e2e-hooks 3 3 0 0 0
✅ demo-e2e-multiapp 4 4 0 0 0
✅ demo-e2e-notifications 3 3 0 0 0
✅ demo-e2e-openapi 2 2 0 0 0
✅ demo-e2e-providers 4 4 0 0 0
✅ demo-e2e-public 4 4 0 0 0
✅ demo-e2e-redis 15 15 0 0 0
✅ demo-e2e-remember 4 4 0 0 0
✅ demo-e2e-remote 5 5 0 0 0
✅ demo-e2e-serverless 2 2 0 0 0
✅ demo-e2e-skills 15 15 0 0 0
✅ demo-e2e-standalone 2 2 0 0 0
✅ demo-e2e-transport-recreation 3 3 0 0 0
✅ demo-e2e-ui 4 4 0 0 0

Total: 101 tests across 21 projects

📊 View full report in workflow run


Generated at: 2026-06-22T08:47:38.668Z
Commit: 7d126250

@frontegg-david frontegg-david merged commit adaa276 into release/1.5.x Jun 22, 2026
37 checks passed
@frontegg-david frontegg-david deleted the fix-zod-schema branch June 22, 2026 08:53
@github-actions

Copy link
Copy Markdown
Contributor

Cherry-pick Created

A cherry-pick PR to main has been automatically created.

Please review and merge if this change should also be in main.

If the cherry-pick is not needed, close the PR.

frontegg-david pushed a commit that referenced this pull request Jun 22, 2026
…on tests for zod integration (#499)

Cherry-picked from #498 (merged to release/1.5.x)
Original commit: adaa276

Co-authored-by: agentfront[bot] <agentfront[bot]@users.noreply.github.com>
Co-authored-by: alexmercerpo <251740932+alexmercerpo@users.noreply.github.com>
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