All Downloads are FREE. Search and download functionalities are using the official Maven repository.

typescript-fetch-api.apiTest.handlebars Maven / Gradle / Ivy

Go to download

OpenAPI-generator for TypeScript interfaces using the browser native fetch API. Generates direct mapping of APIs as interfaces and test-data generators for DTOs

There is a newer version: 0.6.0
Show newest version
/* 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