diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.service.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.service.mustache index 775612c16a3..f52b7085dbe 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.service.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.service.mustache @@ -102,10 +102,9 @@ export class {{classname}} { } {{/queryParams}} -{{#headers}} +{{#headerParams}} headers.set('{{baseName}}', String({{paramName}})); - -{{/headers}} +{{/headerParams}} // to determine the Content-Type header let consumes: string[] = [ diff --git a/samples/client/petstore/typescript-angular2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular2/default/api/pet.service.ts index 6680fd39ffe..bad3f242aaa 100644 --- a/samples/client/petstore/typescript-angular2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/pet.service.ts @@ -53,6 +53,21 @@ export class PetService { this.basePath = basePath || configuration.basePath || this.basePath; } } + + /** + * + * Extends object by coping non-existing properties. + * @param objA object to be extended + * @param objB source object + */ + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } /** * Add a new pet to the store @@ -227,9 +242,13 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -250,6 +269,7 @@ export class PetService { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } + headers.set('api_key', String(apiKey)); // to determine the Content-Type header let consumes: string[] = [ @@ -274,9 +294,13 @@ export class PetService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -319,9 +343,13 @@ export class PetService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -364,9 +392,13 @@ export class PetService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -397,17 +429,17 @@ export class PetService { 'application/xml' ]; + // authentication (api_key) required + if (this.configuration.apiKey) + { + headers.set('api_key', this.configuration.apiKey); + } // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - // authentication (api_key) required - if (this.configuration.apiKey) - { - headers.set('api_key', this.configuration.apiKey); - } @@ -415,9 +447,13 @@ export class PetService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -461,9 +497,13 @@ export class PetService { method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -520,9 +560,13 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -579,9 +623,13 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } diff --git a/samples/client/petstore/typescript-angular2/default/api/store.service.ts b/samples/client/petstore/typescript-angular2/default/api/store.service.ts index c9979216fca..f8cab0853c8 100644 --- a/samples/client/petstore/typescript-angular2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/store.service.ts @@ -53,6 +53,21 @@ export class StoreService { this.basePath = basePath || configuration.basePath || this.basePath; } } + + /** + * + * Extends object by coping non-existing properties. + * @param objA object to be extended + * @param objB source object + */ + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } /** * Delete purchase order by ID @@ -151,9 +166,13 @@ export class StoreService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -191,9 +210,13 @@ export class StoreService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -231,9 +254,13 @@ export class StoreService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -269,9 +296,13 @@ export class StoreService { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } diff --git a/samples/client/petstore/typescript-angular2/default/api/user.service.ts b/samples/client/petstore/typescript-angular2/default/api/user.service.ts index 51bb7ba908c..f77b0768493 100644 --- a/samples/client/petstore/typescript-angular2/default/api/user.service.ts +++ b/samples/client/petstore/typescript-angular2/default/api/user.service.ts @@ -53,6 +53,21 @@ export class UserService { this.basePath = basePath || configuration.basePath || this.basePath; } } + + /** + * + * Extends object by coping non-existing properties. + * @param objA object to be extended + * @param objB source object + */ + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } /** * Create user @@ -215,9 +230,13 @@ export class UserService { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -253,9 +272,13 @@ export class UserService { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -291,9 +314,13 @@ export class UserService { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -331,9 +358,13 @@ export class UserService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -371,9 +402,13 @@ export class UserService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -414,9 +449,13 @@ export class UserService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -449,9 +488,13 @@ export class UserService { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } @@ -492,9 +535,13 @@ export class UserService { method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - responseType: ResponseContentType.Json + search: queryParameters }); + + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = this.extendObj(requestOptions, extraHttpRequestParams); + } return this.http.request(path, requestOptions); } diff --git a/samples/client/petstore/typescript-angular2/default/index.ts b/samples/client/petstore/typescript-angular2/default/index.ts index d097c728017..c312b70fa3e 100644 --- a/samples/client/petstore/typescript-angular2/default/index.ts +++ b/samples/client/petstore/typescript-angular2/default/index.ts @@ -1,4 +1,5 @@ export * from './api/api'; export * from './model/models'; export * from './variables'; -export * from './configuration'; \ No newline at end of file +export * from './configuration'; +export * from './api.module'; \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/npm/README.md b/samples/client/petstore/typescript-angular2/npm/README.md index d9c9481e210..35dbb6845c0 100644 --- a/samples/client/petstore/typescript-angular2/npm/README.md +++ b/samples/client/petstore/typescript-angular2/npm/README.md @@ -1,4 +1,4 @@ -## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201611081538 +## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201612061154 ### Building @@ -19,7 +19,7 @@ navigate to the folder of your consuming project and run one of next commando's. _published:_ ``` -npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201611081538 --save +npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201612061154 --save ``` _unPublished (not recommended):_ @@ -41,4 +41,4 @@ import { BASE_PATH } from './path-to-swagger-gen-service/index'; bootstrap(AppComponent, [ { provide: BASE_PATH, useValue: 'https://your-web-service.com' }, ]); -``` +``` \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular2/npm/api/pet.service.ts index dfce5fb7cf4..bad3f242aaa 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/pet.service.ts @@ -50,6 +50,7 @@ export class PetService { } if (configuration) { this.configuration = configuration; + this.basePath = basePath || configuration.basePath || this.basePath; } } @@ -268,6 +269,7 @@ export class PetService { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } + headers.set('api_key', String(apiKey)); // to determine the Content-Type header let consumes: string[] = [ @@ -427,17 +429,17 @@ export class PetService { 'application/xml' ]; + // authentication (api_key) required + if (this.configuration.apiKey) + { + headers.set('api_key', this.configuration.apiKey); + } // authentication (petstore_auth) required // oauth required if (this.configuration.accessToken) { headers.set('Authorization', 'Bearer ' + this.configuration.accessToken); } - // authentication (api_key) required - if (this.configuration.apiKey) - { - headers.set('api_key', this.configuration.apiKey); - } diff --git a/samples/client/petstore/typescript-angular2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular2/npm/api/store.service.ts index 323d28bc1cd..f8cab0853c8 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/store.service.ts @@ -50,6 +50,7 @@ export class StoreService { } if (configuration) { this.configuration = configuration; + this.basePath = basePath || configuration.basePath || this.basePath; } } diff --git a/samples/client/petstore/typescript-angular2/npm/api/user.service.ts b/samples/client/petstore/typescript-angular2/npm/api/user.service.ts index efb48cb73c4..f77b0768493 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/user.service.ts @@ -50,6 +50,7 @@ export class UserService { } if (configuration) { this.configuration = configuration; + this.basePath = basePath || configuration.basePath || this.basePath; } } diff --git a/samples/client/petstore/typescript-angular2/npm/configuration.ts b/samples/client/petstore/typescript-angular2/npm/configuration.ts index 94989933b63..ec087d2b0c8 100644 --- a/samples/client/petstore/typescript-angular2/npm/configuration.ts +++ b/samples/client/petstore/typescript-angular2/npm/configuration.ts @@ -1,6 +1,24 @@ +export interface ConfigurationParameters { + apiKey?: string; + username?: string; + password?: string; + accessToken?: string; + basePath?: string; +} + export class Configuration { - apiKey: string; - username: string; - password: string; - accessToken: string; -} \ No newline at end of file + apiKey: string; + username: string; + password: string; + accessToken: string; + basePath: string; + + + constructor(configurationParameters: ConfigurationParameters = {}) { + this.apiKey = configurationParameters.apiKey; + this.username = configurationParameters.username; + this.password = configurationParameters.password; + this.accessToken = configurationParameters.accessToken; + this.basePath = configurationParameters.basePath; + } +} diff --git a/samples/client/petstore/typescript-angular2/npm/index.ts b/samples/client/petstore/typescript-angular2/npm/index.ts index d097c728017..c312b70fa3e 100644 --- a/samples/client/petstore/typescript-angular2/npm/index.ts +++ b/samples/client/petstore/typescript-angular2/npm/index.ts @@ -1,4 +1,5 @@ export * from './api/api'; export * from './model/models'; export * from './variables'; -export * from './configuration'; \ No newline at end of file +export * from './configuration'; +export * from './api.module'; \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/npm/package.json b/samples/client/petstore/typescript-angular2/npm/package.json index 4a0760e7efd..45217928e74 100644 --- a/samples/client/petstore/typescript-angular2/npm/package.json +++ b/samples/client/petstore/typescript-angular2/npm/package.json @@ -1,6 +1,6 @@ { "name": "@swagger/angular2-typescript-petstore", - "version": "0.0.1-SNAPSHOT.201611081538", + "version": "0.0.1-SNAPSHOT.201612061154", "description": "swagger client for @swagger/angular2-typescript-petstore", "author": "Swagger Codegen Contributors", "keywords": [ @@ -10,8 +10,7 @@ "main": "dist/index.js", "typings": "dist/index.d.ts", "scripts": { - "build": "typings install && tsc --outDir dist/", - "postinstall": "npm run build" + "build": "typings install && tsc --outDir dist/" }, "peerDependencies": { "@angular/core": "^2.0.0", @@ -20,7 +19,7 @@ "@angular/compiler": "^2.0.0", "core-js": "^2.4.0", "reflect-metadata": "^0.1.3", - "rxjs": "5.0.0-beta.6", + "rxjs": "5.0.0-beta.12", "zone.js": "^0.6.17" }, "devDependencies": { @@ -31,9 +30,9 @@ "@angular/platform-browser": "^2.0.0", "core-js": "^2.4.0", "reflect-metadata": "^0.1.3", - "rxjs": "5.0.0-beta.6", + "rxjs": "5.0.0-beta.12", "zone.js": "^0.6.17", - "typescript": "^1.8.10", + "typescript": "^2.0.0", "typings": "^1.3.2" }, "publishConfig":{ diff --git a/samples/client/petstore/typescript-angular2/npm/tsconfig.json b/samples/client/petstore/typescript-angular2/npm/tsconfig.json index 07fbdf7e1b1..e1f949692b6 100644 --- a/samples/client/petstore/typescript-angular2/npm/tsconfig.json +++ b/samples/client/petstore/typescript-angular2/npm/tsconfig.json @@ -1,27 +1,28 @@ { - "compilerOptions": { - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "noImplicitAny": false, - "suppressImplicitAnyIndexErrors": true, - "target": "es5", - "module": "commonjs", - "moduleResolution": "node", - "removeComments": true, - "sourceMap": true, - "outDir": "./lib", - "noLib": false, - "declaration": true - }, - "exclude": [ - "node_modules", - "typings/main.d.ts", - "typings/main", - "lib" - ], - "filesGlob": [ - "./model/*.ts", - "./api/*.ts", - "typings/browser.d.ts" - ] + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "outDir": "./lib", + "noLib": false, + "declaration": true + }, + "exclude": [ + "node_modules", + "typings/main.d.ts", + "typings/main", + "lib", + "dist" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts", + "typings/browser.d.ts" + ] }