mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Combine TypeScript node output in one file and add missing require statements
This commit is contained in:
parent
cde8d7ba4c
commit
646da19c7d
@ -20,6 +20,7 @@ public class TypeScriptAngularClientCodegen extends TypeScriptNodeClientCodegen
|
||||
apiPackage = "api";
|
||||
modelPackage = "model";
|
||||
|
||||
supportingFiles.clear();
|
||||
supportingFiles.add(new SupportingFile("api.d.mustache", apiPackage + File.separator, "api.d.ts"));
|
||||
}
|
||||
}
|
@ -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<String>(Arrays.asList("abstract",
|
||||
"continue", "for", "new", "switch", "assert", "default", "if",
|
||||
|
@ -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}}
|
||||
{{.}} = <any> '{{.}}',{{/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}}
|
||||
|
@ -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}}
|
||||
{{.}} = <any> '{{.}}',{{/values}}{{/allowableValues}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
}
|
||||
{{/hasEnums}}
|
||||
{{/model}}
|
||||
{{/models}}
|
828
samples/client/petstore/typescript-node/api.ts
Normal file
828
samples/client/petstore/typescript-node/api.ts
Normal file
@ -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<string>;
|
||||
tags: Array<Tag>;
|
||||
/**
|
||||
* pet status in the store
|
||||
*/
|
||||
status: Pet.StatusEnum;
|
||||
}
|
||||
|
||||
export module Pet {
|
||||
export enum StatusEnum {
|
||||
available = <any> 'available',
|
||||
pending = <any> 'pending',
|
||||
sold = <any> '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 = <any> 'placed',
|
||||
approved = <any> 'approved',
|
||||
delivered = <any> '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<User>) : 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<User>) : 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<string>) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
|
||||
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<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 findPetsByTags (tags?: Array<string>) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
|
||||
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<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 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<String, number>; }> {
|
||||
var path = this.url + this.basePath + '/store/inventory';
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headerParams: any = {};
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: map<String, number>; }>();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -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<string> ) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
|
||||
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<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 findPetsByTags (tags: Array<string> ) : Promise<{ response: http.ClientResponse; body: Array<Pet>; }> {
|
||||
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<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 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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<String, number>; }> {
|
||||
var path = this.url + this.basePath + '/store/inventory';
|
||||
|
||||
|
||||
|
||||
var queryParameters: any = {};
|
||||
var headers: any = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
var deferred = promise.defer<{ response: http.ClientResponse; body: map<String, number>; }>();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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<User> ) : 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<User> ) : 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
export class Category {
|
||||
|
||||
id: number;
|
||||
|
||||
name: string;
|
||||
}
|
||||
|
@ -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 = <any> 'placed',
|
||||
approved = <any> 'approved',
|
||||
delivered = <any> 'delivered',
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
export class Pet {
|
||||
|
||||
id: number;
|
||||
|
||||
category: Category;
|
||||
|
||||
name: string;
|
||||
|
||||
photoUrls: Array<string>;
|
||||
|
||||
tags: Array<Tag>;
|
||||
|
||||
/**
|
||||
* pet status in the store
|
||||
*/
|
||||
status: Pet.StatusEnum;
|
||||
}
|
||||
|
||||
export module Pet {
|
||||
|
||||
export enum StatusEnum {
|
||||
available = <any> 'available',
|
||||
pending = <any> 'pending',
|
||||
sold = <any> 'sold',
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
export class Tag {
|
||||
|
||||
id: number;
|
||||
|
||||
name: string;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user