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

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

{{~#withInterfaces~}}
{{~#operations}}
/**
 * {{classname}} - object-oriented interface
{{~#if description}}
 * {{{description}}}
{{~/if}}
 */
export interface {{classname}}Interface {
{{~#operation}}
    /**
     *
     {{~#if summary}}
     * @summary {{summary}}
     {{~/if}}{{#if hasParams}}
     * @param {*} [params] Request parameters, including pathParams, queryParams (including bodyParams) and http options.{{~/if}}
     * @throws {HttpError}
     */
    {{nickname}}{{#if hasParams}}(params{{#unless (or hasRequiredParams hasAuthMethods hasFormParams)}}?{{/unless}}: { {{~#if pathParams.0}}
        pathParams: { {{#pathParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#unless @last}}; {{/unless}}{{/pathParams}} };{{/if}}{{#if queryParams.0}}
        queryParams?: { {{#queryParams}}{{baseName}}{{^required}}?{{/required}}: {{{dataType}}}{{#unless @last}}; {{/unless}}{{/queryParams}} };{{/if}}{{#if bodyParam}}{{#bodyParam}}
        {{paramName}}{{^required}}?{{/required}}: {{{dataType}}};{{/bodyParam}}{{/if}}{{#hasFormParams}}
        formParams{{^required}}?{{/required}}: { {{#formParams}}{{baseName}}{{^required}}?{{/required}}: {{#if isFile}}Blob{{else}}{{{dataType}}}{{/if}}{{#unless @last}}; {{/unless}}{{/formParams}} };{{/hasFormParams}}{{#hasHeaderParams}}
        headers{{^hasRequiredParams}}?{{/hasRequiredParams}}: { {{#headerParams}}"{{baseName}}"{{^required}}?{{/required}}: string{{#unless @last}}; {{/unless}}{{/headerParams}} };{{/hasHeaderParams}}{{#if authMethods}}{{#authMethods}}{{#if @first}}
        security: {{/if}}{{#if (eq scheme 'none')}}undefined{{else}}{{name}}{{/if}}{{#if @last}};{{else}} | {{/if}}{{/authMethods}}{{/if}}
    } & RequestCallOptions){{else if hasAuthMethods}}(params: {
        security: {{#authMethods}}{{#if (eq scheme 'none')}}undefined{{else}}{{name}}{{/if}}{{#if @last}};{{else}} | {{/if}}{{/authMethods}}
    } & RequestCallOptions){{else}}(params?: RequestCallOptions){{/if}}: {{#if isResponseFile}}Promise{{else if returnType}}Promise<{{{returnType}}}{{#responses}}{{#is2xx}}{{#isNull}}|undefined{{/isNull}}{{/is2xx}}{{/responses}}>{{else}}Promise{{/if}};
{{~/operation}}
}
{{/operations}}{{~/withInterfaces}}
{{~#operations}}
/**
 * {{classname}} - object-oriented interface{{#if description}}
 * {{{description}}}{{/if}}
 */
{{~#withInterfaces}}
export class {{classname}} extends BaseAPI implements {{classname}}Interface {
{{~/withInterfaces}}
{{~^withInterfaces}}
export class {{classname}} extends BaseAPI {
{{~/withInterfaces}}
{{~#operation}}
    /**
     *
     {{~#if summary}}
     * @summary {{&summary}}
     {{~/if}}{{#if hasParams}}
     * @param {*} [params] Request parameters, including pathParams, queryParams (including bodyParams) and http options.{{~/if}}
     * @throws {HttpError}
     */
    public async {{nickname}}{{#if hasParams}}(params{{#unless (or hasRequiredParams hasAuthMethods hasFormParams)}}?{{/unless}}: { {{~#if pathParams.0}}
        pathParams: { {{#pathParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#unless @last}}, {{/unless}}{{/pathParams}} };{{/if}}{{#if queryParams.0}}
        queryParams?: { {{#queryParams}}{{baseName}}{{^required}}?{{/required}}: {{{dataType}}}{{#unless @last}}; {{/unless}}{{/queryParams}} };{{/if}}{{#if bodyParam}}{{#bodyParam}}
        {{paramName}}{{^required}}?{{/required}}: {{{dataType}}};{{/bodyParam}}{{/if}}{{#hasFormParams}}
        formParams{{^required}}?{{/required}}: { {{#formParams}}{{baseName}}{{^required}}?{{/required}}: {{#if isFile}}Blob{{else}}{{{dataType}}}{{/if}}{{#unless @last}}; {{/unless}}{{/formParams}} };{{/hasFormParams}}{{#hasHeaderParams}}
        headers{{^hasRequiredParams}}?{{/hasRequiredParams}}: { {{#headerParams}}"{{baseName}}"{{^required}}?{{/required}}: string{{#unless @last}}; {{/unless}}{{/headerParams}} };{{/hasHeaderParams}}{{#if authMethods}}{{#authMethods}}{{#if @first}}
        security: {{/if}}{{#if (eq scheme 'none')}}undefined{{else}}{{name}}{{/if}}{{#if @last}};{{else}} | {{/if}}{{/authMethods}}{{/if}}
    } & RequestCallOptions){{else if hasAuthMethods}}(params: {
        security: {{#authMethods}}{{#if (eq scheme 'none')}}undefined{{else}}{{name}}{{/if}}{{#if @last}};{{else}} | {{/if}}{{/authMethods}}
    } & RequestCallOptions){{else}}(params: RequestCallOptions = {}){{/if}}: {{#if isResponseFile}}Promise{{else if returnType}}Promise<{{{returnType}}}{{#responses}}{{#is2xx}}{{#isNull}}|undefined{{/isNull}}{{/is2xx}}{{/responses}}>{{else}}Promise{{/if}} {
        {{~#if isResponseFile}}
        const response: Response = await this.fetch(
        {{~else}}
        return await this.fetch(
        {{~/if}}
            {{#if (or pathParams queryParams)}}this.url("{{{path}}}"{{#if pathParams}}, params.pathParams{{else}}, {}{{/if}}{{#if hasQueryParams}}, params?.queryParams, { {{~#queryParams}}{{#unless (eq style "form")}}
                {{baseName}}: { delimiter: "{{#if (eq style "spaceDelimited")}} {{else if (eq style "pipeDelimited")}}|{{else}},{{/if}}"{{#if (eq dataFormat "date")}}, format: "{{dataFormat}}"{{/if}} },
            {{~else if (not isExplode)}}
                {{baseName}}: { explode: false{{#if (eq dataFormat "date")}}, format: "{{dataFormat}}"{{/if}} },
            {{else if (eq dataFormat "date")}}
                {{baseName}}: { format: "{{dataFormat}}" },
            {{/unless}}{{/queryParams~}} }{{/if}}){{else}}this.basePath + "{{{path}}}"{{/if}}{{#if (or (neq httpMethod "GET") hasAuthMethods hasHeaderParams)}},
            {
                ...params,
            {{~#if (neq httpMethod 'GET')}}
                method: "{{httpMethod}}",
            {{~/if}}{{~#if bodyParam}}
                body: {{#if hasRequiredParams}}JSON.stringify(params.{{bodyParam.paramName}}){{else if hasAuthMethods}}JSON.stringify(params.{{bodyParam.paramName}}){{else}}params?.{{bodyParam.paramName}} ? JSON.stringify(params.{{bodyParam.paramName}}) : undefined{{/if}},
            {{~else if hasFormParams}}
                body: this.formData(params.formParams),
            {{~/if}}{{#if (or hasAuthMethods hasConsumes)}}
                headers: {
                    ...this.removeEmpty(params{{#unless (or hasRequiredParams hasAuthMethods hasFormParams)}}?{{/unless}}.headers){{#if hasAuthMethods}},
                    ...params.security?.headers(){{/if}}{{#if hasConsumes}},
                    "Content-Type": {{^consumes}}"application/json"{{/consumes}}{{#consumes}}{{#if @first}}"{{{mediaType}}}"{{/if}}{{/consumes}}{{/if}},
                },{{/if}}
            }{{else}}, params{{/if}}
        );
        {{~#if isResponseFile}}
        return await response.blob();
        {{~/if}}
    }
{{~/operation}}
}
{{~/operations}}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy