I propose adding support to @kubb/plugin-msw for passing either a data object or a function as a parameter to handlers. This would allow users to customize the behavior of handlers dynamically, making mocking and testing much more flexible.
Example
Here's an example implementation to illustrate the idea:
export function apiKeysUpdateHandler(
data?: ApiKeysUpdateMutationResponse | Function,
options = {}
) {
return http.put('*/api/v2/api-keys/:uuid/', function handler(info) {
if (isFunction(data)) return data(info);
return new Response(
JSON.stringify(createApiKeysUpdateMutationResponse(data)),
{
headers: {
'Content-Type': 'application/json',
},
...options,
}
);
});
}
Use Case
This would enable users to customize handlers as shown below:
What is the problem this feature would solve?
I propose adding support to
@kubb/plugin-msw
for passing either adata
object or a function as a parameter to handlers. This would allow users to customize the behavior of handlers dynamically, making mocking and testing much more flexible.Example
Here's an example implementation to illustrate the idea:
Use Case
This would enable users to customize handlers as shown below:
Benefits
Reference
This feature is inspired by a similar capability in Orval.