Conversation
📝 WalkthroughWalkthroughThis PR normalizes content-type strings and uses regex-based media-type matching in Zod generation, adds a regression test for charset-suffixed media types, and updates generated MSW/faker mocks and Zod snapshot exports across samples/tests. ChangesMedia Type Detection and Code Generation Updates
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@packages/zod/src/index.ts`:
- Around line 1352-1354: The media-type check is too permissive: update the
multipart/form-data match to be anchored so it only matches the exact media type
(not suffixes/prefixes). Change the usage of isMediaType in the formDataContent
selection (variable formDataContent and array contentEntries) to require an
exact match (or adjust isMediaType implementation to use an anchored pattern
such as ^multipart\/form-data$) and apply the same fix to the other occurrence
around the code that mirrors lines 1436-1439 so both branches only match the
exact media type.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 836220aa-3333-4fb3-a03b-f2fda7beffc1
📒 Files selected for processing (60)
packages/zod/src/index.tspackages/zod/src/zod.test.tssamples/angular-app/__snapshots__/api/endpoints-zod/pets/pets.msw.tssamples/angular-app/__snapshots__/api/http-both/pets/pets.msw.tssamples/angular-app/__snapshots__/api/http-client-custom-params/pets/pets.msw.tssamples/angular-app/__snapshots__/api/http-client/pets/pets.msw.tssamples/angular-app/__snapshots__/api/http-resource-zod/pets/pets.msw.tssamples/angular-app/__snapshots__/api/http-resource/pets/pets.msw.tssamples/angular-app/src/api/endpoints-zod/pets/pets.msw.tssamples/angular-app/src/api/http-both/pets/pets.msw.tssamples/angular-app/src/api/http-client-custom-params/pets/pets.msw.tssamples/angular-app/src/api/http-client/pets/pets.msw.tssamples/angular-app/src/api/http-resource-zod/pets/pets.msw.tssamples/angular-app/src/api/http-resource/pets/pets.msw.tssamples/angular-query/__snapshots__/api/endpoints/pets/pets.msw.tssamples/angular-query/src/api/endpoints/pets/pets.msw.tssamples/basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.tssamples/basic/api/endpoints/petstoreFromFileSpecWithTransformer.tssamples/react-app-with-swr/basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/react-app-with-swr/basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/react-app-with-swr/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/react-app-with-swr/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/react-app/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/react-app/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/react-app/src/api/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/react-app/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/react-query/basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/react-query/basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/react-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/solid-start/basic/src/api/endpoints/petstore.faker.tssamples/solid-start/basic/src/api/endpoints/petstore.msw.tssamples/svelte-query/basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/svelte-query/basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/svelte-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/svelte-query/basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/vue-query/vue-query-basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/vue-query/vue-query-basic/__snapshots__/endpoints/petstoreFromFileSpecWithTransformer.msw.tssamples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.faker.tssamples/vue-query/vue-query-basic/src/api/endpoints/petstoreFromFileSpecWithTransformer.msw.tstests/__snapshots__/default/schemas-zod-only/endpoints.tstests/__snapshots__/hono/endpoint-parameters/endpoints.zod.tstests/__snapshots__/hono/petstore-single/endpoints.zod.tstests/__snapshots__/hono/petstore-split-with-handlers/endpoints.zod.tstests/__snapshots__/hono/petstore-split/endpoints.zod.tstests/__snapshots__/hono/petstore-tags-split-with-handlers/pets/pets.zod.tstests/__snapshots__/hono/petstore-tags-split/pets/pets.zod.tstests/__snapshots__/hono/petstore-tags-with-handlers/pets.zod.tstests/__snapshots__/hono/petstore-tags/pets.zod.tstests/__snapshots__/hono/zod-schema-response/endpoints.zod.tstests/__snapshots__/mcp/custom-server/tool-schemas.zod.tstests/__snapshots__/mcp/single/tool-schemas.zod.tstests/__snapshots__/mcp/zod-schema-response/tool-schemas.zod.tstests/__snapshots__/zod/branded-types/branded-types.tstests/__snapshots__/zod/petstore-tags-split/pets/pets.tstests/__snapshots__/zod/petstore/endpoints.tstests/__snapshots__/zod/preprocess/preprocess.tstests/__snapshots__/zod/schemas-false/endpoints.tstests/__snapshots__/zod/split/endpoints.tstests/__snapshots__/zod/tags/pets.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/zod/src/index.ts (1)
1436-1439: 💤 Low valueConsider compiling the regex once for better performance.
The
RegExpis currently created on each invocation of the returned predicate. For better performance, compile it once whenisMediaTypeis called.♻️ Suggested optimization
const isMediaType = - (pattern: string) => - ([contentType]: [string, object]): boolean => - new RegExp(pattern).test(contentType.split(';')[0].trim().toLowerCase()); + (pattern: string) => { + const regex = new RegExp(pattern); + return ([contentType]: [string, object]): boolean => + regex.test(contentType.split(';')[0].trim().toLowerCase()); + };🤖 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 `@packages/zod/src/index.ts` around lines 1436 - 1439, The predicate factory is compiling a new RegExp on every call of the returned function; change isMediaType to compile the regex once when called (e.g. create const re = new RegExp(pattern)) and have the returned predicate use re.test(...) against contentType.split(';')[0].trim().toLowerCase(); update the function signature/name isMediaType and the inner predicate to reference the precompiled regex.
🤖 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.
Nitpick comments:
In `@packages/zod/src/index.ts`:
- Around line 1436-1439: The predicate factory is compiling a new RegExp on
every call of the returned function; change isMediaType to compile the regex
once when called (e.g. create const re = new RegExp(pattern)) and have the
returned predicate use re.test(...) against
contentType.split(';')[0].trim().toLowerCase(); update the function
signature/name isMediaType and the inner predicate to reference the precompiled
regex.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d77a90eb-dfe0-48e7-986d-c3b4f02dec93
📒 Files selected for processing (1)
packages/zod/src/index.ts
|
cc @wadakatu i must be doing something wrong here i have run everything locally including a |
|
Hey @melloware — debugged locally; CI is only upset about a narrow slice of the diff. Fine: the zod fix in Breaking CI: the 38
I couldn't tell from here where those git checkout origin/master -- samples/
bun run nuke:all && bun install
bun run --filter '*' generate-api
git diff samples/If it's easier on your side, happy to open a separate PR with the same fix (the zod change + the legitimate |
|
Yes please i just ran all your steps and its still thinks there is snapshot fix. Can you open a PR with this fix? |
|
One caveat is I am running under Windows WSL not sure if that makes a difference or not? |
|
Opened #3433 with just the zod fix + the legitimate |
Fix #3420
Summary by CodeRabbit
Bug Fixes
application/json; charset=utf-8) and multipart form-data.Tests
Chores
void 0).