Skip to content

Commit c47a629

Browse files
committed
chore: swap one for pick
1 parent 94cb2aa commit c47a629

2 files changed

Lines changed: 20 additions & 18 deletions

File tree

dev/playground.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const handlers = createMswHandlers({
3232
const server = setupServer(
3333
// ...sourceHandlers,
3434
...handlers.all({
35-
one: {
35+
pick: {
3636
// projectUpdate(info) {
3737
// console.log('Received request for projectUpdate with info:', info);
3838
// },
@@ -80,8 +80,8 @@ const server = setupServer(
8080
// },
8181
},
8282
}),
83-
// handlers.one.projectUpdate(),
84-
handlers.one.globalEvent({
83+
// handlers.pick.projectUpdate(),
84+
handlers.pick.globalEvent({
8585
result: {
8686
directory: 'main',
8787
payload: {

packages/openapi-ts/src/plugins/msw/v2/plugin.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ export const handlerV2: MswPlugin['Handler'] = ({ plugin }) => {
3535
const symbolFactory = plugin.symbol('createMswHandlers');
3636
const symbolHandler = plugin.symbol('Handler');
3737
const symbolInvoke = plugin.symbol('invoke');
38-
const symbolOne = plugin.symbol('one');
38+
const symbolPick = plugin.symbol('pick');
3939
const symbolOverrideValue = plugin.symbol('OverrideValue');
4040
const symbolWrap = plugin.symbol('wrap');
4141

42-
const oneObject = $.object().pretty();
43-
const oneType = $.type.object();
42+
const pickObject = $.object().pretty();
43+
const pickType = $.type.object();
4444
const handlerInfo: Array<HandlerInfo> = [];
4545

4646
plugin.forEach(
@@ -54,12 +54,12 @@ export const handlerV2: MswPlugin['Handler'] = ({ plugin }) => {
5454
});
5555

5656
const name = operation.id;
57-
oneType.prop(name, (p) =>
57+
pickType.prop(name, (p) =>
5858
p
5959
.type($(symbolHandler).typeofType())
6060
.$if(plugin.config.comments && getOperationComment(operation), (f, v) => f.doc(v)),
6161
);
62-
oneObject.prop(name, $(symbolWrap).call(symbolHandler));
62+
pickObject.prop(name, $(symbolWrap).call(symbolHandler));
6363
handlerInfo.push({ name, path: operation.path });
6464
},
6565
{
@@ -68,11 +68,11 @@ export const handlerV2: MswPlugin['Handler'] = ({ plugin }) => {
6868
);
6969

7070
const symbolHandlerFactoriesType = plugin.symbol('MswHandlerFactories');
71-
const handlerFactoriesType = $.type.alias(symbolHandlerFactoriesType).export().type(oneType);
71+
const handlerFactoriesType = $.type.alias(symbolHandlerFactoriesType).export().type(pickType);
7272
plugin.node(handlerFactoriesType);
7373

7474
const factoryResultAll = 'all';
75-
const factoryResultOne = 'one';
75+
const factoryResultPick = 'pick';
7676

7777
const symbolFactoryReturnType = plugin.symbol('CreateMswHandlersResult');
7878
const factoryReturnType = $.type
@@ -87,7 +87,7 @@ export const handlerV2: MswPlugin['Handler'] = ({ plugin }) => {
8787
.func()
8888
.param('options', (p) =>
8989
p.optional().type(
90-
$.type.object().prop('one', (p) =>
90+
$.type.object().prop(factoryResultPick, (p) =>
9191
p.optional().type(
9292
$.type
9393
.mapped('K')
@@ -110,7 +110,7 @@ export const handlerV2: MswPlugin['Handler'] = ({ plugin }) => {
110110
.returns($.type('ReadonlyArray').generic(symbolHttpHandler)),
111111
),
112112
)
113-
.prop(factoryResultOne, (p) => p.type(symbolHandlerFactoriesType)),
113+
.prop(factoryResultPick, (p) => p.type(symbolHandlerFactoriesType)),
114114
);
115115
plugin.node(factoryReturnType);
116116

@@ -145,9 +145,9 @@ export const handlerV2: MswPlugin['Handler'] = ({ plugin }) => {
145145
),
146146
),
147147
),
148-
$.const(symbolOne)
149-
.type($.type(symbolFactoryReturnType).idx($.type.literal(factoryResultOne)))
150-
.assign(oneObject),
148+
$.const(symbolPick)
149+
.type($.type(symbolFactoryReturnType).idx($.type.literal(factoryResultPick)))
150+
.assign(pickObject),
151151
$.const(symbolAll)
152152
.type($.type(symbolFactoryReturnType).idx($.type.literal(factoryResultAll)))
153153
.assign(
@@ -180,18 +180,20 @@ export const handlerV2: MswPlugin['Handler'] = ({ plugin }) => {
180180
.otherwise($('fn').call('override')),
181181
),
182182
),
183-
$.const('overrides').assign($('options').attr('one').coalesce($.object())),
183+
$.const('overrides').assign(
184+
$('options').attr(factoryResultPick).coalesce($.object()),
185+
),
184186
$.array(
185187
...sortHandlers(handlerInfo).map((info) =>
186188
$(symbolInvoke).call(
187-
$(symbolOne).attr(info.name),
189+
$(symbolPick).attr(info.name),
188190
$('overrides').attr(info.name),
189191
),
190192
),
191193
).return(),
192194
),
193195
),
194-
$.object().prop(factoryResultAll, symbolAll).prop(factoryResultOne, symbolOne).return(),
196+
$.object().prop(factoryResultAll, symbolAll).prop(factoryResultPick, symbolPick).return(),
195197
);
196198
plugin.node(factoryFn);
197199
};

0 commit comments

Comments
 (0)