typescript-fetch-api.apiTest.handlebars Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-generator-typescript-fetch-api Show documentation
Show all versions of openapi-generator-typescript-fetch-api Show documentation
OpenAPI-generator for TypeScript interfaces using the browser native fetch API.
Generates direct mapping of APIs as interfaces and test-data generators for DTOs
/* eslint @typescript-eslint/no-unused-vars: off */
{{>licenseInfo}}
import {
{{~#models}}
{{~#model}}
{{classname}},
{{~/model}}
{{~/models}}
} from "../model";
import {
ApplicationApis,
{{~#apiInfo}}{{#apis}}
{{classname}}Interface,
{{~/apis}}{{/apiInfo}}
} from "../api";
function reject(operation: string) {
return () => Promise.reject(new Error("Unexpected function call " + operation));
}
{{#withInterfaces~}}
export function mockApplicationApis({
{{~#apiInfo}}{{#apis}}
{{classVarName}}Api = mock{{classname}}(),
{{~/apis}}{{/apiInfo}}
}: Partial = {}): ApplicationApis {
return { {{#apiInfo}}{{#apis}}{{classVarName}}Api{{#unless @last}}, {{/unless}}{{~/apis}}{{/apiInfo}} };
}
{{~/withInterfaces~}}
{{~#apiInfo}}{{~#apis}}{{~#operations}}
export function mock{{classname}}(
operations: Partial<{{classname}}Interface> = {}
): {{classname}}Interface {
return {
{{~#operation}}
{{nickname}}: operations.{{nickname}} || reject("{{classname}}.{{nickname}}"),
{{~/operation}}
};
}
{{~/operations}}{{~/apis}}{{~/apiInfo}}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy