-
-
Notifications
You must be signed in to change notification settings - Fork 35
v24: Replacing usage of example() method in framework sources
#2954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughIntroduces global example registration for negative schemas to avoid using ZodType.example(), updates result handlers to consume shared schemas, adds an ESLint compatibility rule to flag example() usage, and records the change in the changelog. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant Server
participant ResultHandler
participant GlobalRegistry as GlobalRegistry
Note over Server,ResultHandler: Startup / Module load
Server->>GlobalRegistry: add(defaultNegativeSchema, examples)
Server->>GlobalRegistry: add(arrayNegativeSchema, examples)
Note over Client,ResultHandler: Request handling
Client->>Server: HTTP Request
Server->>ResultHandler: Process result
alt Positive path
ResultHandler-->>Client: Positive response (unchanged)
else Negative path
ResultHandler->>ResultHandler: Select shared negative schema
ResultHandler-->>Client: Negative response using registered schema
end
Note right of GlobalRegistry: Used for example metadata<br/>instead of ZodType.example()
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
eslint.config.js (2)
36-42: Typo in variable name and broaden selector to catch more.example()calls.Rename
compatibilityConerns→compatibilityConcerns. Also, current selector misses optional chaining and computed property calls. Consider the following tweaks.Apply this diff:
-const compatibilityConerns = [ - { - selector: "CallExpression > MemberExpression[property.name='example']", - message: "avoid using example() method to operate without zod plugin", - }, -]; +const compatibilityConcerns = [ + // schema.example() + { + selector: + "CallExpression[callee.type='MemberExpression'][callee.property.name='example']", + message: "avoid using example() method to operate without zod plugin", + }, + // schema?.example() + { + selector: + "ChainExpression > CallExpression[callee.type='MemberExpression'][callee.property.name='example']", + message: "avoid using example() method to operate without zod plugin", + }, + // schema['example']() + { + selector: + "CallExpression[callee.type='MemberExpression'][callee.computed=true][callee.property.value='example']", + message: "avoid using example() method to operate without zod plugin", + }, +];
220-220: Update spread usage after rename.Adjust reference to the corrected variable.
- ...compatibilityConerns, + ...compatibilityConcerns,
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CHANGELOG.md(1 hunks)eslint.config.js(2 hunks)express-zod-api/src/result-handler.ts(4 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-05-28T05:04:40.327Z
Learnt from: RobinTail
PR: RobinTail/express-zod-api#2546
File: express-zod-api/src/io-schema.ts:5-8
Timestamp: 2025-05-28T05:04:40.327Z
Learning: The Base type `object & { [Symbol.iterator]?: never }` in express-zod-api correctly excludes arrays and other iterables from IOSchema. Arrays are properly rejected because they have a defined Symbol.iterator method which conflicts with the never constraint, as demonstrated by TypeScript compiler errors when attempting to assign z.array() to IOSchema.
Applied to files:
express-zod-api/src/result-handler.ts
🔇 Additional comments (5)
CHANGELOG.md (1)
5-11: Changelog entry reads well; scope and rationale are clear.No API breakage implied and the mitigation is explicit. LGTM.
express-zod-api/src/result-handler.ts (4)
98-107: Good: static negative schema + registry examples (no per-call allocations).Typed
examplesviasatisfiesis a nice safety net. This addresses prior memory concerns about re-adding examples.
125-125: Swapping inline negative schema for a shared constant is correct.Keeps the error shape consistent and avoids duplicate registry entries.
144-150: Array negative schema registered once with a canonical example.Matches the handler’s text/plain behavior.
181-181: Negative response now declarestext/plainexplicitly — LGTM.Docs generation should reflect this. .example() appears only in express-zod-api/src/zod-plugin.ts; globalRegistry is imported from "zod/v4" in express-zod-api/src/zts.ts, express-zod-api/src/metadata.ts, and express-zod-api/src/result-handler.ts.
|
✅ QA passed |
RobinTail
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏁 ready
Cherry-picked 3aacc05 , #2954 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Standardized error handling with reusable default and array error schemas, including documented examples. - arrayResultHandler now uses a structured negative configuration (schema + mimeType). - Bug Fixes - Resolved a TypeError occurring in some environments related to generating examples. - Documentation - Added v25.4.1 changelog entry with details and attribution. - Updated README with additional contributor avatars. - Chores - Introduced an ESLint rule to flag incompatible example() usage, improving cross-environment compatibility. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
A user reported that they're having troubles with module augmentation in their environment, but they aren't even using the
example()method. It's found to be used in the framework itself and this PR should fix it, so that the framework would be usable for them even without the plugin features.Summary by CodeRabbit
Bug Fixes
Chores
Documentation