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

typescript-fetch-api.api.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}},{{#if vendorExtensions.ts-fetch-api-omitted-in-response}}
    {{classname}}Response,{{/if}}{{~#if vendorExtensions.ts-fetch-api-omitted-in-request}}
    {{classname}}Request,{{/if}}{{~/model}}
{{~/models}}
} from "./model";

import { BaseAPI, RequestCallOptions, SecurityScheme } from "./base";

{{#withInterfaces~}}
export interface ApplicationApis {
{{~#apiInfo}}{{#apis}}
    {{classVarName}}Api: {{classname}}Interface;
{{~/apis}}{{/apiInfo}}
}
{{~/withInterfaces}}
{{#apiInfo}}{{#apis}}{{>apiInner}}{{/apis}}{{/apiInfo}}
type ServerNames =
{{~#servers}}
    | "{{#if description}}{{description}}{{else}}default{{/if}}"
{{~/servers}};

export const servers: Record = {
{{~#servers}}
    {{#if description}}"{{description}}"{{else}}default{{/if}}: {
    {{~#apiInfo}}{{#apis}}
        {{classVarName}}Api: new {{classname}}("{{url}}"),
    {{~/apis}}{{/apiInfo}}
    },
{{~/servers}}
};

{{#if authMethods}}{{#authMethods}}
{{~#unless (eq scheme 'none')}}
export class {{name}} implements SecurityScheme {
{{~#if isBasicBasic}}
    constructor(private basicAuthorization: string) {}

    headers(): Record {
        return {
            "Authorization": `Basic ${this.basicAuthorization}`,
        }
    }
{{~else}}
    constructor(private bearerToken: string) {}

    headers(): Record {
        return {
            "Authorization": `Bearer ${this.bearerToken}`,
        }
    }
{{~/if}}
}
{{/unless~}}
{{/authMethods~}}{{/if~}}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy