Repository navigation
Feat/msw plugin restore - #4114
Conversation
|
|
🦋 Changeset detectedLatest commit: 7c8d4d6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — restores the MSW plugin, generating type-safe mock handler factories from OpenAPI specs with support for static values, custom resolver functions, path parameter handling, route specificity sorting, and configurable fallback behavior.
- Add
@hey-api/mswplugin — new code generation plugin inpackages/openapi-ts/src/plugins/msw/that emitsmsw.gen.tswith acreateMswHandlers()factory, per-operation handler functions, and supporting types (ToResponseUnion,RequestHandlerOptions,MswHandlerFactories, etc.) - Add MSW symbols —
packages/openapi-ts/src/symbols/msw.tsregisters external MSW type references (HttpResponse,HttpHandler,HttpResponseResolver,DefaultBodyType,RequestHandlerOptions,http) collectDepssupports array-valued dependencies —packages/shared/src/normalize/value.tsnow recursively collects string values from arrays (needed for MSW'ssourceconfig, which is array-valued)- Plugin registration — wired up in
packages/openapi-ts/src/plugins.ts,config.ts,index.ts, andsymbols/index.tsfollowing existing plugin patterns - Handler sorting by route specificity —
sort.tsensures static routes take precedence over parameterized ones (depth → segment type → declaration order) - Dominant response computation —
computeDominantResponse.tspicks the best 2XX response candidate by media type priority (json > text > binary > void), with example extraction and validation - Path sanitization —
path.tsconverts OpenAPI{param}syntax to MSW:paramformat, escaping existing colons and sanitizing non-word characters in param names - Test coverage — runtime tests (
msw.test.ts), type-level tests (msw-types.test-d.ts), and 60+ snapshot tests across 2.0.x/3.0.x/3.1.x spec versions - Documentation — new
msw.mdxdocs page, VitePress config, README update (moved from "proposals" to "available" section) @hey-api/examplesfix —operation.operationId!→operation.operationId ?? ''to handle nullable operation IDs- Dependency:
[email protected]— added toexamples/openapi-ts-fetchfor test execution
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4114 +/- ##
==========================================
- Coverage 38.54% 38.04% -0.51%
==========================================
Files 633 657 +24
Lines 22028 23166 +1138
Branches 6539 6941 +402
==========================================
+ Hits 8491 8813 +322
- Misses 10938 11560 +622
- Partials 2599 2793 +194
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
ℹ️ Minor suggestion only — one test version mismatch caught.
Reviewed changes — restores the MSW plugin (@hey-api/msw) with a full rewrite following the current plugin architecture. The plugin generates typed MSW v2 handlers from OpenAPI specs, with support for baseUrl configuration, responseFallback (error or passthrough), route specificity sorting, and multiple response format handling.
- Add
@hey-api/mswplugin — new plugin config (config.ts), types (types.ts), imports factory (imports.ts), handler dispatch (plugin.ts,v2/plugin.ts), and shared utilities for handler generation, path sanitization, response computation, and route sorting - Add MSW symbols —
symbols/msw.tsregistersDefaultBodyType,HttpHandler,HttpResponse,HttpResponseResolver,RequestHandlerOptions, andhttpfrom themswpackage - Support array
$dependenciesincollectDeps—packages/shared/src/normalize/value.tsnow walks array-valued dependencies so plugins like MSW that depend onsource(which is an array) resolve correctly - Register plugin —
index.tsaugmentsPluginConfigMap,plugins.tsexportsmswhelper,config.tsregisters default config - Add MSW test project —
packages/openapi-ts-tests/msw/v2/with snapshot tests for 2.0.x, 3.0.x, and 3.1.x specs across multiple scenarios (default, response-example, response-example-disabled, response-types, servers) - Integrate into
openapi-ts-fetchexample — add MSW plugin, generatemsw.gen.ts, add runtime tests and type-level tests with vitest - Update
@hey-api/examplesplugin — guardoperation.operationIdwith?? ''instead of!assertion - Update docs — rewrite
msw.mdxdocumentation page
Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:
packages/openapi-ts-tests/msw/v2/test/2.0.x.test.ts:10491(RIGHT) — line 10491 (RIGHT) is not inside a diff hunk
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
Inline comment that was dropped from the review above (line numbering mismatch on a new file): ℹ️
|
@hey-api/codegen-core
@hey-api/json-schema-ref-parser
@hey-api/nuxt
@hey-api/openapi-python
@hey-api/openapi-ts
@hey-api/shared
@hey-api/spec-types
@hey-api/types
@hey-api/vite-plugin
commit: |

Related #3570