Fixing recursive prop issue and supporting ZodNonOptional#2696
Fixing recursive prop issue and supporting ZodNonOptional#2696
ZodNonOptional#2696Conversation
WalkthroughThe changes introduce support for the Changes
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)
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
1e56248 to
bd30c9b
Compare
bd30c9b to
dc6f4b1
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
CHANGELOG.md (1)
7-7: Consistent formatting: backtick theIntegrationreference
For consistency with surrounding entries (e.g., v24.1.0), wrapIntegrationin 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
📒 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
ZodNonOptionalsupport. This is a breaking change for existing clients that may not provide thefeaturesproperty.Ensure that all existing usages of this type have been updated to provide the now-required
featuresproperty.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
$ZodNonOptionaltype handling.
189-194: Excellent unification of optional and non-optional wrapper handling.The approach of extending
onWrappedto handle both$ZodOptionaland$ZodNonOptionalis elegant. Both types simply extract theinnerType, 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
optionalandnonoptionalto theonWrappedproducer, 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
Schema1directly aligns with the updated recursive schema structure.
47-47: Correctly marks features as required.Adding
featuresto 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
titleproperty remains required and the recursive reference toSchema1for features is maintained.The structure maintains type safety while supporting the recursive relationship.
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
Documentation