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

typescript-angular.api.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
{{>licenseInfo}}
/// 

/* tslint:disable:no-unused-variable member-ordering */

{{#operations}}
namespace {{package}} {
    'use strict';

{{#description}}
    /**
    * {{&description}}
    */
{{/description}}
    export class {{classname}} {
        protected basePath = '{{basePath}}';
        public defaultHeaders : any = {};

        static $inject: string[] = ['$http', '$httpParamSerializer', 'basePath'];

        constructor(protected $http: ng.IHttpService, protected $httpParamSerializer?: (d: any) => any, basePath?: string) {
            if (basePath !== undefined) {
                this.basePath = basePath;
            }
        }

        private extendObj(objA: T1, objB: T2) {
            for(let key in objB){
                if(objB.hasOwnProperty(key)){
                    objA[key] = objB[key];
                }
            }
            return objA;
        }

{{#operation}}
        /**
         * {{summary}}
         * {{notes}}
         {{#allParams}}* @param {{paramName}} {{description}}
         {{/allParams}}*/
        public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any ) : ng.IHttpPromise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
            const localVarPath = this.basePath + '{{path}}'{{#pathParams}}
                .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}};

            let queryParameters: any = {};
            let headerParams: any = this.extendObj({}, this.defaultHeaders);
{{#hasFormParams}}
            let formParams: any = {};

{{/hasFormParams}}
{{#allParams}}
{{#required}}
            // verify required parameter '{{paramName}}' is not null or undefined
            if ({{paramName}} === null || {{paramName}} === undefined) {
                throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.');
            }
{{/required}}
{{/allParams}}
{{#queryParams}}
            if ({{paramName}} !== undefined) {
                queryParameters['{{baseName}}'] = {{paramName}};
            }

{{/queryParams}}
{{#headerParams}}
            headerParams['{{baseName}}'] = {{paramName}};

{{/headerParams}}
{{#hasFormParams}}
            headerParams['Content-Type'] = 'application/x-www-form-urlencoded';

{{/hasFormParams}}
{{#formParams}}
            formParams['{{baseName}}'] = {{paramName}};

{{/formParams}}
            let httpRequestParams: any = {
                method: '{{httpMethod}}',
                url: localVarPath,
                json: {{#hasFormParams}}false{{/hasFormParams}}{{^hasFormParams}}true{{/hasFormParams}},
                {{#bodyParam}}data: {{paramName}},
                {{/bodyParam}}
                {{#hasFormParams}}data: this.$httpParamSerializer(formParams),
                {{/hasFormParams}}
                params: queryParameters,
                headers: headerParams
            };

            if (extraHttpRequestParams) {
                httpRequestParams = this.extendObj(httpRequestParams, extraHttpRequestParams);
            }

            return this.$http(httpRequestParams);
        }
{{/operation}}
    }
}
{{/operations}}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy