From 2e7e25801d18c4109df17ca375d9c8e5a264cbf4 Mon Sep 17 00:00:00 2001 From: Richard Naeve Date: Fri, 13 Jan 2017 16:41:54 +0100 Subject: [PATCH] Issue 4531 (#4539) * ISSUE-4531 Arrays are now serialized according to the different collection formats. All api classes are also exported in a const array to make handling of large api libraries easier. * Added petstore samples * Fixed indentations and coding style --- .../typescript-angular2/api.mustache | 70 ++++++++--- .../typescript-angular2/apis.mustache | 2 + .../typescript-angular2/variables.mustache | 8 +- .../typescript-angular2/default/api/PetApi.ts | 109 ++++++------------ .../default/api/StoreApi.ts | 35 +----- .../default/api/UserApi.ts | 62 ++-------- .../typescript-angular2/default/api/api.ts | 4 + .../typescript-angular2/default/variables.ts | 8 +- .../typescript-angular2/npm/README.md | 4 +- .../typescript-angular2/npm/api/PetApi.ts | 109 ++++++------------ .../typescript-angular2/npm/api/StoreApi.ts | 35 +----- .../typescript-angular2/npm/api/UserApi.ts | 62 ++-------- .../typescript-angular2/npm/api/api.ts | 4 + .../typescript-angular2/npm/package.json | 2 +- .../typescript-angular2/npm/variables.ts | 8 +- 15 files changed, 194 insertions(+), 328 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache index 8700083b63d..d62224930ef 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache @@ -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 */ @@ -93,15 +93,36 @@ export class {{classname}} { {{/required}} {{/allParams}} {{#queryParams}} + {{#isListContainer}} + if ({{paramName}}) { + {{#isCollectionFormatMulti}} + {{paramName}}.forEach((element) => { + queryParameters.append('{{baseName}}', element); + }) + {{/isCollectionFormatMulti}} + {{^isCollectionFormatMulti}} + queryParameters.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); + {{/isCollectionFormatMulti}} + } + {{/isListContainer}} + {{^isListContainer}} if ({{paramName}} !== undefined) { queryParameters.set('{{baseName}}', {{paramName}}); } + {{/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}} @@ -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}} - {{#formParams}} - if ({{paramName}} !== undefined) { - formParams.set('{{baseName}}', {{paramName}}); + {{#isListContainer}} + if ({{paramName}}) { + {{#isCollectionFormatMulti}} + {{paramName}}.forEach((element) => { + formParams.append('{{baseName}}', element); + }) + {{/isCollectionFormatMulti}} + {{^isCollectionFormatMulti}} + formParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); + {{/isCollectionFormatMulti}} } -{{/formParams}} + {{/isListContainer}} + {{^isListContainer}} + if ({{paramName}} !== undefined) { + formParams.set('{{baseName}}', {{paramName}}); + } + {{/isListContainer}} +{{/formParams}} let requestOptions: RequestOptionsArgs = new RequestOptions({ method: {{httpMethod}}, headers: headers, @@ -184,7 +218,7 @@ export class {{classname}} { return this.http.request(path, requestOptions); } - + {{/operation}} } {{/operations}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache index 9a39b864538..85522cf6c58 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache @@ -2,6 +2,8 @@ {{#apis}} {{#operations}} export * from './{{ classname }}'; +import { {{ classname }} } from './{{ classname }}'; {{/operations}} {{/apis}} +export const APIS = [ {{#apis}}{{#operations}}{{ classname }}, {{/operations}}{{/apis}}]; {{/apiInfo}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/variables.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/variables.mustache index 27b987e9b23..944e688f1b1 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/variables.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/variables.mustache @@ -1,3 +1,9 @@ import { OpaqueToken } from '@angular/core'; -export const BASE_PATH = new OpaqueToken('basePath'); \ No newline at end of file +export const BASE_PATH = new OpaqueToken('basePath'); +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/default/api/PetApi.ts b/samples/client/petstore/typescript-angular2/default/api/PetApi.ts index 5751b452369..535d21d66d0 100644 --- a/samples/client/petstore/typescript-angular2/default/api/PetApi.ts +++ b/samples/client/petstore/typescript-angular2/default/api/PetApi.ts @@ -19,7 +19,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 */ @@ -199,8 +199,6 @@ export class PetApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ 'application/json', @@ -215,18 +213,15 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -241,7 +236,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Deletes a pet * @@ -257,7 +252,6 @@ export class PetApi { if (petId === null || petId === undefined) { 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 @@ -272,16 +266,12 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, @@ -296,7 +286,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -307,11 +297,12 @@ export class PetApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (status !== undefined) { - queryParameters.set('status', status); + if (status) { + status.forEach((element) => { + queryParameters.append('status', element); + }) } - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -324,16 +315,12 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -348,7 +335,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -359,11 +346,12 @@ export class PetApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (tags !== undefined) { - queryParameters.set('tags', tags); + if (tags) { + tags.forEach((element) => { + queryParameters.append('tags', element); + }) } - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -376,16 +364,12 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -400,7 +384,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Find pet by ID * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions @@ -415,8 +399,6 @@ export class PetApi { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -427,23 +409,19 @@ export class PetApi { '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) - { + if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; headers.set('Authorization', 'Bearer ' + accessToken); } - // authentication (api_key) required - if (this.configuration.apiKey) - { - headers.set('api_key', this.configuration.apiKey); - } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -458,7 +436,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Update an existing pet * @@ -469,8 +447,6 @@ export class PetApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ 'application/json', @@ -485,18 +461,15 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, @@ -511,7 +484,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Updates a pet in the store with form data * @@ -530,8 +503,6 @@ export class PetApi { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } - - // to determine the Content-Type header let consumes: string[] = [ 'application/x-www-form-urlencoded' @@ -545,22 +516,21 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - + headers.set('Content-Type', 'application/x-www-form-urlencoded'); - if (name !== undefined) { - formParams.set('name', name); + formParams.set('name', name); } + if (status !== undefined) { - formParams.set('status', status); + formParams.set('status', status); } let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -577,7 +547,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * uploads an image * @@ -596,8 +566,6 @@ export class PetApi { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } - - // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data' @@ -611,22 +579,21 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - + headers.set('Content-Type', 'application/x-www-form-urlencoded'); - if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams.set('additionalMetadata', additionalMetadata); } + if (file !== undefined) { - formParams.set('file', file); + formParams.set('file', file); } let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -643,5 +610,5 @@ export class PetApi { return this.http.request(path, requestOptions); } - + } diff --git a/samples/client/petstore/typescript-angular2/default/api/StoreApi.ts b/samples/client/petstore/typescript-angular2/default/api/StoreApi.ts index 484d5e56fde..344d1f1b257 100644 --- a/samples/client/petstore/typescript-angular2/default/api/StoreApi.ts +++ b/samples/client/petstore/typescript-angular2/default/api/StoreApi.ts @@ -19,7 +19,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 */ @@ -133,8 +133,6 @@ export class StoreApi { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -145,10 +143,6 @@ export class StoreApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -162,7 +156,7 @@ export class StoreApi { return this.http.request(path, requestOptions); } - + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -172,8 +166,6 @@ export class StoreApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -185,13 +177,9 @@ export class StoreApi { ]; // authentication (api_key) required - if (this.configuration.apiKey) - { + if (this.configuration.apiKey) { headers.set('api_key', this.configuration.apiKey); } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -206,7 +194,7 @@ export class StoreApi { return this.http.request(path, requestOptions); } - + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -221,8 +209,6 @@ export class StoreApi { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -233,10 +219,6 @@ export class StoreApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -250,7 +232,7 @@ export class StoreApi { return this.http.request(path, requestOptions); } - + /** * Place an order for a pet * @@ -261,8 +243,6 @@ export class StoreApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -273,11 +253,8 @@ export class StoreApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -292,5 +269,5 @@ export class StoreApi { return this.http.request(path, requestOptions); } - + } diff --git a/samples/client/petstore/typescript-angular2/default/api/UserApi.ts b/samples/client/petstore/typescript-angular2/default/api/UserApi.ts index 8dda0cf8377..bb7884ea636 100644 --- a/samples/client/petstore/typescript-angular2/default/api/UserApi.ts +++ b/samples/client/petstore/typescript-angular2/default/api/UserApi.ts @@ -19,7 +19,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 */ @@ -195,8 +195,6 @@ export class UserApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -207,11 +205,8 @@ export class UserApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -226,7 +221,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Creates list of users with given input array * @@ -237,8 +232,6 @@ export class UserApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -249,11 +242,8 @@ export class UserApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -268,7 +258,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Creates list of users with given input array * @@ -279,8 +269,6 @@ export class UserApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -291,11 +279,8 @@ export class UserApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -310,7 +295,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Delete user * This can only be done by the logged in user. @@ -325,8 +310,6 @@ export class UserApi { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -337,10 +320,6 @@ export class UserApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -354,7 +333,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Get user by user name * @@ -369,8 +348,6 @@ export class UserApi { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -381,10 +358,6 @@ export class UserApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -398,7 +371,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Logs user into the system * @@ -413,11 +386,11 @@ export class UserApi { if (username !== undefined) { queryParameters.set('username', username); } + if (password !== undefined) { queryParameters.set('password', password); } - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -428,10 +401,6 @@ export class UserApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -445,7 +414,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Logs out current logged in user session * @@ -455,8 +424,6 @@ export class UserApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -467,10 +434,6 @@ export class UserApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -484,7 +447,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Updated user * This can only be done by the logged in user. @@ -500,8 +463,6 @@ export class UserApi { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -512,11 +473,8 @@ export class UserApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, @@ -531,5 +489,5 @@ export class UserApi { return this.http.request(path, requestOptions); } - + } diff --git a/samples/client/petstore/typescript-angular2/default/api/api.ts b/samples/client/petstore/typescript-angular2/default/api/api.ts index 056206bfaca..0d1e9f047fd 100644 --- a/samples/client/petstore/typescript-angular2/default/api/api.ts +++ b/samples/client/petstore/typescript-angular2/default/api/api.ts @@ -1,3 +1,7 @@ export * from './PetApi'; +import { PetApi } from './PetApi'; export * from './StoreApi'; +import { StoreApi } from './StoreApi'; export * from './UserApi'; +import { UserApi } from './UserApi'; +export const APIS = [ PetApi, StoreApi, UserApi, ]; diff --git a/samples/client/petstore/typescript-angular2/default/variables.ts b/samples/client/petstore/typescript-angular2/default/variables.ts index 27b987e9b23..944e688f1b1 100644 --- a/samples/client/petstore/typescript-angular2/default/variables.ts +++ b/samples/client/petstore/typescript-angular2/default/variables.ts @@ -1,3 +1,9 @@ import { OpaqueToken } from '@angular/core'; -export const BASE_PATH = new OpaqueToken('basePath'); \ No newline at end of file +export const BASE_PATH = new OpaqueToken('basePath'); +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} \ 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 5f176a7b484..b1cac56e5e8 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.201612150011 +## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201701111439 ### 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.201612150011 --save +npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201701111439 --save ``` _unPublished (not recommended):_ diff --git a/samples/client/petstore/typescript-angular2/npm/api/PetApi.ts b/samples/client/petstore/typescript-angular2/npm/api/PetApi.ts index 5751b452369..535d21d66d0 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/PetApi.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/PetApi.ts @@ -19,7 +19,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 */ @@ -199,8 +199,6 @@ export class PetApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ 'application/json', @@ -215,18 +213,15 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -241,7 +236,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Deletes a pet * @@ -257,7 +252,6 @@ export class PetApi { if (petId === null || petId === undefined) { 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 @@ -272,16 +266,12 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, @@ -296,7 +286,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Finds Pets by status * Multiple status values can be provided with comma separated strings @@ -307,11 +297,12 @@ export class PetApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (status !== undefined) { - queryParameters.set('status', status); + if (status) { + status.forEach((element) => { + queryParameters.append('status', element); + }) } - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -324,16 +315,12 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -348,7 +335,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Finds Pets by tags * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. @@ -359,11 +346,12 @@ export class PetApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (tags !== undefined) { - queryParameters.set('tags', tags); + if (tags) { + tags.forEach((element) => { + queryParameters.append('tags', element); + }) } - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -376,16 +364,12 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -400,7 +384,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Find pet by ID * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions @@ -415,8 +399,6 @@ export class PetApi { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -427,23 +409,19 @@ export class PetApi { '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) - { + if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; headers.set('Authorization', 'Bearer ' + accessToken); } - // authentication (api_key) required - if (this.configuration.apiKey) - { - headers.set('api_key', this.configuration.apiKey); - } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -458,7 +436,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Update an existing pet * @@ -469,8 +447,6 @@ export class PetApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ 'application/json', @@ -485,18 +461,15 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, @@ -511,7 +484,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * Updates a pet in the store with form data * @@ -530,8 +503,6 @@ export class PetApi { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } - - // to determine the Content-Type header let consumes: string[] = [ 'application/x-www-form-urlencoded' @@ -545,22 +516,21 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - + headers.set('Content-Type', 'application/x-www-form-urlencoded'); - if (name !== undefined) { - formParams.set('name', name); + formParams.set('name', name); } + if (status !== undefined) { - formParams.set('status', status); + formParams.set('status', status); } let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -577,7 +547,7 @@ export class PetApi { return this.http.request(path, requestOptions); } - + /** * uploads an image * @@ -596,8 +566,6 @@ export class PetApi { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } - - // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data' @@ -611,22 +579,21 @@ export class PetApi { // authentication (petstore_auth) required // 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); } - + headers.set('Content-Type', 'application/x-www-form-urlencoded'); - if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams.set('additionalMetadata', additionalMetadata); } + if (file !== undefined) { - formParams.set('file', file); + formParams.set('file', file); } let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -643,5 +610,5 @@ export class PetApi { return this.http.request(path, requestOptions); } - + } diff --git a/samples/client/petstore/typescript-angular2/npm/api/StoreApi.ts b/samples/client/petstore/typescript-angular2/npm/api/StoreApi.ts index 484d5e56fde..344d1f1b257 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/StoreApi.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/StoreApi.ts @@ -19,7 +19,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 */ @@ -133,8 +133,6 @@ export class StoreApi { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -145,10 +143,6 @@ export class StoreApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -162,7 +156,7 @@ export class StoreApi { return this.http.request(path, requestOptions); } - + /** * Returns pet inventories by status * Returns a map of status codes to quantities @@ -172,8 +166,6 @@ export class StoreApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -185,13 +177,9 @@ export class StoreApi { ]; // authentication (api_key) required - if (this.configuration.apiKey) - { + if (this.configuration.apiKey) { headers.set('api_key', this.configuration.apiKey); } - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -206,7 +194,7 @@ export class StoreApi { return this.http.request(path, requestOptions); } - + /** * Find purchase order by ID * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions @@ -221,8 +209,6 @@ export class StoreApi { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -233,10 +219,6 @@ export class StoreApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -250,7 +232,7 @@ export class StoreApi { return this.http.request(path, requestOptions); } - + /** * Place an order for a pet * @@ -261,8 +243,6 @@ export class StoreApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -273,11 +253,8 @@ export class StoreApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -292,5 +269,5 @@ export class StoreApi { return this.http.request(path, requestOptions); } - + } diff --git a/samples/client/petstore/typescript-angular2/npm/api/UserApi.ts b/samples/client/petstore/typescript-angular2/npm/api/UserApi.ts index 8dda0cf8377..bb7884ea636 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/UserApi.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/UserApi.ts @@ -19,7 +19,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 */ @@ -195,8 +195,6 @@ export class UserApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -207,11 +205,8 @@ export class UserApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -226,7 +221,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Creates list of users with given input array * @@ -237,8 +232,6 @@ export class UserApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -249,11 +242,8 @@ export class UserApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -268,7 +258,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Creates list of users with given input array * @@ -279,8 +269,6 @@ export class UserApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -291,11 +279,8 @@ export class UserApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, @@ -310,7 +295,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Delete user * This can only be done by the logged in user. @@ -325,8 +310,6 @@ export class UserApi { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -337,10 +320,6 @@ export class UserApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -354,7 +333,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Get user by user name * @@ -369,8 +348,6 @@ export class UserApi { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -381,10 +358,6 @@ export class UserApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -398,7 +371,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Logs user into the system * @@ -413,11 +386,11 @@ export class UserApi { if (username !== undefined) { queryParameters.set('username', username); } + if (password !== undefined) { queryParameters.set('password', password); } - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -428,10 +401,6 @@ export class UserApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -445,7 +414,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Logs out current logged in user session * @@ -455,8 +424,6 @@ export class UserApi { let queryParameters = new URLSearchParams(); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -467,10 +434,6 @@ export class UserApi { 'application/xml' ]; - - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -484,7 +447,7 @@ export class UserApi { return this.http.request(path, requestOptions); } - + /** * Updated user * This can only be done by the logged in user. @@ -500,8 +463,6 @@ export class UserApi { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - - // to determine the Content-Type header let consumes: string[] = [ ]; @@ -512,11 +473,8 @@ export class UserApi { 'application/xml' ]; - - headers.set('Content-Type', 'application/json'); - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, @@ -531,5 +489,5 @@ export class UserApi { return this.http.request(path, requestOptions); } - + } diff --git a/samples/client/petstore/typescript-angular2/npm/api/api.ts b/samples/client/petstore/typescript-angular2/npm/api/api.ts index 056206bfaca..0d1e9f047fd 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/api.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/api.ts @@ -1,3 +1,7 @@ export * from './PetApi'; +import { PetApi } from './PetApi'; export * from './StoreApi'; +import { StoreApi } from './StoreApi'; export * from './UserApi'; +import { UserApi } from './UserApi'; +export const APIS = [ PetApi, StoreApi, UserApi, ]; diff --git a/samples/client/petstore/typescript-angular2/npm/package.json b/samples/client/petstore/typescript-angular2/npm/package.json index 6dd91bb3f86..e6d3d71d494 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.201612150011", + "version": "0.0.1-SNAPSHOT.201701111439", "description": "swagger client for @swagger/angular2-typescript-petstore", "author": "Swagger Codegen Contributors", "keywords": [ diff --git a/samples/client/petstore/typescript-angular2/npm/variables.ts b/samples/client/petstore/typescript-angular2/npm/variables.ts index 27b987e9b23..944e688f1b1 100644 --- a/samples/client/petstore/typescript-angular2/npm/variables.ts +++ b/samples/client/petstore/typescript-angular2/npm/variables.ts @@ -1,3 +1,9 @@ import { OpaqueToken } from '@angular/core'; -export const BASE_PATH = new OpaqueToken('basePath'); \ No newline at end of file +export const BASE_PATH = new OpaqueToken('basePath'); +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} \ No newline at end of file