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

typescript-fetch.apis.mustache Maven / Gradle / Ivy

The newest version!
/* tslint:disable */
/* eslint-disable */
{{>licenseInfo}}

import * as runtime from '../runtime';
{{#imports.0}}
import {
    {{#imports}}
    {{className}},
    {{className}}FromJSON,
    {{className}}ToJSON,
    {{/imports}}
} from '../models';
{{/imports.0}}

{{#operations}}
{{#operation}}
{{#allParams.0}}
export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request {
{{#allParams}}
    {{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}};
{{/allParams}}
}

{{/allParams.0}}
{{/operation}}
{{/operations}}
{{#operations}}
/**
 * {{#description}}{{{description}}}{{/description}}{{^description}}no description{{/description}}
 */
export class {{classname}} extends runtime.BaseAPI {

    {{#operation}}
    /**
     {{#notes}}
     * {{¬es}}
     {{/notes}}
     {{#summary}}
     * {{&summary}}
     {{/summary}}
     */
    async {{nickname}}Raw({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{/allParams.0}}): Promise> {
        {{#allParams}}
        {{#required}}
        if (requestParameters.{{paramName}} === null || requestParameters.{{paramName}} === undefined) {
            throw new runtime.RequiredError('{{paramName}}','Required parameter requestParameters.{{paramName}} was null or undefined when calling {{nickname}}.');
        }

        {{/required}}
        {{/allParams}}
        const queryParameters: runtime.HTTPQuery = {};

        {{#queryParams}}
        {{#isListContainer}}
        if (requestParameters.{{paramName}}) {
            {{#isCollectionFormatMulti}}
            queryParameters['{{baseName}}'] = requestParameters.{{paramName}};
            {{/isCollectionFormatMulti}}
            {{^isCollectionFormatMulti}}
            queryParameters['{{baseName}}'] = requestParameters.{{paramName}}.join(runtime.COLLECTION_FORMATS["{{collectionFormat}}"]);
            {{/isCollectionFormatMulti}}
        }

        {{/isListContainer}}
        {{^isListContainer}}
        if (requestParameters.{{paramName}} !== undefined) {
            {{#isDateTime}}
            queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString();
            {{/isDateTime}}
            {{^isDateTime}}
            {{#isDate}}
            queryParameters['{{baseName}}'] = (requestParameters.{{paramName}} as any).toISOString().substr(0,10);
            {{/isDate}}
            {{^isDate}}
            queryParameters['{{baseName}}'] = requestParameters.{{paramName}};
            {{/isDate}}
            {{/isDateTime}}
        }

        {{/isListContainer}}
        {{/queryParams}}
        const headerParameters: runtime.HTTPHeaders = {};

        {{#bodyParam}}
        {{^consumes}}
        headerParameters['Content-Type'] = 'application/json';

        {{/consumes}}
        {{#consumes.0}}
        headerParameters['Content-Type'] = '{{{mediaType}}}';

        {{/consumes.0}}
        {{/bodyParam}}
        {{#headerParams}}
        {{#isListContainer}}
        if (requestParameters.{{paramName}}) {
            headerParameters['{{baseName}}'] = requestParameters.{{paramName}}.join(runtime.COLLECTION_FORMATS["{{collectionFormat}}"]);
        }

        {{/isListContainer}}
        {{^isListContainer}}
        if (requestParameters.{{paramName}} !== undefined && requestParameters.{{paramName}} !== null) {
            headerParameters['{{baseName}}'] = String(requestParameters.{{paramName}});
        }

        {{/isListContainer}}
        {{/headerParams}}
        {{#authMethods}}
        {{#isBasic}}
        {{#isBasicBasic}}
        if (this.configuration && (this.configuration.username !== undefined || this.configuration.password !== undefined)) {
            headerParameters["Authorization"] = "Basic " + btoa(this.configuration.username + ":" + this.configuration.password);
        }
        {{/isBasicBasic}}
        {{#isBasicBearer}}
        if (this.configuration && this.configuration.accessToken) {
            const token = this.configuration.accessToken;
            const tokenString = typeof token === 'function' ? token("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]) : token;

            if (tokenString) {
                headerParameters["Authorization"] = `Bearer ${tokenString}`;
            }
        }
        {{/isBasicBearer}}
        {{/isBasic}}
        {{#isApiKey}}
        {{#isKeyInHeader}}
        if (this.configuration && this.configuration.apiKey) {
            headerParameters["{{keyParamName}}"] = this.configuration.apiKey("{{keyParamName}}"); // {{name}} authentication
        }

        {{/isKeyInHeader}}
        {{#isKeyInQuery}}
        if (this.configuration && this.configuration.apiKey) {
            queryParameters["{{keyParamName}}"] = this.configuration.apiKey("{{keyParamName}}"); // {{name}} authentication
        }

        {{/isKeyInQuery}}
        {{/isApiKey}}
        {{#isOAuth}}
        if (this.configuration && this.configuration.accessToken) {
            // oauth required
            if (typeof this.configuration.accessToken === 'function') {
                headerParameters["Authorization"] = this.configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}]);
            } else {
                headerParameters["Authorization"] = this.configuration.accessToken;
            }
        }

        {{/isOAuth}}
        {{/authMethods}}
        {{#hasFormParams}}
        const consumes: runtime.Consume[] = [
            {{#consumes}}
            { contentType: '{{{mediaType}}}' },
            {{/consumes}}
        ];
        // @ts-ignore: canConsumeForm may be unused
        const canConsumeForm = runtime.canConsumeForm(consumes);

        let formParams: { append(param: string, value: any): any };
        let useForm = false;
        {{#formParams}}
        {{#isFile}}
        // use FormData to transmit files using content-type "multipart/form-data"
        useForm = canConsumeForm;
        {{/isFile}}
        {{/formParams}}
        if (useForm) {
            formParams = new FormData();
        } else {
            formParams = new URLSearchParams();
        }

        {{#formParams}}
        {{#isListContainer}}
        if (requestParameters.{{paramName}}) {
            {{#isCollectionFormatMulti}}
            requestParameters.{{paramName}}.forEach((element) => {
                formParams.append('{{baseName}}', element as any);
            })
            {{/isCollectionFormatMulti}}
            {{^isCollectionFormatMulti}}
            formParams.append('{{baseName}}', requestParameters.{{paramName}}.join(runtime.COLLECTION_FORMATS["{{collectionFormat}}"]));
            {{/isCollectionFormatMulti}}
        }

        {{/isListContainer}}
        {{^isListContainer}}
        if (requestParameters.{{paramName}} !== undefined) {
            formParams.append('{{baseName}}', requestParameters.{{paramName}} as any);
        }

        {{/isListContainer}}
        {{/formParams}}
        {{/hasFormParams}}
        const response = await this.request({
            path: `{{{path}}}`{{#pathParams}}.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String(requestParameters.{{paramName}}))){{/pathParams}},
            method: '{{httpMethod}}',
            headers: headerParameters,
            query: queryParameters,
            {{#hasBodyParam}}
            {{#bodyParam}}
            {{#isContainer}}
            body: requestParameters.{{paramName}}{{#isListContainer}}{{#items}}{{^isPrimitiveType}}.map({{datatype}}ToJSON){{/isPrimitiveType}}{{/items}}{{/isListContainer}},
            {{/isContainer}}
            {{^isContainer}}
            {{^isPrimitiveType}}
            body: {{dataType}}ToJSON(requestParameters.{{paramName}}),
            {{/isPrimitiveType}}
            {{#isPrimitiveType}}
            body: requestParameters.{{paramName}} as any,
            {{/isPrimitiveType}}
            {{/isContainer}}
            {{/bodyParam}}
            {{/hasBodyParam}}
            {{#hasFormParams}}
            body: formParams,
            {{/hasFormParams}}
        });

        {{#returnType}}
        {{#isResponseFile}}
        return new runtime.BlobApiResponse(response);
        {{/isResponseFile}}
        {{^isResponseFile}}
        {{#returnTypeIsPrimitive}}
        {{#isMapContainer}}
        return new runtime.JSONApiResponse(response);
        {{/isMapContainer}}
        {{#isListContainer}}
        return new runtime.JSONApiResponse(response);
        {{/isListContainer}}
        {{#returnSimpleType}}
        return new runtime.TextApiResponse(response) as any;
        {{/returnSimpleType}}
        {{/returnTypeIsPrimitive}}
        {{^returnTypeIsPrimitive}}
        {{#isListContainer}}
        return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map({{returnBaseType}}FromJSON));
        {{/isListContainer}}
        {{^isListContainer}}
        return new runtime.JSONApiResponse(response, (jsonValue) => {{returnBaseType}}FromJSON(jsonValue));
        {{/isListContainer}}
        {{/returnTypeIsPrimitive}}
        {{/isResponseFile}}
        {{/returnType}}
        {{^returnType}}
        return new runtime.VoidApiResponse(response);
        {{/returnType}}
    }

    /**
     {{#notes}}
     * {{¬es}}
     {{/notes}}
     {{#summary}}
     * {{&summary}}
     {{/summary}}
     */
    {{^useSingleRequestParameter}}
    async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
        {{#returnType}}
        const response = await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}} }{{/allParams.0}});
        return await response.value();
        {{/returnType}}
        {{^returnType}}
        await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}} }{{/allParams.0}});
        {{/returnType}}
    }
    {{/useSingleRequestParameter}}
    {{#useSingleRequestParameter}}
    async {{nickname}}({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{/allParams.0}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
        {{#returnType}}
        const response = await this.{{nickname}}Raw({{#allParams.0}}requestParameters{{/allParams.0}});
        return await response.value();
        {{/returnType}}
        {{^returnType}}
        await this.{{nickname}}Raw({{#allParams.0}}requestParameters{{/allParams.0}});
        {{/returnType}}
    }
    {{/useSingleRequestParameter}}

    {{/operation}}
}
{{/operations}}
{{#hasEnums}}

{{#operations}}
{{#operation}}
{{#allParams}}
{{#isEnum}}
/**
    * @export
    * @enum {string}
    */
export enum {{operationIdCamelCase}}{{enumName}} {
{{#allowableValues}}
    {{#enumVars}}
    {{{name}}} = {{{value}}}{{^-last}},{{/-last}}
    {{/enumVars}}
{{/allowableValues}}
}
{{/isEnum}}
{{/allParams}}
{{/operation}}
{{/operations}}
{{/hasEnums}}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy