Open RoCat opened 1 year ago
Another option would be to allow the path to be fully extracted so the route could be mocked in Cypress.
I'm using a combination of https://github.com/anttiviljami/mock-json-schema and https://github.com/APIDevTools/json-schema-ref-parser plus small custom script to generate mock entities for my tests.
As a result, i have mock.ts file containing all entities generated by this library file.
Scheme Example:
/** UpdateUserRequest */
export interface UpdateUserRequest {
/** Firstname */
firstName: string;
/** Lastname */
lastName: string;
/** Timezone */
timezone: string;
/** An enumeration. */
languagePreference: Language;
}
Mock example:
export const mockUpdateUserRequest: UpdateUserRequest = {"firstName":"string","lastName":"string","timezone":"string","languagePreference":Language.EN};
Where Language.EN
is enum.
some fields can be customized, for example for datetime i use valid iso datetime
Hello,
I use swagger-template-typescript to generate all API calls. As I also make some unit / functional tests and need to mock API calls, I sometimes had to wite things like:
As you can notice neither path / query or response are typed... Is there a plan to add mock generator ?
As a "workaround" I currently use extraTemplates option to generate files I need, but I can only generate 1 file per API (no modular) ...
I'm not sure this feature is broadly needed, and my template contains some shortcuts i took for my personnal needs / api, so its not 100% generic.
Anyway here is my template, if that can help someone or be a start for a generic feature: