Skip to content

Fixing recursive prop issue and supporting ZodNonOptional#2696

Merged
RobinTail merged 2 commits intomasterfrom
fix-recursive-prop-issue
Jun 2, 2025
Merged

Fixing recursive prop issue and supporting ZodNonOptional#2696
RobinTail merged 2 commits intomasterfrom
fix-recursive-prop-issue

Conversation

@RobinTail
Copy link
Copy Markdown
Owner

@RobinTail RobinTail commented Jun 2, 2025

Related to #2691
Implementing a better workaround for colinhacks/zod#4592 which turned out to be a limitation of Zod 4.

Summary by CodeRabbit

  • Bug Fixes

    • The user data response now always includes the features property, ensuring it is required rather than optional.
    • Updated the user data schema to reflect features as a required property and adjusted its structure for consistency.
  • Documentation

    • Added a changelog entry for version 24.2.0, highlighting improved support for non-optional schemas in integration generators.

@RobinTail RobinTail added enhancement New feature or request refactoring The better way to achieve the same result external bug it's a bug, but in a dependency labels Jun 2, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2025

Walkthrough

The changes introduce support for the z.nonoptional() schema in the Integration generator and update related type handling. The output schemas, type definitions, and OpenAPI documentation are adjusted to make the features property required and non-optional. Internal schema producer logic is unified for optional and non-optional wrappers.

Changes

File(s) Change Summary
CHANGELOG.md Added changelog entry for version 24.2.0 noting support for z.nonoptional() in the Integration generator.
example/endpoints/retrieve-user.ts Changed features output schema from optional array to required non-optional schema via feature.shape.features.
example/example.client.ts Updated type: features in GetV1UserRetrievePositiveVariant1 from optional to required array property.
example/example.documentation.yaml Made features required in user data; changed Schema1 from recursive object to recursive array of objects.
express-zod-api/src/zts.ts Unified handling of optional/non-optional wrappers; removed onOptional, extended onWrapped to handle both types.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    participant SchemaHandler

    Client->>API: Request user data
    API->>SchemaHandler: Validate and process user schema
    SchemaHandler->>SchemaHandler: Handle .optional() and .nonoptional() with unified logic
    SchemaHandler-->>API: Return user data with required features property
    API-->>Client: Respond with user data (features always present)
Loading

Poem

🐇
The schemas now are neat and tight,
Features required—no option in sight!
With wrappers handled all as one,
The changelog marks what we have done.
Hop along, code, with cheerful cheer—
Our types are clear, the docs sincere!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@RobinTail RobinTail marked this pull request as ready for review June 2, 2025 19:49
@RobinTail RobinTail force-pushed the fix-recursive-prop-issue branch from 1e56248 to bd30c9b Compare June 2, 2025 19:52
@RobinTail RobinTail force-pushed the fix-recursive-prop-issue branch from bd30c9b to dc6f4b1 Compare June 2, 2025 19:56
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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)
CHANGELOG.md (1)

7-7: Consistent formatting: backtick the Integration reference
For consistency with surrounding entries (e.g., v24.1.0), wrap Integration in backticks:

- - Supporting `z.nonoptional()` schema by `Integration` generator.
+ - Supporting `z.nonoptional()` schema by the `Integration` generator.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4eb85b4 and dc6f4b1.

📒 Files selected for processing (5)
  • CHANGELOG.md (1 hunks)
  • example/endpoints/retrieve-user.ts (1 hunks)
  • example/example.client.ts (1 hunks)
  • example/example.documentation.yaml (2 hunks)
  • express-zod-api/src/zts.ts (3 hunks)
🔇 Additional comments (8)
example/example.client.ts (1)

20-20: Breaking change: features property is now required.

The change from optional to required aligns with the new ZodNonOptional support. This is a breaking change for existing clients that may not provide the features property.

Ensure that all existing usages of this type have been updated to provide the now-required features property.

example/endpoints/retrieve-user.ts (1)

32-32: Clever workaround for recursive schema limitations.

The use of feature.shape.features.nonoptional() is an elegant solution for the Zod recursive schema limitation referenced in issue #4592. This approach correctly makes the features array required while maintaining the recursive structure.

The comment referencing the Zod issue provides helpful context for future maintainers.

express-zod-api/src/zts.ts (3)

10-10: Added import for ZodNonOptional support.

The import addition is necessary for the new $ZodNonOptional type handling.


189-194: Excellent unification of optional and non-optional wrapper handling.

The approach of extending onWrapped to handle both $ZodOptional and $ZodNonOptional is elegant. Both types simply extract the innerType, so using a unified producer reduces code duplication and maintains consistency.

This design follows the DRY principle effectively.


262-263: Clean mapping of schema types to unified producer.

The changes correctly map both optional and nonoptional to the onWrapped producer, completing the unification. This ensures consistent handling of wrapped types.

example/example.documentation.yaml (3)

43-43: Updated schema reference for consistency.

The change to reference Schema1 directly aligns with the updated recursive schema structure.


47-47: Correctly marks features as required.

Adding features to the required properties list accurately reflects the schema change from optional to required.


746-756: Schema1 definition properly reflects recursive array structure.

The transformation from object schema to array schema with recursive items correctly represents the new schema design. The title property remains required and the recursive reference to Schema1 for features is maintained.

The structure maintains type safety while supporting the recursive relationship.

Comment thread CHANGELOG.md
@RobinTail RobinTail merged commit 875387c into master Jun 2, 2025
15 checks passed
@RobinTail RobinTail deleted the fix-recursive-prop-issue branch June 2, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request external bug it's a bug, but in a dependency refactoring The better way to achieve the same result

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant