diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java index 11cae0de0e..9b9422bbcd 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java @@ -19,7 +19,8 @@ public class TypeScriptAngularClientCodegen extends TypeScriptNodeClientCodegen templateDir = "TypeScript-Angular"; apiPackage = "api"; modelPackage = "model"; - + + supportingFiles.clear(); supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage + File.separator, "api.d.ts")); } } \ No newline at end of file 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 0ea33f2170..9e2e1056dc 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 @@ -31,11 +31,9 @@ public class TypeScriptNodeClientCodegen extends DefaultCodegen implements Codeg public TypeScriptNodeClientCodegen() { super(); outputFolder = "generated-code/typescript-node"; - modelTemplateFiles.put("model.mustache", ".ts"); - apiTemplateFiles.put("api.mustache", ".ts"); templateDir = "TypeScript-node"; - apiPackage = "api"; - modelPackage = "model"; + + supportingFiles.add(new SupportingFile("api.mustache", null, "api.ts")); reservedWords = new HashSet(Arrays.asList("abstract", "continue", "for", "new", "switch", "assert", "default", "if", 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 debeed6951..67b7d4fc3f 100644 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache +++ b/modules/swagger-codegen/src/main/resources/TypeScript-node/api.mustache @@ -1,10 +1,52 @@ +import request = require('request'); +import promise = require('bluebird'); +import http = require('http'); + +// =============================================== +// This file is autogenerated - Please do not edit +// =============================================== + /* tslint:disable:no-unused-variable */ -{{#operations}} +{{#models}} +{{#model}} +{{#description}} +/** +* {{{description}}} +*/ +{{/description}} +export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ +{{#vars}} {{#description}} /** - * {{&description}} + * {{{description}}} */ +{{/description}} + {{name}}: {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; +{{/vars}} +} + +{{#hasEnums}} +export module {{classname}} { +{{#vars}} +{{#isEnum}} + export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}} + {{.}} = '{{.}}',{{/values}}{{/allowableValues}} + } +{{/isEnum}} +{{/vars}} +} +{{/hasEnums}} +{{/model}} +{{/models}} + +{{#apiInfo}} +{{#apis}} +{{#operations}} +{{#description}} +/** +* {{&description}} +*/ {{/description}} export class {{classname}} { private basePath = '{{contextPath}}'; @@ -14,60 +56,65 @@ export class {{classname}} { this.basePath = basePath; } } +{{#operation}} - {{#operation}} - public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }> { - var path = this.url + this.basePath + '{{path}}'; + public {{nickname}} ({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) : Promise<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }> { + var path = this.url + this.basePath + '{{path}}'; - {{#pathParams}} - path = path.replace('{' + '{{paramName}}' + '}', String({{paramName}})); - {{/pathParams}} +{{#pathParams}} + path = path.replace('{' + '{{paramName}}' + '}', String({{paramName}})); - var queryParameters: any = {}; - var headerParams: any = {}; +{{/pathParams}} + var queryParameters: any = {}; + var headerParams: any = {}; - {{#allParams}}{{#required}} - // verify required parameter '{{paramName}}' is set - if (!{{paramName}}) { - throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}'); - } - {{/required}}{{/allParams}} - - {{#queryParams}}if ({{paramName}} !== undefined) { - queryParameters['{{paramName}}'] = {{paramName}}; - } - {{/queryParams}} - - {{#headerParams}}headerParams['{{paramName}}'] = {{paramName}}; - {{/headerParams}} - - var deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>(); - - request({ - method: '{{httpMethod}}', - qs: queryParameters, - uri: path, - json: true, - {{#bodyParam}}body: {{paramName}}, - {{/bodyParam}} - auth: { - username: this.username, password: this.password +{{#allParams}} +{{#required}} + // verify required parameter '{{paramName}}' is set + if (!{{paramName}}) { + throw new Error('Missing required parameter {{paramName}} when calling {{nickname}}'); } - }, (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 }); + +{{/required}} +{{/allParams}} +{{#queryParams}} + if ({{paramName}} !== undefined) { + queryParameters['{{paramName}}'] = {{paramName}}; } - } - }); - return deferred.promise; - } +{{/queryParams}} +{{#headerParams}} + headerParams['{{paramName}}'] = {{paramName}}; - {{/operation}} +{{/headerParams}} + var deferred = promise.defer<{ response: http.ClientResponse; {{#returnType}}body: {{{returnType}}}; {{/returnType}} }>(); + + request({ + method: '{{httpMethod}}', + qs: queryParameters, + uri: path, + json: true, + {{#bodyParam}}body: {{paramName}}, + {{/bodyParam}} + auth: { + username: this.username, password: this.password + } + }, (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; + } +{{/operation}} } {{/operations}} +{{/apis}} +{{/apiInfo}} diff --git a/modules/swagger-codegen/src/main/resources/TypeScript-node/model.mustache b/modules/swagger-codegen/src/main/resources/TypeScript-node/model.mustache deleted file mode 100644 index 55c8997e1b..0000000000 --- a/modules/swagger-codegen/src/main/resources/TypeScript-node/model.mustache +++ /dev/null @@ -1,33 +0,0 @@ -{{#models}} -{{#model}} -{{#description}} -/** - * {{{description}}} - */ -{{/description}} -export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{ -{{#vars}} - -{{#description}} - /** - * {{{description}}} - */ -{{/description}} - {{name}}: {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; -{{/vars}} -} - -{{#hasEnums}} -export module {{classname}} { -{{#vars}} -{{#isEnum}} - - export enum {{datatypeWithEnum}} { {{#allowableValues}}{{#values}} - {{.}} = '{{.}}',{{/values}}{{/allowableValues}} - } -{{/isEnum}} -{{/vars}} -} -{{/hasEnums}} -{{/model}} -{{/models}} diff --git a/samples/client/petstore/typescript-node/api.ts b/samples/client/petstore/typescript-node/api.ts new file mode 100644 index 0000000000..b165be2d31 --- /dev/null +++ b/samples/client/petstore/typescript-node/api.ts @@ -0,0 +1,828 @@ +import request = require('request'); +import promise = require('bluebird'); +import http = require('http'); + +// =============================================== +// This file is autogenerated - Please do not edit +// =============================================== + +/* 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 module Pet { + export enum StatusEnum { + available = 'available', + pending = 'pending', + sold = 'sold', + } +} +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 module Order { + export enum StatusEnum { + placed = 'placed', + approved = 'approved', + delivered = 'delivered', + } +} + +export class UserApi { + private basePath = '/v2'; + + constructor(private url: string, private username: string, private password: string, basePath?: string) { + if (basePath) { + this.basePath = basePath; + } + } + + public createUser (body?: User) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'POST', + qs: queryParameters, + uri: path, + json: true, + body: body, + + auth: { + username: this.username, password: this.password + } + }, (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 createUsersWithArrayInput (body?: Array) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user/createWithArray'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'POST', + qs: queryParameters, + uri: path, + json: true, + body: body, + + auth: { + username: this.username, password: this.password + } + }, (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 createUsersWithListInput (body?: Array) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user/createWithList'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'POST', + qs: queryParameters, + uri: path, + json: true, + body: body, + + auth: { + username: this.username, password: this.password + } + }, (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 loginUser (username?: string, password?: string) : Promise<{ response: http.ClientResponse; body: string; }> { + var path = this.url + this.basePath + '/user/login'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + if (username !== undefined) { + queryParameters['username'] = username; + } + + if (password !== undefined) { + queryParameters['password'] = password; + } + + var deferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); + + request({ + method: 'GET', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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 logoutUser () : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user/logout'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'GET', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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 getUserByName (username: string) : Promise<{ response: http.ClientResponse; body: User; }> { + var path = this.url + this.basePath + '/user/{username}'; + + path = path.replace('{' + 'username' + '}', String(username)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling getUserByName'); + } + + var deferred = promise.defer<{ response: http.ClientResponse; body: User; }>(); + + request({ + method: 'GET', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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 updateUser (username: string, body?: User) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user/{username}'; + + path = path.replace('{' + 'username' + '}', String(username)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling updateUser'); + } + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'PUT', + qs: queryParameters, + uri: path, + json: true, + body: body, + + auth: { + username: this.username, password: this.password + } + }, (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 deleteUser (username: string) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/user/{username}'; + + path = path.replace('{' + 'username' + '}', String(username)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling deleteUser'); + } + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'DELETE', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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 PetApi { + private basePath = '/v2'; + + constructor(private url: string, private username: string, private password: string, basePath?: string) { + if (basePath) { + this.basePath = basePath; + } + } + + public updatePet (body?: Pet) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/pet'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'PUT', + qs: queryParameters, + uri: path, + json: true, + body: body, + + auth: { + username: this.username, password: this.password + } + }, (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; }> { + var path = this.url + this.basePath + '/pet'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'POST', + qs: queryParameters, + uri: path, + json: true, + body: body, + + auth: { + username: this.username, password: this.password + } + }, (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; }> { + var path = this.url + this.basePath + '/pet/findByStatus'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + if (status !== undefined) { + queryParameters['status'] = status; + } + + var deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + + request({ + method: 'GET', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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; }> { + var path = this.url + this.basePath + '/pet/findByTags'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + if (tags !== undefined) { + queryParameters['tags'] = tags; + } + + var deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); + + request({ + method: 'GET', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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; }> { + var path = this.url + this.basePath + '/pet/{petId}'; + + path = path.replace('{' + 'petId' + '}', String(petId)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling getPetById'); + } + + var deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); + + request({ + method: 'GET', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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; }> { + var path = this.url + this.basePath + '/pet/{petId}'; + + path = path.replace('{' + 'petId' + '}', String(petId)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling updatePetWithForm'); + } + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'POST', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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; }> { + var path = this.url + this.basePath + '/pet/{petId}'; + + path = path.replace('{' + 'petId' + '}', String(petId)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling deletePet'); + } + + headerParams['apiKey'] = apiKey; + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'DELETE', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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?: file) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/pet/{petId}/uploadImage'; + + path = path.replace('{' + 'petId' + '}', String(petId)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling uploadFile'); + } + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'POST', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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 { + private basePath = '/v2'; + + constructor(private url: string, private username: string, private password: string, basePath?: string) { + if (basePath) { + this.basePath = basePath; + } + } + + public getInventory () : Promise<{ response: http.ClientResponse; body: map; }> { + var path = this.url + this.basePath + '/store/inventory'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + var deferred = promise.defer<{ response: http.ClientResponse; body: map; }>(); + + request({ + method: 'GET', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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 placeOrder (body?: Order) : Promise<{ response: http.ClientResponse; body: Order; }> { + var path = this.url + this.basePath + '/store/order'; + + var queryParameters: any = {}; + var headerParams: any = {}; + + var deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + + request({ + method: 'POST', + qs: queryParameters, + uri: path, + json: true, + body: body, + + auth: { + username: this.username, password: this.password + } + }, (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 getOrderById (orderId: string) : Promise<{ response: http.ClientResponse; body: Order; }> { + var path = this.url + this.basePath + '/store/order/{orderId}'; + + path = path.replace('{' + 'orderId' + '}', String(orderId)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling getOrderById'); + } + + var deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); + + request({ + method: 'GET', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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 deleteOrder (orderId: string) : Promise<{ response: http.ClientResponse; }> { + var path = this.url + this.basePath + '/store/order/{orderId}'; + + path = path.replace('{' + 'orderId' + '}', String(orderId)); + + var queryParameters: any = {}; + var headerParams: any = {}; + + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling deleteOrder'); + } + + var deferred = promise.defer<{ response: http.ClientResponse; }>(); + + request({ + method: 'DELETE', + qs: queryParameters, + uri: path, + json: true, + + auth: { + username: this.username, password: this.password + } + }, (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; + } +} diff --git a/samples/client/petstore/typescript-node/api/PetApi.ts b/samples/client/petstore/typescript-node/api/PetApi.ts deleted file mode 100644 index 02605f2c8a..0000000000 --- a/samples/client/petstore/typescript-node/api/PetApi.ts +++ /dev/null @@ -1,378 +0,0 @@ -/* tslint:disable:no-unused-variable */ - -export class PetApi { - private basePath = 'http://petstore.swagger.io/v2'; - - constructor(private url: string, private username: string, private password: string, basePath?: string) { - if (basePath) { - this.basePath = basePath; - } - } - - - public updatePet (body: Pet ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/pet'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'PUT', - qs: queryParameters, - uri: path, - json: true, - body: body, - - auth: { - username: this.username, password: this.password - } - }, (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; }> { - var path = this.url + this.basePath + '/pet'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'POST', - qs: queryParameters, - uri: path, - json: true, - body: body, - - auth: { - username: this.username, password: this.password - } - }, (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; }> { - var path = this.url + this.basePath + '/pet/findByStatus'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - if (status !== undefined) { - queryParameters['status'] = status; - } - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); - - request({ - method: 'GET', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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; }> { - var path = this.url + this.basePath + '/pet/findByTags'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - if (tags !== undefined) { - queryParameters['tags'] = tags; - } - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: Array; }>(); - - request({ - method: 'GET', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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; }> { - var path = this.url + this.basePath + '/pet/{petId}'; - - - path = path.replace('{' + 'petId' + '}', String(petId)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'petId' is set - if (!petId) { - throw new Error('Missing required parameter petId when calling getPetById'); - } - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: Pet; }>(); - - request({ - method: 'GET', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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; }> { - var path = this.url + this.basePath + '/pet/{petId}'; - - - path = path.replace('{' + 'petId' + '}', String(petId)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'petId' is set - if (!petId) { - throw new Error('Missing required parameter petId when calling updatePetWithForm'); - } - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'POST', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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 (apiKey: string, petId: number ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/pet/{petId}'; - - - path = path.replace('{' + 'petId' + '}', String(petId)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'petId' is set - if (!petId) { - throw new Error('Missing required parameter petId when calling deletePet'); - } - - - - - headerParams['apiKey'] = apiKey; - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'DELETE', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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: file ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/pet/{petId}/uploadImage'; - - - path = path.replace('{' + 'petId' + '}', String(petId)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'petId' is set - if (!petId) { - throw new Error('Missing required parameter petId when calling uploadFile'); - } - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'POST', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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; - } - - -} diff --git a/samples/client/petstore/typescript-node/api/StoreApi.ts b/samples/client/petstore/typescript-node/api/StoreApi.ts deleted file mode 100644 index 71cfe106fc..0000000000 --- a/samples/client/petstore/typescript-node/api/StoreApi.ts +++ /dev/null @@ -1,192 +0,0 @@ -/* tslint:disable:no-unused-variable */ - -export class StoreApi { - private basePath = 'http://petstore.swagger.io/v2'; - - constructor(private url: string, private username: string, private password: string, basePath?: string) { - if (basePath) { - this.basePath = basePath; - } - } - - - public getInventory ( ) : Promise<{ response: http.ClientResponse; body: map; }> { - var path = this.url + this.basePath + '/store/inventory'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: map; }>(); - - request({ - method: 'GET', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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 placeOrder (body: Order ) : Promise<{ response: http.ClientResponse; body: Order; }> { - var path = this.url + this.basePath + '/store/order'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); - - request({ - method: 'POST', - qs: queryParameters, - uri: path, - json: true, - body: body, - - auth: { - username: this.username, password: this.password - } - }, (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 getOrderById (orderId: string ) : Promise<{ response: http.ClientResponse; body: Order; }> { - var path = this.url + this.basePath + '/store/order/{orderId}'; - - - path = path.replace('{' + 'orderId' + '}', String(orderId)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'orderId' is set - if (!orderId) { - throw new Error('Missing required parameter orderId when calling getOrderById'); - } - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: Order; }>(); - - request({ - method: 'GET', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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 deleteOrder (orderId: string ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/store/order/{orderId}'; - - - path = path.replace('{' + 'orderId' + '}', String(orderId)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'orderId' is set - if (!orderId) { - throw new Error('Missing required parameter orderId when calling deleteOrder'); - } - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'DELETE', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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; - } - - -} diff --git a/samples/client/petstore/typescript-node/api/UserApi.ts b/samples/client/petstore/typescript-node/api/UserApi.ts deleted file mode 100644 index ca6fd41c59..0000000000 --- a/samples/client/petstore/typescript-node/api/UserApi.ts +++ /dev/null @@ -1,372 +0,0 @@ -/* tslint:disable:no-unused-variable */ - -export class UserApi { - private basePath = 'http://petstore.swagger.io/v2'; - - constructor(private url: string, private username: string, private password: string, basePath?: string) { - if (basePath) { - this.basePath = basePath; - } - } - - - public createUser (body: User ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/user'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'POST', - qs: queryParameters, - uri: path, - json: true, - body: body, - - auth: { - username: this.username, password: this.password - } - }, (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 createUsersWithArrayInput (body: Array ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/user/createWithArray'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'POST', - qs: queryParameters, - uri: path, - json: true, - body: body, - - auth: { - username: this.username, password: this.password - } - }, (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 createUsersWithListInput (body: Array ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/user/createWithList'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'POST', - qs: queryParameters, - uri: path, - json: true, - body: body, - - auth: { - username: this.username, password: this.password - } - }, (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 loginUser (username: string, password: string ) : Promise<{ response: http.ClientResponse; body: string; }> { - var path = this.url + this.basePath + '/user/login'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - if (username !== undefined) { - queryParameters['username'] = username; - } - if (password !== undefined) { - queryParameters['password'] = password; - } - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: string; }>(); - - request({ - method: 'GET', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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 logoutUser ( ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/user/logout'; - - - - var queryParameters: any = {}; - var headers: any = {}; - - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'GET', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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 getUserByName (username: string ) : Promise<{ response: http.ClientResponse; body: User; }> { - var path = this.url + this.basePath + '/user/{username}'; - - - path = path.replace('{' + 'username' + '}', String(username)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'username' is set - if (!username) { - throw new Error('Missing required parameter username when calling getUserByName'); - } - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; body: User; }>(); - - request({ - method: 'GET', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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 updateUser (username: string, body: User ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/user/{username}'; - - - path = path.replace('{' + 'username' + '}', String(username)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'username' is set - if (!username) { - throw new Error('Missing required parameter username when calling updateUser'); - } - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'PUT', - qs: queryParameters, - uri: path, - json: true, - body: body, - - auth: { - username: this.username, password: this.password - } - }, (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 deleteUser (username: string ) : Promise<{ response: http.ClientResponse; }> { - var path = this.url + this.basePath + '/user/{username}'; - - - path = path.replace('{' + 'username' + '}', String(username)); - - - var queryParameters: any = {}; - var headers: any = {}; - - - // verify required parameter 'username' is set - if (!username) { - throw new Error('Missing required parameter username when calling deleteUser'); - } - - - - - - - var deferred = promise.defer<{ response: http.ClientResponse; }>(); - - request({ - method: 'DELETE', - qs: queryParameters, - uri: path, - json: true, - - auth: { - username: this.username, password: this.password - } - }, (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; - } - - -} diff --git a/samples/client/petstore/typescript-node/model/Category.ts b/samples/client/petstore/typescript-node/model/Category.ts deleted file mode 100644 index fc4b2874e9..0000000000 --- a/samples/client/petstore/typescript-node/model/Category.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class Category { - - id: number; - - name: string; -} - diff --git a/samples/client/petstore/typescript-node/model/Order.ts b/samples/client/petstore/typescript-node/model/Order.ts deleted file mode 100644 index b46ad4570a..0000000000 --- a/samples/client/petstore/typescript-node/model/Order.ts +++ /dev/null @@ -1,26 +0,0 @@ -export class Order { - - id: number; - - petId: number; - - quantity: number; - - shipDate: DateTime; - - /** - * Order Status - */ - status: Order.StatusEnum; - - complete: boolean; -} - -export module Order { - - export enum StatusEnum { - placed = 'placed', - approved = 'approved', - delivered = 'delivered', - } -} diff --git a/samples/client/petstore/typescript-node/model/Pet.ts b/samples/client/petstore/typescript-node/model/Pet.ts deleted file mode 100644 index 4a3faa129e..0000000000 --- a/samples/client/petstore/typescript-node/model/Pet.ts +++ /dev/null @@ -1,26 +0,0 @@ -export class Pet { - - id: number; - - category: Category; - - name: string; - - photoUrls: Array; - - tags: Array; - - /** - * pet status in the store - */ - status: Pet.StatusEnum; -} - -export module Pet { - - export enum StatusEnum { - available = 'available', - pending = 'pending', - sold = 'sold', - } -} diff --git a/samples/client/petstore/typescript-node/model/Tag.ts b/samples/client/petstore/typescript-node/model/Tag.ts deleted file mode 100644 index 6ae0d4ef57..0000000000 --- a/samples/client/petstore/typescript-node/model/Tag.ts +++ /dev/null @@ -1,7 +0,0 @@ -export class Tag { - - id: number; - - name: string; -} - diff --git a/samples/client/petstore/typescript-node/model/User.ts b/samples/client/petstore/typescript-node/model/User.ts deleted file mode 100644 index fee31563d1..0000000000 --- a/samples/client/petstore/typescript-node/model/User.ts +++ /dev/null @@ -1,22 +0,0 @@ -export class User { - - id: number; - - username: string; - - firstName: string; - - lastName: string; - - email: string; - - password: string; - - phone: string; - - /** - * User Status - */ - userStatus: number; -} -