Skip to content

Commit bc9a50f

Browse files
feat!: update msw peer dependency to latest version (#70)
1 parent 33088be commit bc9a50f

File tree

8 files changed

+29
-21
lines changed

8 files changed

+29
-21
lines changed

.changeset/eight-feet-heal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"openapi-msw": minor
33
---
44

5-
Removed dependency on `openapi-typescript-helpers`. We were depending on an older version without being able to easily update. With this refactoring, your projects should no longer resolve to multiple versions of `openapi-typescript-helpers`.
5+
Removed dependency on _openapi-typescript-helpers_. We were depending on an older version without being able to easily update. With this refactoring, your projects should no longer resolve to multiple versions of _openapi-typescript-helpers_.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-msw": major
3+
---
4+
5+
Updated MSW peer dependency from _v2.0.0_ to _v2.7.0_. This is only a breaking change if you are not already using the latest version of MSW.

.changeset/twenty-tables-allow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-msw": major
3+
---
4+
5+
Renamed `HttpHandlerFactory` type to `OpenApiHttpRequestHandler`. This rename aligns its name with MSW's equivalent `HttpRequestHandler` type.

exports/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ export type { AnyApiSpec, HttpMethod } from "../src/api-spec.js";
22

33
export {
44
createOpenApiHttp,
5-
type HttpHandlerFactory,
65
type HttpOptions,
76
type OpenApiHttpHandlers,
7+
type OpenApiHttpRequestHandler,
88
} from "../src/openapi-http.js";
99

1010
export type {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"release": "changeset publish"
4343
},
4444
"peerDependencies": {
45-
"msw": "^2.0.0"
45+
"msw": "^2.7.0"
4646
},
4747
"devDependencies": {
4848
"@changesets/changelog-github": "^0.5.0",

src/openapi-http.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { http, type RequestHandlerOptions } from "msw";
1+
import { http, type HttpHandler, type RequestHandlerOptions } from "msw";
22
import type { AnyApiSpec, HttpMethod, PathsForMethod } from "./api-spec.js";
33
import { convertToColonPath } from "./path-mapping.js";
44
import {
@@ -7,36 +7,33 @@ import {
77
} from "./response-resolver.js";
88

99
/** HTTP handler factory with type inference for provided api paths. */
10-
export type HttpHandlerFactory<
10+
export type OpenApiHttpRequestHandler<
1111
ApiSpec extends AnyApiSpec,
1212
Method extends HttpMethod,
1313
> = <Path extends PathsForMethod<ApiSpec, Method>>(
1414
path: Path,
1515
resolver: ResponseResolver<ApiSpec, Path, Method>,
1616
options?: RequestHandlerOptions,
17-
) => ReturnType<typeof http.all>;
17+
) => HttpHandler;
1818

1919
function createHttpWrapper<
2020
ApiSpec extends AnyApiSpec,
2121
Method extends HttpMethod,
2222
>(
2323
method: Method,
2424
httpOptions?: HttpOptions,
25-
): HttpHandlerFactory<ApiSpec, Method> {
25+
): OpenApiHttpRequestHandler<ApiSpec, Method> {
2626
return (path, resolver, options) => {
2727
const mswPath = convertToColonPath(path as string, httpOptions?.baseUrl);
2828
const mswResolver = createResolverWrapper(resolver);
2929

30-
// Since TS v5.4 mswResolver errors with "Type 'undefined' is not assignable to type 'RequestBody<ApiSpec, Path, Method>'"
31-
// This assignment is only part of the inner workings and does not leak to the outer type-safety.
32-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
33-
return http[method]<any, any, any>(mswPath, mswResolver, options);
30+
return http[method](mswPath, mswResolver, options);
3431
};
3532
}
3633

3734
/** Collection of enhanced HTTP handler factories for each available HTTP Method. */
3835
export type OpenApiHttpHandlers<ApiSpec extends AnyApiSpec> = {
39-
[Method in HttpMethod]: HttpHandlerFactory<ApiSpec, Method>;
36+
[Method in HttpMethod]: OpenApiHttpRequestHandler<ApiSpec, Method>;
4037
} & { untyped: typeof http };
4138

4239
export interface HttpOptions {

src/response-resolver.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
import type { AsyncResponseResolverReturnType, http } from "msw";
1+
import type {
2+
AsyncResponseResolverReturnType,
3+
HttpResponseResolver,
4+
} from "msw";
25
import type {
36
AnyApiSpec,
47
HttpMethod,
@@ -114,10 +117,8 @@ export type MSWResponseResolver<
114117
ApiSpec extends AnyApiSpec,
115118
Path extends keyof ApiSpec,
116119
Method extends HttpMethod,
117-
> = Parameters<
118-
typeof http.all<
119-
PathParams<ApiSpec, Path, Method>,
120-
RequestBody<ApiSpec, Path, Method>,
121-
ResponseBody<ApiSpec, Path, Method>
122-
>
123-
>[1];
120+
> = HttpResponseResolver<
121+
PathParams<ApiSpec, Path, Method>,
122+
RequestBody<ApiSpec, Path, Method>,
123+
ResponseBody<ApiSpec, Path, Method>
124+
>;

0 commit comments

Comments
 (0)