From dad28dcba01738b426ead012c140d1682df7afea Mon Sep 17 00:00:00 2001 From: cbornet Date: Mon, 9 Nov 2015 16:10:55 +0100 Subject: [PATCH 1/7] don't retry if the access token doesn't change This is to avoid an infinite loop if the server always gives an invalid token --- .../libraries/retrofit/auth/OAuth.mustache | 75 +++++++++++-------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuth.mustache index 68ee918601ed..647ff1413290 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit/auth/OAuth.mustache @@ -1,6 +1,7 @@ package {{invokerPackage}}.auth; import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED; +import static java.net.HttpURLConnection.HTTP_FORBIDDEN; import java.io.IOException; import java.util.Map; @@ -85,42 +86,55 @@ public class OAuth implements Interceptor { updateAccessToken(null); } - // Build the request - Builder rb = request.newBuilder(); - - String requestAccessToken = new String(getAccessToken()); - try { - oAuthRequest = new OAuthBearerClientRequest(request.urlString()) - .setAccessToken(requestAccessToken) - .buildHeaderMessage(); - } catch (OAuthSystemException e) { - throw new IOException(e); + if (getAccessToken() != null) { + // Build the request + Builder rb = request.newBuilder(); + + String requestAccessToken = new String(getAccessToken()); + try { + oAuthRequest = new OAuthBearerClientRequest(request.urlString()) + .setAccessToken(requestAccessToken) + .buildHeaderMessage(); + } catch (OAuthSystemException e) { + throw new IOException(e); + } + + for ( Map.Entry header : oAuthRequest.getHeaders().entrySet() ) { + rb.addHeader(header.getKey(), header.getValue()); + } + rb.url( oAuthRequest.getLocationUri()); + + //Execute the request + Response response = chain.proceed(rb.build()); + + // 401 most likely indicates that access token has expired. + // Time to refresh and resend the request + if ( response != null && (response.code() == HTTP_UNAUTHORIZED | response.code() == HTTP_FORBIDDEN) ) { + if (updateAccessToken(requestAccessToken)) { + return intercept( chain ); + } + } + return response; + } else { + return chain.proceed(chain.request()); } - - for ( Map.Entry header : oAuthRequest.getHeaders().entrySet() ) { - rb.addHeader(header.getKey(), header.getValue()); - } - rb.url( oAuthRequest.getLocationUri()); - - //Execute the request - Response response = chain.proceed(rb.build()); - - // 401 most likely indicates that access token has expired. - // Time to refresh and resend the request - if ( response.code() == HTTP_UNAUTHORIZED ) { - updateAccessToken(requestAccessToken); - return intercept( chain ); - } - return response; } - public synchronized void updateAccessToken(String requestAccessToken) throws IOException { + /* + * Returns true if the access token has been updated + */ + public synchronized boolean updateAccessToken(String requestAccessToken) throws IOException { if (getAccessToken() == null || getAccessToken().equals(requestAccessToken)) { try { OAuthJSONAccessTokenResponse accessTokenResponse = oauthClient.accessToken(this.tokenRequestBuilder.buildBodyMessage()); - setAccessToken(accessTokenResponse.getAccessToken()); - if (accessTokenListener != null) { - accessTokenListener.notify((BasicOAuthToken) accessTokenResponse.getOAuthToken()); + if (accessTokenResponse != null && accessTokenResponse.getAccessToken() != null) { + setAccessToken(accessTokenResponse.getAccessToken()); + if (accessTokenListener != null) { + accessTokenListener.notify((BasicOAuthToken) accessTokenResponse.getOAuthToken()); + } + return getAccessToken().equals(requestAccessToken); + } else { + return false; } } catch (OAuthSystemException e) { throw new IOException(e); @@ -128,6 +142,7 @@ public class OAuth implements Interceptor { throw new IOException(e); } } + return true; } public void registerAccessTokenListener(AccessTokenListener accessTokenListener) { From aaafd0632cc90d4ff348b34a271c4f9a788dbb3b Mon Sep 17 00:00:00 2001 From: xhh Date: Tue, 10 Nov 2015 12:04:29 +0800 Subject: [PATCH 2/7] Fix error with array of enum in Java client ref: https://github.com/swagger-api/swagger-codegen/pull/1457#issuecomment-155185530 --- .../io/swagger/codegen/languages/JavaClientCodegen.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java index 4e6f1b9910a1..31b963cf142f 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java @@ -496,7 +496,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { } allowableValues.put("enumVars", enumVars); // handle default value for enum, e.g. available => StatusEnum.AVAILABLE - if (var.defaultValue != null && !"null".equals(var.defaultValue)) { + if (var.defaultValue != null) { String enumName = null; for (Map enumVar : enumVars) { if (var.defaultValue.equals(enumVar.get("value"))) { @@ -504,10 +504,9 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { break; } } - if (enumName == null) { - throw new RuntimeException("default value of property \"" + var.baseName + "\" is not in allowed values: " + var.defaultValue); + if (enumName != null) { + var.defaultValue = var.datatypeWithEnum + "." + enumName; } - var.defaultValue = var.datatypeWithEnum + "." + enumName; } } } From c07e30b8cf487282680f33693fc77cda917272ab Mon Sep 17 00:00:00 2001 From: xhh Date: Tue, 10 Nov 2015 13:22:06 +0800 Subject: [PATCH 3/7] Update testCreateUser to avoid occasional failures --- .../src/test/java/io/swagger/petstore/test/UserApiTest.java | 2 +- .../src/test/java/io/swagger/petstore/test/UserApiTest.java | 2 +- .../src/test/java/io/swagger/petstore/test/UserApiTest.java | 2 +- .../src/test/java/io/swagger/petstore/test/UserApiTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/client/petstore/java/default/src/test/java/io/swagger/petstore/test/UserApiTest.java b/samples/client/petstore/java/default/src/test/java/io/swagger/petstore/test/UserApiTest.java index 26e46bfa6024..a3f257f568bf 100644 --- a/samples/client/petstore/java/default/src/test/java/io/swagger/petstore/test/UserApiTest.java +++ b/samples/client/petstore/java/default/src/test/java/io/swagger/petstore/test/UserApiTest.java @@ -73,7 +73,7 @@ public class UserApiTest { private User createUser() { User user = new User(); user.setId(System.currentTimeMillis()); - user.setUsername("fred"); + user.setUsername("fred" + user.getId()); user.setFirstName("Fred"); user.setLastName("Meyer"); user.setEmail("fred@fredmeyer.com"); diff --git a/samples/client/petstore/java/jersey2/src/test/java/io/swagger/petstore/test/UserApiTest.java b/samples/client/petstore/java/jersey2/src/test/java/io/swagger/petstore/test/UserApiTest.java index 26e46bfa6024..a3f257f568bf 100644 --- a/samples/client/petstore/java/jersey2/src/test/java/io/swagger/petstore/test/UserApiTest.java +++ b/samples/client/petstore/java/jersey2/src/test/java/io/swagger/petstore/test/UserApiTest.java @@ -73,7 +73,7 @@ public class UserApiTest { private User createUser() { User user = new User(); user.setId(System.currentTimeMillis()); - user.setUsername("fred"); + user.setUsername("fred" + user.getId()); user.setFirstName("Fred"); user.setLastName("Meyer"); user.setEmail("fred@fredmeyer.com"); diff --git a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/UserApiTest.java b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/UserApiTest.java index 26e46bfa6024..a3f257f568bf 100644 --- a/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/UserApiTest.java +++ b/samples/client/petstore/java/okhttp-gson/src/test/java/io/swagger/petstore/test/UserApiTest.java @@ -73,7 +73,7 @@ public class UserApiTest { private User createUser() { User user = new User(); user.setId(System.currentTimeMillis()); - user.setUsername("fred"); + user.setUsername("fred" + user.getId()); user.setFirstName("Fred"); user.setLastName("Meyer"); user.setEmail("fred@fredmeyer.com"); diff --git a/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java b/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java index 373218465f0f..f99d7f513cc6 100644 --- a/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java +++ b/samples/client/petstore/java/retrofit/src/test/java/io/swagger/petstore/test/UserApiTest.java @@ -71,7 +71,7 @@ public class UserApiTest { private User createUser() { User user = new User(); user.setId(System.currentTimeMillis()); - user.setUsername("fred"); + user.setUsername("fred" + user.getId()); user.setFirstName("Fred"); user.setLastName("Meyer"); user.setEmail("fred@fredmeyer.com"); From cbd1b98bf53928e6c9979a4536ddcaa6260ef522 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 11 Nov 2015 16:35:17 +0800 Subject: [PATCH 4/7] better scala test (UserApi) --- .../scala/src/test/scala/UserApiTest.scala | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/samples/client/petstore/scala/src/test/scala/UserApiTest.scala b/samples/client/petstore/scala/src/test/scala/UserApiTest.scala index ea0fda03d9a8..f965510344f8 100644 --- a/samples/client/petstore/scala/src/test/scala/UserApiTest.scala +++ b/samples/client/petstore/scala/src/test/scala/UserApiTest.scala @@ -11,21 +11,41 @@ import scala.collection.JavaConverters._ import scala.beans.BeanProperty @RunWith(classOf[JUnitRunner]) -class UserApiTest extends FlatSpec with Matchers { +class UserApiTest extends FlatSpec with Matchers with BeforeAndAfterAll { behavior of "UserApi" val api = new UserApi api.apiInvoker.defaultHeaders += "api_key" -> "special-key" + // preparation before running a test + override def beforeAll() { + val user = User( + 11222, + "scala-test-username", + "scala-test-first", + "scala-test-last", + "scala_test@fail.com", + "SCALATEST", + "408-867-5309", + 1) + + api.createUser(user) + } + + // cleanup after running a test + override def afterAll() { + api.deleteUser("scala-test-username") + } + it should "fetch a user" in { - api.getUserByName("user1") match { + api.getUserByName("scala-test") match { case Some(user) => { - user.id should be(1) - user.username should be("user1") - user.password should be("XXXXXXXXXXX") - user.email should be("email1@test.com") - user.firstName should be("first name 1") - user.lastName should be("last name 1") - user.phone should be("123-456-7890") + user.id should be(11222) + user.username should be("scala-test-username") + user.password should be("SCALATEST") + user.email should be("scala_test@fail.com") + user.firstName should be("scala-test-first") + user.lastName should be("scala-test-last") + user.phone should be("408-867-5309") user.userStatus should be(1) } case None => @@ -33,7 +53,7 @@ class UserApiTest extends FlatSpec with Matchers { } it should "authenticate a user" in { - api.loginUser("user1", "XXXXXXXXXXX") match { + api.loginUser("scala-test-username", "SCALATEST") match { case Some(status) => status.startsWith("logged in user session") match { case true => // success! case _ => fail("didn't get expected message " + status) @@ -46,28 +66,6 @@ class UserApiTest extends FlatSpec with Matchers { api.logoutUser } - it should "create a user" in { - val user = User( - 1002, - "johnny", - "Johnny", - "Rocket", - "johnny@fail.com", - "XXXXXXXXXXX", - "408-867-5309", - 1) - - api.createUser(user) - - api.getUserByName("johnny") match { - case Some(user) => { - user.id should be(1002) - user.username should be("johnny") - } - case None => - } - } - it should "create 2 users" in { val userArray = (for (i <- (1 to 2)) yield { User( @@ -149,4 +147,4 @@ class UserApiTest extends FlatSpec with Matchers { case None => } } -} \ No newline at end of file +} From 05efd193c0e8c966bae90bd1a07317f578ee2232 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 11 Nov 2015 16:42:00 +0800 Subject: [PATCH 5/7] update test username for scala --- samples/client/petstore/scala/src/test/scala/UserApiTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/client/petstore/scala/src/test/scala/UserApiTest.scala b/samples/client/petstore/scala/src/test/scala/UserApiTest.scala index f965510344f8..77614a5dbbba 100644 --- a/samples/client/petstore/scala/src/test/scala/UserApiTest.scala +++ b/samples/client/petstore/scala/src/test/scala/UserApiTest.scala @@ -37,7 +37,7 @@ class UserApiTest extends FlatSpec with Matchers with BeforeAndAfterAll { } it should "fetch a user" in { - api.getUserByName("scala-test") match { + api.getUserByName("scala-test-username") match { case Some(user) => { user.id should be(11222) user.username should be("scala-test-username") From 2886ca0312a0b71600ab3bc3f019955e630a1e61 Mon Sep 17 00:00:00 2001 From: aersamkull Date: Wed, 11 Nov 2015 11:54:42 +0100 Subject: [PATCH 6/7] Adds comments to TypeScript Generator --- .../src/main/resources/TypeScript-Angular/api.mustache | 7 ++++++- .../src/main/resources/TypeScript-node/api.mustache | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache index 000ed2707b31..fc787b6437f0 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-Angular/api.mustache @@ -33,7 +33,12 @@ namespace {{package}} { } {{#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 path = this.basePath + '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache index e2a440bb8468..266dbaa412f2 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache @@ -167,7 +167,12 @@ export class {{classname}} { return objA; } {{#operation}} - + /** + * {{summary}} + * {{notes}} + {{#allParams}}* @param {{paramName}} {{description}} + {{/allParams}} + */ public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}}{{^returnType}}body?: any; {{/returnType}} }> { const path = this.url + this.basePath + '{{path}}'{{#pathParams}} .replace('{' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; From 684062ccbfe613db778055b6b4e553957fbf46e0 Mon Sep 17 00:00:00 2001 From: aersamkull Date: Wed, 11 Nov 2015 13:47:09 +0100 Subject: [PATCH 7/7] Updates samples --- .../typescript-angular/API/Client/Category.ts | 11 + .../typescript-angular/API/Client/Order.ts | 35 + .../typescript-angular/API/Client/Pet.ts | 35 + .../typescript-angular/API/Client/PetApi.ts | 146 ++ .../typescript-angular/API/Client/StoreApi.ts | 59 + .../typescript-angular/API/Client/Tag.ts | 11 + .../typescript-angular/API/Client/User.ts | 24 + .../typescript-angular/API/Client/UserApi.ts | 124 ++ .../typescript-angular/API/Client/api.d.ts | 30 +- .../client/petstore/typescript-node/api.ts | 1403 +++++++++++------ 10 files changed, 1416 insertions(+), 462 deletions(-) diff --git a/samples/client/petstore/typescript-angular/API/Client/Category.ts b/samples/client/petstore/typescript-angular/API/Client/Category.ts index a802fe4ebdf6..5e0a12f2122a 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Category.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Category.ts @@ -3,11 +3,22 @@ namespace API.Client { 'use strict'; + + + export interface Category { + + id?: number; + + name?: string; + } + + + } diff --git a/samples/client/petstore/typescript-angular/API/Client/Order.ts b/samples/client/petstore/typescript-angular/API/Client/Order.ts index 1dd84e6d0adb..874efb18c7e7 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Order.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Order.ts @@ -3,30 +3,65 @@ namespace API.Client { 'use strict'; + + + export interface Order { + + id?: number; + + petId?: number; + + quantity?: number; + + shipDate?: Date; + + /** * Order Status */ + status?: Order.StatusEnum; + + complete?: boolean; + } + export namespace Order { + + + + + + + + + + export enum StatusEnum { placed = 'placed', approved = 'approved', delivered = 'delivered', } + + + + } + + + } diff --git a/samples/client/petstore/typescript-angular/API/Client/Pet.ts b/samples/client/petstore/typescript-angular/API/Client/Pet.ts index 60431f69c83b..bf1560de85cc 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Pet.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Pet.ts @@ -3,30 +3,65 @@ namespace API.Client { 'use strict'; + + + export interface Pet { + + id?: number; + + category?: Category; + + name: string; + + photoUrls: Array; + + tags?: Array; + + /** * pet status in the store */ + status?: Pet.StatusEnum; + } + export namespace Pet { + + + + + + + + + + + + export enum StatusEnum { available = 'available', pending = 'pending', sold = 'sold', } + + } + + + } diff --git a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts index 7c89b754914a..2e936fdddd19 100644 --- a/samples/client/petstore/typescript-angular/API/Client/PetApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/PetApi.ts @@ -2,9 +2,11 @@ /* tslint:disable:no-unused-variable member-ordering */ + namespace API.Client { 'use strict'; + export class PetApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -27,11 +29,25 @@ namespace API.Client { } + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + + */ public updatePet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'PUT', url: path, @@ -50,11 +66,25 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + + */ public addPet (body?: Pet, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'POST', url: path, @@ -73,15 +103,30 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + + */ public findPetsByStatus (status?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { const path = this.basePath + '/pet/findByStatus'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + if (status !== undefined) { queryParameters['status'] = status; } + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -99,15 +144,30 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + + */ public findPetsByTags (tags?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise> { const path = this.basePath + '/pet/findByTags'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + if (tags !== undefined) { queryParameters['tags'] = tags; } + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -125,16 +185,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + + */ public getPetById (petId: number, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling getPetById'); } + + + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -152,24 +227,49 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + + */ public updatePetWithForm (petId: string, name?: string, status?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling updatePetWithForm'); } + + + + + + + + + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; + + formParams['name'] = name; + formParams['status'] = status; + let httpRequestParams: any = { method: 'POST', url: path, @@ -188,18 +288,37 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + + */ public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling deletePet'); } + + + + + + headerParams['api_key'] = apiKey; + + + let httpRequestParams: any = { method: 'DELETE', url: path, @@ -217,24 +336,49 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + + */ public uploadFile (petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/pet/{petId}/uploadImage' .replace('{' + 'petId' + '}', String(petId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'petId' is set if (!petId) { throw new Error('Missing required parameter petId when calling uploadFile'); } + + + + + + + + + headerParams['Content-Type'] = 'application/x-www-form-urlencoded'; + + formParams['additionalMetadata'] = additionalMetadata; + formParams['file'] = file; + let httpRequestParams: any = { method: 'POST', url: path, @@ -252,5 +396,7 @@ namespace API.Client { return this.$http(httpRequestParams); } + } } + diff --git a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts index 801a86a4a04e..492ef6885feb 100644 --- a/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/StoreApi.ts @@ -2,9 +2,11 @@ /* tslint:disable:no-unused-variable member-ordering */ + namespace API.Client { 'use strict'; + export class StoreApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -27,11 +29,22 @@ namespace API.Client { } + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + + */ public getInventory (extraHttpRequestParams?: any ) : ng.IHttpPromise<{ [key: string]: number; }> { const path = this.basePath + '/store/inventory'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -49,11 +62,25 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + + */ public placeOrder (body?: Order, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/store/order'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'POST', url: path, @@ -72,16 +99,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + + */ public getOrderById (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'orderId' is set if (!orderId) { throw new Error('Missing required parameter orderId when calling getOrderById'); } + + + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -99,16 +141,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + + */ public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'orderId' is set if (!orderId) { throw new Error('Missing required parameter orderId when calling deleteOrder'); } + + + + + + let httpRequestParams: any = { method: 'DELETE', url: path, @@ -125,5 +182,7 @@ namespace API.Client { return this.$http(httpRequestParams); } + } } + diff --git a/samples/client/petstore/typescript-angular/API/Client/Tag.ts b/samples/client/petstore/typescript-angular/API/Client/Tag.ts index 1c0284cce485..66666719d890 100644 --- a/samples/client/petstore/typescript-angular/API/Client/Tag.ts +++ b/samples/client/petstore/typescript-angular/API/Client/Tag.ts @@ -3,11 +3,22 @@ namespace API.Client { 'use strict'; + + + export interface Tag { + + id?: number; + + name?: string; + } + + + } diff --git a/samples/client/petstore/typescript-angular/API/Client/User.ts b/samples/client/petstore/typescript-angular/API/Client/User.ts index 7c2b0b78b0ce..69e94835d302 100644 --- a/samples/client/petstore/typescript-angular/API/Client/User.ts +++ b/samples/client/petstore/typescript-angular/API/Client/User.ts @@ -3,26 +3,50 @@ namespace API.Client { 'use strict'; + + + export interface User { + + id?: number; + + username?: string; + + firstName?: string; + + lastName?: string; + + email?: string; + + password?: string; + + phone?: string; + + /** * User Status */ + userStatus?: number; + } + + + } diff --git a/samples/client/petstore/typescript-angular/API/Client/UserApi.ts b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts index 4deb8bc6ebe3..036508eb69d8 100644 --- a/samples/client/petstore/typescript-angular/API/Client/UserApi.ts +++ b/samples/client/petstore/typescript-angular/API/Client/UserApi.ts @@ -2,9 +2,11 @@ /* tslint:disable:no-unused-variable member-ordering */ + namespace API.Client { 'use strict'; + export class UserApi { protected basePath = 'http://petstore.swagger.io/v2'; public defaultHeaders : any = {}; @@ -27,11 +29,25 @@ namespace API.Client { } + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + + */ public createUser (body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'POST', url: path, @@ -50,11 +66,25 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Creates list of users with given input array + * + * @param body List of user object + + */ public createUsersWithArrayInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/createWithArray'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'POST', url: path, @@ -73,11 +103,25 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Creates list of users with given input array + * + * @param body List of user object + + */ public createUsersWithListInput (body?: Array, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/createWithList'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + + let httpRequestParams: any = { method: 'POST', url: path, @@ -96,19 +140,38 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + + */ public loginUser (username?: string, password?: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/user/login'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + + if (username !== undefined) { queryParameters['username'] = username; } + if (password !== undefined) { queryParameters['password'] = password; } + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -126,11 +189,22 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Logs out current logged in user session + * + + */ public logoutUser (extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/logout'; let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -148,16 +222,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + + */ public getUserByName (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise { const path = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling getUserByName'); } + + + + + + let httpRequestParams: any = { method: 'GET', url: path, @@ -175,16 +264,34 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + + */ public updateUser (username: string, body?: User, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling updateUser'); } + + + + + + + + let httpRequestParams: any = { method: 'PUT', url: path, @@ -203,16 +310,31 @@ namespace API.Client { return this.$http(httpRequestParams); } + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + + */ public deleteUser (username: string, extraHttpRequestParams?: any ) : ng.IHttpPromise<{}> { const path = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); let queryParameters: any = {}; let headerParams: any = this.extendObj({}, this.defaultHeaders); + + + // verify required parameter 'username' is set if (!username) { throw new Error('Missing required parameter username when calling deleteUser'); } + + + + + + let httpRequestParams: any = { method: 'DELETE', url: path, @@ -229,5 +351,7 @@ namespace API.Client { return this.$http(httpRequestParams); } + } } + diff --git a/samples/client/petstore/typescript-angular/API/Client/api.d.ts b/samples/client/petstore/typescript-angular/API/Client/api.d.ts index 19c60623dc94..7a4f79f38b1e 100644 --- a/samples/client/petstore/typescript-angular/API/Client/api.d.ts +++ b/samples/client/petstore/typescript-angular/API/Client/api.d.ts @@ -1,9 +1,37 @@ + + /// + + + /// + + + /// + + + /// + + + /// + + + + + /// -/// + + + /// + + + +/// + + + diff --git a/samples/client/petstore/typescript-node/api.ts b/samples/client/petstore/typescript-node/api.ts index 47026929d819..4728b6f8c147 100644 --- a/samples/client/petstore/typescript-node/api.ts +++ b/samples/client/petstore/typescript-node/api.ts @@ -8,69 +8,181 @@ import http = require('http'); /* tslint:disable:no-unused-variable */ + + + export class User { + + id: number; + + username: string; + + firstName: string; + + lastName: string; + + email: string; + + password: string; + + phone: string; + + /** * User Status */ + userStatus: number; + } + + + + + export class Category { + + id: number; + + name: string; + } + + + + + export class Pet { + + id: number; + + category: Category; + + name: string; + + photoUrls: Array; + + tags: Array; + + /** * pet status in the store */ + status: Pet.StatusEnum; + } + export namespace Pet { + + + + + + + + + + + + export enum StatusEnum { available = 'available', pending = 'pending', sold = 'sold', } -} -export class Tag { - id: number; - name: string; + + } -export class Order { + + + + +export class Tag { + + id: number; + + + name: string; + +} + + + + + + +export class Order { + + + id: number; + + petId: number; + + quantity: number; + + shipDate: Date; + + /** * Order Status */ + status: Order.StatusEnum; + + complete: boolean; + } + export namespace Order { + + + + + + + + + + export enum StatusEnum { placed = 'placed', approved = 'approved', delivered = 'delivered', } + + + + } + + + interface Authentication { /** * Apply authentication settings to header and query params. @@ -117,6 +229,10 @@ class VoidAuth implements Authentication { } } + + + + export class UserApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; @@ -125,13 +241,34 @@ export class UserApi { public authentications = { 'default': new VoidAuth(), - 'api_key': new ApiKeyAuth('header', 'api_key'), + + + + 'petstore_auth': new OAuth(), + + + + + 'api_key': new ApiKeyAuth('header', 'api_key'), + + + } constructor(url: string, basePath?: string); + + + + + constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { if (password) { + + + + + if (basePath) { this.basePath = basePath; } @@ -142,9 +279,20 @@ export class UserApi { } } + + + + + + + + set apiKey(key: string) { this.authentications.api_key.apiKey = key; } + + + private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){ @@ -154,6 +302,12 @@ export class UserApi { return objA; } + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + + */ public createUser (body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user'; let queryParameters: any = {}; @@ -161,8 +315,11 @@ export class UserApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -171,9 +328,12 @@ export class UserApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -199,6 +359,12 @@ export class UserApi { return deferred.promise; } + /** + * Creates list of users with given input array + * + * @param body List of user object + + */ public createUsersWithArrayInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/createWithArray'; let queryParameters: any = {}; @@ -206,8 +372,11 @@ export class UserApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -216,9 +385,12 @@ export class UserApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -244,6 +416,12 @@ export class UserApi { return deferred.promise; } + /** + * Creates list of users with given input array + * + * @param body List of user object + + */ public createUsersWithListInput (body?: Array) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/createWithList'; let queryParameters: any = {}; @@ -251,8 +429,11 @@ export class UserApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -261,9 +442,12 @@ export class UserApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -289,6 +473,13 @@ export class UserApi { return deferred.promise; } + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + + */ public loginUser (username?: string, password?: string) : Promise<{ response: http.ClientResponse; body: string; }> { const path = this.url + this.basePath + '/user/login'; let queryParameters: any = {}; @@ -296,16 +487,21 @@ export class UserApi { let formParams: any = {}; + if (username !== undefined) { queryParameters['username'] = username; } + if (password !== undefined) { queryParameters['password'] = password; } + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); let requestOptions: request.Options = { @@ -314,8 +510,10 @@ export class UserApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -341,6 +539,11 @@ export class UserApi { return deferred.promise; } + /** + * Logs out current logged in user session + * + + */ public logoutUser () : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/logout'; let queryParameters: any = {}; @@ -348,8 +551,11 @@ export class UserApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -358,8 +564,10 @@ export class UserApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -385,6 +593,12 @@ export class UserApi { return deferred.promise; } + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + + */ public getUserByName (username: string) : Promise<{ response: http.ClientResponse; body: User; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -398,8 +612,11 @@ export class UserApi { throw new Error('Missing required parameter username when calling getUserByName'); } + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body: User; }>(); let requestOptions: request.Options = { @@ -408,8 +625,10 @@ export class UserApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -435,6 +654,13 @@ export class UserApi { return deferred.promise; } + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + + */ public updateUser (username: string, body?: User) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -448,8 +674,11 @@ export class UserApi { throw new Error('Missing required parameter username when calling updateUser'); } + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -458,9 +687,12 @@ export class UserApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -486,6 +718,12 @@ export class UserApi { return deferred.promise; } + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + + */ public deleteUser (username: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -499,8 +737,11 @@ export class UserApi { throw new Error('Missing required parameter username when calling deleteUser'); } + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -509,8 +750,10 @@ export class UserApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -535,465 +778,12 @@ export class UserApi { return deferred.promise; } + } -export class PetApi { - protected basePath = 'http://petstore.swagger.io/v2'; - protected defaultHeaders : any = {}; - public authentications = { - 'default': new VoidAuth(), - 'api_key': new ApiKeyAuth('header', 'api_key'), - 'petstore_auth': new OAuth(), - } - constructor(url: string, basePath?: string); - constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { - if (password) { - if (basePath) { - this.basePath = basePath; - } - } else { - if (basePathOrUsername) { - this.basePath = basePathOrUsername - } - } - } - - set apiKey(key: string) { - this.authentications.api_key.apiKey = key; - } - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - objA[key] = objB[key]; - } - } - return objA; - } - - public updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/pet'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let requestOptions: request.Options = { - method: 'PUT', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - body: body, - } - - this.authentications.petstore_auth.applyToRequest(requestOptions); - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - public addPet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/pet'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let requestOptions: request.Options = { - method: 'POST', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - body: body, - } - - this.authentications.petstore_auth.applyToRequest(requestOptions); - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - public findPetsByStatus (status?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { - const path = this.url + this.basePath + '/pet/findByStatus'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - if (status !== undefined) { - queryParameters['status'] = status; - } - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); - - let requestOptions: request.Options = { - method: 'GET', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - } - - this.authentications.petstore_auth.applyToRequest(requestOptions); - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - public findPetsByTags (tags?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { - const path = this.url + this.basePath + '/pet/findByTags'; - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - if (tags !== undefined) { - queryParameters['tags'] = tags; - } - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); - - let requestOptions: request.Options = { - method: 'GET', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - } - - this.authentications.petstore_auth.applyToRequest(requestOptions); - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { - const path = this.url + this.basePath + '/pet/{petId}' - .replace('{' + 'petId' + '}', String(petId)); - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'petId' is set - if (!petId) { - throw new Error('Missing required parameter petId when calling getPetById'); - } - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); - - let requestOptions: request.Options = { - method: 'GET', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - } - - this.authentications.api_key.applyToRequest(requestOptions); - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - public updatePetWithForm (petId: string, name?: string, status?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/pet/{petId}' - .replace('{' + 'petId' + '}', String(petId)); - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'petId' is set - if (!petId) { - throw new Error('Missing required parameter petId when calling updatePetWithForm'); - } - - let useFormData = false; - - if (name !== undefined) { - formParams['name'] = name; - } - - if (status !== undefined) { - formParams['status'] = status; - } - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let requestOptions: request.Options = { - method: 'POST', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - } - - this.authentications.petstore_auth.applyToRequest(requestOptions); - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/pet/{petId}' - .replace('{' + 'petId' + '}', String(petId)); - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'petId' is set - if (!petId) { - throw new Error('Missing required parameter petId when calling deletePet'); - } - - headerParams['api_key'] = apiKey; - - let useFormData = false; - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let requestOptions: request.Options = { - method: 'DELETE', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - } - - this.authentications.petstore_auth.applyToRequest(requestOptions); - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } - - public uploadFile (petId: number, additionalMetadata?: string, file?: any) : Promise<{ response: http.ClientResponse; body?: any; }> { - const path = this.url + this.basePath + '/pet/{petId}/uploadImage' - .replace('{' + 'petId' + '}', String(petId)); - let queryParameters: any = {}; - let headerParams: any = this.extendObj({}, this.defaultHeaders); - let formParams: any = {}; - - - // verify required parameter 'petId' is set - if (!petId) { - throw new Error('Missing required parameter petId when calling uploadFile'); - } - - let useFormData = false; - - if (additionalMetadata !== undefined) { - formParams['additionalMetadata'] = additionalMetadata; - } - - if (file !== undefined) { - formParams['file'] = file; - } - useFormData = true; - - let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); - - let requestOptions: request.Options = { - method: 'POST', - qs: queryParameters, - headers: headerParams, - uri: path, - json: true, - } - - this.authentications.petstore_auth.applyToRequest(requestOptions); - - this.authentications.default.applyToRequest(requestOptions); - - if (Object.keys(formParams).length) { - if (useFormData) { - (requestOptions).formData = formParams; - } else { - requestOptions.form = formParams; - } - } - - request(requestOptions, (error, response, body) => { - if (error) { - deferred.reject(error); - } else { - if (response.statusCode >= 200 && response.statusCode <= 299) { - deferred.resolve({ response: response, body: body }); - } else { - deferred.reject({ response: response, body: body }); - } - } - }); - - return deferred.promise; - } -} export class StoreApi { protected basePath = 'http://petstore.swagger.io/v2'; protected defaultHeaders : any = {}; @@ -1002,13 +792,34 @@ export class StoreApi { public authentications = { 'default': new VoidAuth(), - 'api_key': new ApiKeyAuth('header', 'api_key'), + + + + 'petstore_auth': new OAuth(), + + + + + 'api_key': new ApiKeyAuth('header', 'api_key'), + + + } constructor(url: string, basePath?: string); + + + + + constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { if (password) { + + + + + if (basePath) { this.basePath = basePath; } @@ -1019,9 +830,20 @@ export class StoreApi { } } + + + + + + + + set apiKey(key: string) { this.authentications.api_key.apiKey = key; } + + + private extendObj(objA: T1, objB: T2) { for(let key in objB){ if(objB.hasOwnProperty(key)){ @@ -1031,6 +853,11 @@ export class StoreApi { return objA; } + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + + */ public getInventory () : Promise<{ response: http.ClientResponse; body: { [key: string]: number; }; }> { const path = this.url + this.basePath + '/store/inventory'; let queryParameters: any = {}; @@ -1038,8 +865,11 @@ export class StoreApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body: { [key: string]: number; }; }>(); let requestOptions: request.Options = { @@ -1048,10 +878,13 @@ export class StoreApi { headers: headerParams, uri: path, json: true, + } + this.authentications.api_key.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1077,6 +910,12 @@ export class StoreApi { return deferred.promise; } + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + + */ public placeOrder (body?: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { const path = this.url + this.basePath + '/store/order'; let queryParameters: any = {}; @@ -1084,8 +923,11 @@ export class StoreApi { let formParams: any = {}; + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); let requestOptions: request.Options = { @@ -1094,9 +936,12 @@ export class StoreApi { headers: headerParams, uri: path, json: true, + body: body, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1122,6 +967,12 @@ export class StoreApi { return deferred.promise; } + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + + */ public getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { const path = this.url + this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); @@ -1135,8 +986,11 @@ export class StoreApi { throw new Error('Missing required parameter orderId when calling getOrderById'); } + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); let requestOptions: request.Options = { @@ -1145,8 +999,10 @@ export class StoreApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1172,6 +1028,12 @@ export class StoreApi { return deferred.promise; } + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + + */ public deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; body?: any; }> { const path = this.url + this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); @@ -1185,8 +1047,11 @@ export class StoreApi { throw new Error('Missing required parameter orderId when calling deleteOrder'); } + + let useFormData = false; + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); let requestOptions: request.Options = { @@ -1195,8 +1060,10 @@ export class StoreApi { headers: headerParams, uri: path, json: true, + } + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -1221,4 +1088,618 @@ export class StoreApi { return deferred.promise; } + } + + + + +export class PetApi { + protected basePath = 'http://petstore.swagger.io/v2'; + protected defaultHeaders : any = {}; + + + + public authentications = { + 'default': new VoidAuth(), + + + + + 'petstore_auth': new OAuth(), + + + + + 'api_key': new ApiKeyAuth('header', 'api_key'), + + + + } + + constructor(url: string, basePath?: string); + + + + + + constructor(private url: string, basePathOrUsername: string, password?: string, basePath?: string) { + if (password) { + + + + + + if (basePath) { + this.basePath = basePath; + } + } else { + if (basePathOrUsername) { + this.basePath = basePathOrUsername + } + } + } + + + + + + + + + + set apiKey(key: string) { + this.authentications.api_key.apiKey = key; + } + + + + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + objA[key] = objB[key]; + } + } + return objA; + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + + */ + public updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/pet'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let requestOptions: request.Options = { + method: 'PUT', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + body: body, + + } + + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + + */ + public addPet (body?: Pet) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/pet'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + body: body, + + } + + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + + */ + public findPetsByStatus (status?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { + const path = this.url + this.basePath + '/pet/findByStatus'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + + if (status !== undefined) { + queryParameters['status'] = status; + } + + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + + let requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + } + + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + + */ + public findPetsByTags (tags?: Array) : Promise<{ response: http.ClientResponse; body: Array; }> { + const path = this.url + this.basePath + '/pet/findByTags'; + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + + if (tags !== undefined) { + queryParameters['tags'] = tags; + } + + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + + let requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + } + + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + + */ + public getPetById (petId: number) : Promise<{ response: http.ClientResponse; body: Pet; }> { + const path = this.url + this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling getPetById'); + } + + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); + + let requestOptions: request.Options = { + method: 'GET', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + } + + + this.authentications.api_key.applyToRequest(requestOptions); + + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + + */ + public updatePetWithForm (petId: string, name?: string, status?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling updatePetWithForm'); + } + + + + let useFormData = false; + + + if (name !== undefined) { + formParams['name'] = name; + } + + + + if (status !== undefined) { + formParams['status'] = status; + } + + + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + } + + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + + */ + public deletePet (petId: number, apiKey?: string) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling deletePet'); + } + + + + headerParams['api_key'] = apiKey; + + + let useFormData = false; + + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let requestOptions: request.Options = { + method: 'DELETE', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + } + + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + + */ + public uploadFile (petId: number, additionalMetadata?: string, file?: any) : Promise<{ response: http.ClientResponse; body?: any; }> { + const path = this.url + this.basePath + '/pet/{petId}/uploadImage' + .replace('{' + 'petId' + '}', String(petId)); + let queryParameters: any = {}; + let headerParams: any = this.extendObj({}, this.defaultHeaders); + let formParams: any = {}; + + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling uploadFile'); + } + + + + let useFormData = false; + + + if (additionalMetadata !== undefined) { + formParams['additionalMetadata'] = additionalMetadata; + } + + + + if (file !== undefined) { + formParams['file'] = file; + } + + useFormData = true; + + + + let deferred = promise.defer<{ response: http.ClientResponse; body?: any; }>(); + + let requestOptions: request.Options = { + method: 'POST', + qs: queryParameters, + headers: headerParams, + uri: path, + json: true, + + } + + + this.authentications.petstore_auth.applyToRequest(requestOptions); + + + this.authentications.default.applyToRequest(requestOptions); + + if (Object.keys(formParams).length) { + if (useFormData) { + (requestOptions).formData = formParams; + } else { + requestOptions.form = formParams; + } + } + + request(requestOptions, (error, response, body) => { + if (error) { + deferred.reject(error); + } else { + if (response.statusCode >= 200 && response.statusCode <= 299) { + deferred.resolve({ response: response, body: body }); + } else { + deferred.reject({ response: response, body: body }); + } + } + }); + + return deferred.promise; + } + +} + + +