From ea8516d74722dd518477b5441ee3536c764dc58b Mon Sep 17 00:00:00 2001 From: Kristof Vrolijkx Date: Tue, 3 May 2016 08:39:39 +0200 Subject: [PATCH 1/2] Readding client.ts --- .../petstore/typescript-node/npm/client.ts | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 samples/client/petstore/typescript-node/npm/client.ts diff --git a/samples/client/petstore/typescript-node/npm/client.ts b/samples/client/petstore/typescript-node/npm/client.ts new file mode 100644 index 000000000000..51a7f687e09f --- /dev/null +++ b/samples/client/petstore/typescript-node/npm/client.ts @@ -0,0 +1,59 @@ +import api = require('./api'); +import fs = require('fs'); + +var petApi = new api.PetApi(); +petApi.setApiKey(api.PetApiApiKeys.api_key, 'special-key'); +petApi.setApiKey(api.PetApiApiKeys.test_api_key_header, 'query-key'); + +var tag1 = new api.Tag(); +tag1.id = 18291; +tag1.name = 'TS tag 1'; + +var pet = new api.Pet(); +pet.name = 'TypeScriptDoggie'; +pet.id = 18291; +pet.photoUrls = ["http://url1", "http://url2"]; +pet.tags = [tag1]; + +var petId: any; + +var exitCode = 0; + +// Test various API calls to the petstore +petApi.addPet(pet) + .then((res) => { + var newPet = res.body; + petId = newPet.id; + console.log(`Created pet with ID ${petId}`); + newPet.status = api.Pet.StatusEnum.available; + return petApi.updatePet(newPet); + }) + .then((res) => { + console.log('Updated pet using POST body'); + return petApi.updatePetWithForm(petId, undefined, "pending"); + }) + .then((res) => { + console.log('Updated pet using POST form'); + return petApi.uploadFile(petId, undefined, fs.createReadStream('sample.png')); + }) + .then((res) => { + console.log('Uploaded image'); + return petApi.getPetById(petId); + }) + .then((res) => { + console.log('Got pet by ID: ' + JSON.stringify(res.body)); + if (res.body.status != api.Pet.StatusEnum.pending) { + throw new Error("Unexpected pet status"); + } + }) + .catch((err: any) => { + console.error(err); + exitCode = 1; + }) + .finally(() => { + return petApi.deletePet(petId); + }) + .then((res) => { + console.log('Deleted pet'); + process.exit(exitCode); + }); From 9fb85ae8fea527c4268d52afc5ca9009d4afc08e Mon Sep 17 00:00:00 2001 From: Kristof Vrolijkx Date: Tue, 3 May 2016 20:36:24 +0200 Subject: [PATCH 2/2] removing comment --- .../codegen/languages/TypeScriptNodeClientCodegen.java | 1 - samples/client/petstore/typescript-node/npm/api.ts | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java index 3950c1a7ff32..d4207f09cc83 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptNodeClientCodegen.java @@ -41,7 +41,6 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen super.processOpts(); supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts")); supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); - //supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore")); LOGGER.warn("check additionals: " + additionalProperties.get(NPM_NAME)); if(additionalProperties.containsKey(NPM_NAME)) { diff --git a/samples/client/petstore/typescript-node/npm/api.ts b/samples/client/petstore/typescript-node/npm/api.ts index c2bd53e8ca29..3e25b5e718c0 100644 --- a/samples/client/petstore/typescript-node/npm/api.ts +++ b/samples/client/petstore/typescript-node/npm/api.ts @@ -129,8 +129,8 @@ export class PetApi { protected authentications = { 'default': new VoidAuth(), - 'api_key': new ApiKeyAuth('header', 'api_key'), 'petstore_auth': new OAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), } constructor(basePath?: string); @@ -409,10 +409,10 @@ export class PetApi { json: true, } - this.authentications.api_key.applyToRequest(requestOptions); - this.authentications.petstore_auth.applyToRequest(requestOptions); + this.authentications.api_key.applyToRequest(requestOptions); + this.authentications.default.applyToRequest(requestOptions); if (Object.keys(formParams).length) { @@ -632,8 +632,8 @@ export class StoreApi { protected authentications = { 'default': new VoidAuth(), - 'api_key': new ApiKeyAuth('header', 'api_key'), 'petstore_auth': new OAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), } constructor(basePath?: string); @@ -881,8 +881,8 @@ export class UserApi { protected authentications = { 'default': new VoidAuth(), - 'api_key': new ApiKeyAuth('header', 'api_key'), 'petstore_auth': new OAuth(), + 'api_key': new ApiKeyAuth('header', 'api_key'), } constructor(basePath?: string);