Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Observable } from 'rxjs/Observab
import 'rxjs/add/operator/map';

import * as models from '../model/models';
import { BASE_PATH } from '../variables';
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { Configuration } from '../configuration';

/* tslint:disable:no-unused-variable member-ordering */
Expand Down Expand Up @@ -93,15 +93,36 @@ export class {{classname}} {
{{/required}}
{{/allParams}}
{{#queryParams}}
{{#isListContainer}}
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
queryParameters.append('{{baseName}}', <any>element);
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
queryParameters.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']));
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined) {
queryParameters.set('{{baseName}}', <any>{{paramName}});
}
{{/queryParams}}
{{/isListContainer}}

{{/queryParams}}
{{#headerParams}}
{{#isListContainer}}
if ({{paramName}}) {
headers.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']));
}
{{/isListContainer}}
{{^isListContainer}}
headers.set('{{baseName}}', String({{paramName}}));
{{/headerParams}}
{{/isListContainer}}

{{/headerParams}}
// to determine the Content-Type header
let consumes: string[] = [
{{#consumes}}
Expand All @@ -120,51 +141,64 @@ export class {{classname}} {
// authentication ({{name}}) required
{{#isApiKey}}
{{#isKeyInHeader}}
if (this.configuration.apiKey)
{
if (this.configuration.apiKey) {
headers.set('{{keyParamName}}', this.configuration.apiKey);
}

{{/isKeyInHeader}}
{{#isKeyInQuery}}
if (this.configuration.apiKey)
{
if (this.configuration.apiKey) {
formParams.set('{{keyParamName}}', this.configuration.apiKey);
}

{{/isKeyInQuery}}
{{/isApiKey}}
{{#isBasic}}
// http basic authentication required
if (this.configuration.username || this.configuration.password)
{
if (this.configuration.username || this.configuration.password) {
headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password));
}

{{/isBasic}}
{{#isOAuth}}
// oauth required
if (this.configuration.accessToken)
{
if (this.configuration.accessToken) {
let accessToken = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken()
: this.configuration.accessToken;
headers.set('Authorization', 'Bearer ' + accessToken);
}

{{/isOAuth}}
{{/authMethods}}

{{#hasFormParams}}
headers.set('Content-Type', 'application/x-www-form-urlencoded');
{{/hasFormParams}}

{{/hasFormParams}}
{{#bodyParam}}
headers.set('Content-Type', 'application/json');
{{/bodyParam}}

{{/bodyParam}}
{{#formParams}}
{{#isListContainer}}
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
formParams.append('{{baseName}}', <any>element);
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
formParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']));
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined) {
formParams.set('{{baseName}}', <any>{{paramName}});
formParams.set('{{baseName}}', <any>{{paramName}});
}
{{/formParams}}
{{/isListContainer}}

{{/formParams}}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: {{httpMethod}},
headers: headers,
Expand All @@ -184,7 +218,7 @@ export class {{classname}} {

return this.http.request(path, requestOptions);
}

{{/operation}}
}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
{{#apis}}
{{#operations}}
export * from './{{ classname }}';
import { {{ classname }} } from './{{ classname }}';
{{/operations}}
{{/apis}}
export const APIS = [ {{#apis}}{{#operations}}{{ classname }}, {{/operations}}{{/apis}}];
{{/apiInfo}}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import { OpaqueToken } from '@angular/core';

export const BASE_PATH = new OpaqueToken('basePath');
export const BASE_PATH = new OpaqueToken('basePath');
export const COLLECTION_FORMATS = {
'csv': ',',
'tsv': ' ',
'ssv': ' ',
'pipes': '|'
}
Loading