zoubingwu / msw-auto-mock

A cli tool to generate random mock data from OpenAPI definition for msw.
246 stars 54 forks source link

Suggestion: typescript, only handlers #15

Closed pikilon closed 1 year ago

pikilon commented 1 year ago

I am very impressed with the library, very useful.

I had to implement it by adding a d.ts file in order to work in my repository. I think it would be a good addition to it.

I also think the library should be decoubled from MSW implementation, so it removes work for you and usage will not add unused code. With this addition in mind we could even have parameters to modify handlers individually to differents tests scenarios.

Thank you again and keep on the good work!

zoubingwu commented 1 year ago

@pikilon hey since v0.11.0 the generated code will have all response in a get function, the name was derived from operationId in the OpenAPI spec, for example:

export function getEnterpriseAdminUpdateOrgName202Response() {
  return {
    message: faker.lorem.slug(1),
    url: faker.internet.url(),
  };
}

I hope this will be helpful.