Skip to content

Commit 947cfa8

Browse files
committed
chore: improve build
1 parent 3e043e7 commit 947cfa8

4 files changed

Lines changed: 41 additions & 13 deletions

File tree

packages/openapi-ts-tests/msw/v2/__snapshots__/3.1.x/default/types.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ export type ComplexParamsData = {
19791979
readonly key: string | null;
19801980
name: string | null;
19811981
enabled?: boolean;
1982-
type: 'Monkey' | 'Horse' | 'Bird';
1982+
readonly type: 'Monkey' | 'Horse' | 'Bird';
19831983
listOfModels?: Array<ModelWithString> | null;
19841984
listOfStrings?: Array<string> | null;
19851985
parameters: ModelWithString | ModelWithEnum | ModelWithArray | ModelWithDictionary;

packages/openapi-ts/src/plugins/msw/shared/handler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ export function getHandler({
180180

181181
let bodyType: ReturnType<typeof $.type.idx | typeof $.type>;
182182
if (operation.body && symbolDataType) {
183-
bodyType = $.type(symbolDataType).idx($.type.literal('body'));
183+
if (operation.body?.schema.type === 'unknown') {
184+
bodyType = $.type(plugin.external('msw.DefaultBodyType'));
185+
} else {
186+
bodyType = $.type(symbolDataType).idx($.type.literal('body'));
187+
}
184188
} else {
185189
bodyType = $.type('never');
186190
}

packages/openapi-ts/src/plugins/msw/shared/response.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ export function createHttpResponse({
3030
case 'json':
3131
return $(symbolHttpResponse).attr('json').call(body, init);
3232
case 'text':
33-
return $(symbolHttpResponse).attr('text').call(body, init);
33+
return $(symbolHttpResponse)
34+
.attr('text')
35+
.call(
36+
$.ternary($(body).typeofExpr().eq($.literal('string')))
37+
.do(body)
38+
.otherwise($('JSON').attr('stringify').call(body)),
39+
init,
40+
);
3441
case 'void':
3542
return $.new(symbolHttpResponse, body, init);
3643
}

pnpm-lock.yaml

Lines changed: 27 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)