Skip to content

Feat/msw plugin restore - #4114

Merged
mrlubos merged 29 commits into
mainfrom
feat/msw-plugin-restore
Jun 21, 2026
Merged

mrlubos merged 29 commits into
mainfrom
feat/msw-plugin-restore

Conversation

@mrlubos

@mrlubos mrlubos commented Jun 21, 2026

Copy link
Copy Markdown
Member

Related #3570

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@changeset-bot

changeset-bot Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7c8d4d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hey-api/shared Patch
@hey-api/openapi-python Patch
@hey-api/openapi-ts Patch

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

@vercel

vercel Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
web Ready Ready Preview, Comment Jun 21, 2026 7:03am

Request Review

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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/msw plugin — new code generation plugin in packages/openapi-ts/src/plugins/msw/ that emits msw.gen.ts with a createMswHandlers() factory, per-operation handler functions, and supporting types (ToResponseUnion, RequestHandlerOptions, MswHandlerFactories, etc.)
  • Add MSW symbols — packages/openapi-ts/src/symbols/msw.ts registers external MSW type references (HttpResponse, HttpHandler, HttpResponseResolver, DefaultBodyType, RequestHandlerOptions, http)
  • collectDeps supports array-valued dependencies — packages/shared/src/normalize/value.ts now recursively collects string values from arrays (needed for MSW's source config, which is array-valued)
  • Plugin registration — wired up in packages/openapi-ts/src/plugins.ts, config.ts, index.ts, and symbols/index.ts following existing plugin patterns
  • Handler sorting by route specificity — sort.ts ensures static routes take precedence over parameterized ones (depth → segment type → declaration order)
  • Dominant response computation — computeDominantResponse.ts picks the best 2XX response candidate by media type priority (json > text > binary > void), with example extraction and validation
  • Path sanitization — path.ts converts OpenAPI {param} syntax to MSW :param format, 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.mdx docs page, VitePress config, README update (moved from "proposals" to "available" section)
  • @hey-api/examples fix — operation.operationId! → operation.operationId ?? '' to handle nullable operation IDs
  • Dependency: [email protected] — added to examples/openapi-ts-fetch for test execution

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@codecov

codecov Bot commented Jun 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.10879% with 401 lines in your changes missing coverage. Please review.
✅ Project coverage is 38.04%. Comparing base (228f1a7) to head (7c8d4d6).

Files with missing lines Patch % Lines
examples/openapi-ts-fetch/src/client/msw.gen.ts 29.83% 112 Missing and 55 partials ⚠️
...kages/openapi-ts/src/plugins/msw/shared/handler.ts 0.00% 55 Missing and 8 partials ⚠️
...rc/plugins/msw/shared/compute-dominant-response.ts 1.85% 35 Missing and 18 partials ⚠️
packages/openapi-ts/src/plugins/msw/v2/plugin.ts 2.27% 42 Missing and 1 partial ⚠️
packages/openapi-ts/src/plugins/msw/shared/sort.ts 0.00% 14 Missing and 3 partials ⚠️
...ages/openapi-ts/src/plugins/msw/shared/response.ts 0.00% 12 Missing and 1 partial ⚠️
...ackages/openapi-ts/src/plugins/msw/shared/types.ts 0.00% 10 Missing ⚠️
packages/shared/src/normalize/value.ts 0.00% 6 Missing and 3 partials ⚠️
packages/openapi-ts/src/plugins/msw/config.ts 20.00% 6 Missing and 2 partials ⚠️
...openapi-ts/src/plugins/@hey-api/examples/plugin.ts 0.00% 6 Missing ⚠️
... and 4 more
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     
Flag Coverage Δ
unittests 38.04% <16.10%> (-0.51%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mrlubos
mrlubos marked this pull request as ready for review June 21, 2026 06:38

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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/msw plugin — 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.ts registers DefaultBodyType, HttpHandler, HttpResponse, HttpResponseResolver, RequestHandlerOptions, and http from the msw package
  • Support array $dependencies in collectDeps — packages/shared/src/normalize/value.ts now walks array-valued dependencies so plugins like MSW that depend on source (which is an array) resolve correctly
  • Register plugin — index.ts augments PluginConfigMap, plugins.ts exports msw helper, config.ts registers 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-fetch example — add MSW plugin, generate msw.gen.ts, add runtime tests and type-level tests with vitest
  • Update @hey-api/examples plugin — guard operation.operationId with ?? '' instead of ! assertion
  • Update docs — rewrite msw.mdx documentation 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

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pullfrog

pullfrog Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Inline comment that was dropped from the review above (line numbering mismatch on a new file):

ℹ️ packages/openapi-ts-tests/msw/v2/test/2.0.x.test.ts:10: This file uses version = '3.0.x' instead of '2.0.x', so it loads 3.0.x specs and writes snapshots under the 3.0.x/ directory — overlapping with 3.0.x.test.ts. As a result, 2.0.x specs are never tested for the MSW plugin. Switch version to '2.0.x' and add the corresponding 2.0.x snapshot directory.

Pullfrog  | View workflow run | via Pullfrog | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@pkg-pr-new

pkg-pr-new Bot commented Jun 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

@hey-api/codegen-core

npm i https://pkg.pr.new/@hey-api/codegen-core@4114

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/@hey-api/json-schema-ref-parser@4114

@hey-api/nuxt

npm i https://pkg.pr.new/@hey-api/nuxt@4114

@hey-api/openapi-python

npm i https://pkg.pr.new/@hey-api/openapi-python@4114

@hey-api/openapi-ts

npm i https://pkg.pr.new/@hey-api/openapi-ts@4114

@hey-api/shared

npm i https://pkg.pr.new/@hey-api/shared@4114

@hey-api/spec-types

npm i https://pkg.pr.new/@hey-api/spec-types@4114

@hey-api/types

npm i https://pkg.pr.new/@hey-api/types@4114

@hey-api/vite-plugin

npm i https://pkg.pr.new/@hey-api/vite-plugin@4114

commit: 7c8d4d6

@mrlubos
mrlubos merged commit 9adbaa2 into main Jun 21, 2026
10 of 12 checks passed
@mrlubos
mrlubos deleted the feat/msw-plugin-restore branch June 21, 2026 07:38
@hey-api hey-api Bot mentioned this pull request Jun 21, 2026

This branch was successfully deployed

1 active deployment
Preview — 7c8d4d64 Deployed Jun 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants