forked from loafle/openapi-generator-original
[Typescript] Improve exception for unknown responses (#10361)
* Clean up tests * Change pets to async-await * Use different pets for each test * Workaround multiple petstore server instances * Add test for unknown error response code * Remove call duplication Running the petstore server locally fixes all issues. * Make body of unexpected error responses available * Regenerate all consolidated typescript samples * Remove json heuristic for unknown error responses
This commit is contained in:
parent
476a82cb75
commit
be3bd2e6c7
@ -200,7 +200,7 @@ export class {{classname}}ResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
{{/is2xx}}
|
{{/is2xx}}
|
||||||
{{^is2xx}}
|
{{^is2xx}}
|
||||||
throw new ApiException<{{{dataType}}}>({{code}}, body);
|
throw new ApiException<{{{dataType}}}>({{code}}, "{{message}}", body);
|
||||||
{{/is2xx}}
|
{{/is2xx}}
|
||||||
{{/dataType}}
|
{{/dataType}}
|
||||||
{{^dataType}}
|
{{^dataType}}
|
||||||
@ -208,7 +208,7 @@ export class {{classname}}ResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
{{/is2xx}}
|
{{/is2xx}}
|
||||||
{{^is2xx}}
|
{{^is2xx}}
|
||||||
throw new ApiException<string>(response.httpStatusCode, "{{message}}");
|
throw new ApiException<undefined>(response.httpStatusCode, "{{message}}", undefined);
|
||||||
{{/is2xx}}
|
{{/is2xx}}
|
||||||
{{/dataType}}
|
{{/dataType}}
|
||||||
}
|
}
|
||||||
@ -233,8 +233,7 @@ export class {{classname}}ResponseProcessor {
|
|||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | {{{fileContentDataType}}} | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class ApiException<T> extends Error {
|
export class ApiException<T> extends Error {
|
||||||
public constructor(public code: number, public body: T) {
|
public constructor(public code: number, message: string, public body: T) {
|
||||||
super("HTTP-Code: " + code + "\nMessage: " + JSON.stringify(body))
|
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -287,6 +287,22 @@ export class ResponseContext {
|
|||||||
{{/node}}
|
{{/node}}
|
||||||
{{/platforms}}
|
{{/platforms}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a heuristic to get a body of unknown data structure.
|
||||||
|
* Return as string if possible, otherwise as binary.
|
||||||
|
*/
|
||||||
|
public getBodyAsAny(): Promise<string | {{{fileContentDataType}}} | undefined> {
|
||||||
|
try {
|
||||||
|
return this.body.text();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return this.body.binary();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HttpLibrary {
|
export interface HttpLibrary {
|
||||||
|
@ -134,8 +134,7 @@ export class DefaultApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,8 +159,7 @@ export class DefaultApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,8 +184,7 @@ export class DefaultApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class ApiException<T> extends Error {
|
export class ApiException<T> extends Error {
|
||||||
public constructor(public code: number, public body: T) {
|
public constructor(public code: number, message: string, public body: T) {
|
||||||
super("HTTP-Code: " + code + "\nMessage: " + JSON.stringify(body))
|
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,22 @@ export class ResponseContext {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a heuristic to get a body of unknown data structure.
|
||||||
|
* Return as string if possible, otherwise as binary.
|
||||||
|
*/
|
||||||
|
public getBodyAsAny(): Promise<string | Blob | undefined> {
|
||||||
|
try {
|
||||||
|
return this.body.text();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return this.body.binary();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HttpLibrary {
|
export interface HttpLibrary {
|
||||||
|
@ -402,7 +402,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -414,8 +414,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -428,7 +427,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async deletePet(response: ResponseContext): Promise< void> {
|
public async deletePet(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid pet value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid pet value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -436,8 +435,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -457,7 +455,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid status value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid status value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -469,8 +467,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -490,7 +487,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid tag value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid tag value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -502,8 +499,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -523,10 +519,10 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -538,8 +534,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -559,13 +554,13 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Validation exception");
|
throw new ApiException<undefined>(response.httpStatusCode, "Validation exception", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -577,8 +572,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -591,7 +585,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -599,8 +593,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -629,8 +622,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,10 @@ export class StoreApiResponseProcessor {
|
|||||||
public async deleteOrder(response: ResponseContext): Promise< void> {
|
public async deleteOrder(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -156,8 +156,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,8 +185,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -207,10 +205,10 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -222,8 +220,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,7 +240,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid Order");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid Order", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -255,8 +252,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUser(response: ResponseContext): Promise< void> {
|
public async createUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -341,8 +341,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,7 +354,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -363,8 +362,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -377,7 +375,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -385,8 +383,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -399,10 +396,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async deleteUser(response: ResponseContext): Promise< void> {
|
public async deleteUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -410,8 +407,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -431,10 +427,10 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -446,8 +442,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -467,7 +462,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username/password supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username/password supplied", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -479,8 +474,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -493,7 +487,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async logoutUser(response: ResponseContext): Promise< void> {
|
public async logoutUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -501,8 +495,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -515,10 +508,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async updateUser(response: ResponseContext): Promise< void> {
|
public async updateUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid user supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid user supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -526,8 +519,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class ApiException<T> extends Error {
|
export class ApiException<T> extends Error {
|
||||||
public constructor(public code: number, public body: T) {
|
public constructor(public code: number, message: string, public body: T) {
|
||||||
super("HTTP-Code: " + code + "\nMessage: " + JSON.stringify(body))
|
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,22 @@ export class ResponseContext {
|
|||||||
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
|
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
|
||||||
return { data, name: fileName };
|
return { data, name: fileName };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a heuristic to get a body of unknown data structure.
|
||||||
|
* Return as string if possible, otherwise as binary.
|
||||||
|
*/
|
||||||
|
public getBodyAsAny(): Promise<string | Buffer | undefined> {
|
||||||
|
try {
|
||||||
|
return this.body.text();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return this.body.binary();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HttpLibrary {
|
export interface HttpLibrary {
|
||||||
|
@ -400,7 +400,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -412,8 +412,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -426,7 +425,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async deletePet(response: ResponseContext): Promise< void> {
|
public async deletePet(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid pet value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid pet value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -434,8 +433,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -455,7 +453,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid status value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid status value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -467,8 +465,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -488,7 +485,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid tag value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid tag value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -500,8 +497,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -521,10 +517,10 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -536,8 +532,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -557,13 +552,13 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Validation exception");
|
throw new ApiException<undefined>(response.httpStatusCode, "Validation exception", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -575,8 +570,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -589,7 +583,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -597,8 +591,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -627,8 +620,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -143,10 +143,10 @@ export class StoreApiResponseProcessor {
|
|||||||
public async deleteOrder(response: ResponseContext): Promise< void> {
|
public async deleteOrder(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -154,8 +154,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,8 +183,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,10 +203,10 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -220,8 +218,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -241,7 +238,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid Order");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid Order", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -253,8 +250,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUser(response: ResponseContext): Promise< void> {
|
public async createUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -339,8 +339,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,7 +352,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -361,8 +360,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -375,7 +373,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -383,8 +381,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -397,10 +394,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async deleteUser(response: ResponseContext): Promise< void> {
|
public async deleteUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -408,8 +405,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -429,10 +425,10 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -444,8 +440,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -465,7 +460,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username/password supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username/password supplied", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -477,8 +472,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -491,7 +485,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async logoutUser(response: ResponseContext): Promise< void> {
|
public async logoutUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -499,8 +493,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -513,10 +506,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async updateUser(response: ResponseContext): Promise< void> {
|
public async updateUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid user supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid user supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -524,8 +517,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class ApiException<T> extends Error {
|
export class ApiException<T> extends Error {
|
||||||
public constructor(public code: number, public body: T) {
|
public constructor(public code: number, message: string, public body: T) {
|
||||||
super("HTTP-Code: " + code + "\nMessage: " + JSON.stringify(body))
|
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,6 +219,22 @@ export class ResponseContext {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a heuristic to get a body of unknown data structure.
|
||||||
|
* Return as string if possible, otherwise as binary.
|
||||||
|
*/
|
||||||
|
public getBodyAsAny(): Promise<string | Blob | undefined> {
|
||||||
|
try {
|
||||||
|
return this.body.text();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return this.body.binary();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HttpLibrary {
|
export interface HttpLibrary {
|
||||||
|
@ -405,7 +405,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -417,8 +417,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -431,7 +430,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async deletePet(response: ResponseContext): Promise< void> {
|
public async deletePet(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid pet value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid pet value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -439,8 +438,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -460,7 +458,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid status value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid status value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -472,8 +470,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -493,7 +490,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid tag value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid tag value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -505,8 +502,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -526,10 +522,10 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -541,8 +537,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -562,13 +557,13 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Validation exception");
|
throw new ApiException<undefined>(response.httpStatusCode, "Validation exception", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -580,8 +575,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -594,7 +588,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -602,8 +596,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -632,8 +625,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -148,10 +148,10 @@ export class StoreApiResponseProcessor {
|
|||||||
public async deleteOrder(response: ResponseContext): Promise< void> {
|
public async deleteOrder(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -159,8 +159,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -189,8 +188,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -210,10 +208,10 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -225,8 +223,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -246,7 +243,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid Order");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid Order", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -258,8 +255,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -336,7 +336,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUser(response: ResponseContext): Promise< void> {
|
public async createUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -344,8 +344,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -358,7 +357,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -366,8 +365,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -380,7 +378,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -388,8 +386,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -402,10 +399,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async deleteUser(response: ResponseContext): Promise< void> {
|
public async deleteUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -413,8 +410,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -434,10 +430,10 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -449,8 +445,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -470,7 +465,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username/password supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username/password supplied", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -482,8 +477,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -496,7 +490,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async logoutUser(response: ResponseContext): Promise< void> {
|
public async logoutUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -504,8 +498,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -518,10 +511,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async updateUser(response: ResponseContext): Promise< void> {
|
public async updateUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid user supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid user supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -529,8 +522,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class ApiException<T> extends Error {
|
export class ApiException<T> extends Error {
|
||||||
public constructor(public code: number, public body: T) {
|
public constructor(public code: number, message: string, public body: T) {
|
||||||
super("HTTP-Code: " + code + "\nMessage: " + JSON.stringify(body))
|
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,22 @@ export class ResponseContext {
|
|||||||
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
|
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
|
||||||
return { data, name: fileName };
|
return { data, name: fileName };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a heuristic to get a body of unknown data structure.
|
||||||
|
* Return as string if possible, otherwise as binary.
|
||||||
|
*/
|
||||||
|
public getBodyAsAny(): Promise<string | Buffer | undefined> {
|
||||||
|
try {
|
||||||
|
return this.body.text();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return this.body.binary();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HttpLibrary {
|
export interface HttpLibrary {
|
||||||
|
@ -400,7 +400,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -412,8 +412,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -426,7 +425,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async deletePet(response: ResponseContext): Promise< void> {
|
public async deletePet(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid pet value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid pet value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -434,8 +433,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -455,7 +453,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid status value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid status value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -467,8 +465,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -488,7 +485,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid tag value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid tag value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -500,8 +497,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -521,10 +517,10 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -536,8 +532,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -557,13 +552,13 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Validation exception");
|
throw new ApiException<undefined>(response.httpStatusCode, "Validation exception", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -575,8 +570,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -589,7 +583,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -597,8 +591,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -627,8 +620,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -143,10 +143,10 @@ export class StoreApiResponseProcessor {
|
|||||||
public async deleteOrder(response: ResponseContext): Promise< void> {
|
public async deleteOrder(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -154,8 +154,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,8 +183,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,10 +203,10 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -220,8 +218,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -241,7 +238,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid Order");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid Order", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -253,8 +250,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -331,7 +331,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUser(response: ResponseContext): Promise< void> {
|
public async createUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -339,8 +339,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -353,7 +352,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -361,8 +360,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -375,7 +373,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -383,8 +381,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -397,10 +394,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async deleteUser(response: ResponseContext): Promise< void> {
|
public async deleteUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -408,8 +405,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -429,10 +425,10 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -444,8 +440,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -465,7 +460,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username/password supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username/password supplied", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -477,8 +472,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -491,7 +485,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async logoutUser(response: ResponseContext): Promise< void> {
|
public async logoutUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -499,8 +493,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -513,10 +506,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async updateUser(response: ResponseContext): Promise< void> {
|
public async updateUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid user supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid user supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -524,8 +517,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Blob | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class ApiException<T> extends Error {
|
export class ApiException<T> extends Error {
|
||||||
public constructor(public code: number, public body: T) {
|
public constructor(public code: number, message: string, public body: T) {
|
||||||
super("HTTP-Code: " + code + "\nMessage: " + JSON.stringify(body))
|
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,6 +201,22 @@ export class ResponseContext {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a heuristic to get a body of unknown data structure.
|
||||||
|
* Return as string if possible, otherwise as binary.
|
||||||
|
*/
|
||||||
|
public getBodyAsAny(): Promise<string | Blob | undefined> {
|
||||||
|
try {
|
||||||
|
return this.body.text();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return this.body.binary();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HttpLibrary {
|
export interface HttpLibrary {
|
||||||
|
@ -402,7 +402,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -414,8 +414,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -428,7 +427,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async deletePet(response: ResponseContext): Promise< void> {
|
public async deletePet(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid pet value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid pet value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -436,8 +435,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -457,7 +455,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid status value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid status value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -469,8 +467,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -490,7 +487,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid tag value");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid tag value", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -502,8 +499,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -523,10 +519,10 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -538,8 +534,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -559,13 +554,13 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Pet not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Pet not found", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Validation exception");
|
throw new ApiException<undefined>(response.httpStatusCode, "Validation exception", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -577,8 +572,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -591,7 +585,7 @@ export class PetApiResponseProcessor {
|
|||||||
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
public async updatePetWithForm(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid input");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid input", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -599,8 +593,7 @@ export class PetApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -629,8 +622,7 @@ export class PetApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,10 @@ export class StoreApiResponseProcessor {
|
|||||||
public async deleteOrder(response: ResponseContext): Promise< void> {
|
public async deleteOrder(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -156,8 +156,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,8 +185,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -207,10 +205,10 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid ID supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Order not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "Order not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -222,8 +220,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -243,7 +240,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid Order");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid Order", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -255,8 +252,7 @@ export class StoreApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUser(response: ResponseContext): Promise< void> {
|
public async createUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -341,8 +341,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -355,7 +354,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -363,8 +362,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -377,7 +375,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
public async createUsersWithListInput(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -385,8 +383,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -399,10 +396,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async deleteUser(response: ResponseContext): Promise< void> {
|
public async deleteUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -410,8 +407,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -431,10 +427,10 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -446,8 +442,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -467,7 +462,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username/password supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid username/password supplied", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -479,8 +474,7 @@ export class UserApiResponseProcessor {
|
|||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -493,7 +487,7 @@ export class UserApiResponseProcessor {
|
|||||||
public async logoutUser(response: ResponseContext): Promise< void> {
|
public async logoutUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("0", response.httpStatusCode)) {
|
if (isCodeInRange("0", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "successful operation");
|
throw new ApiException<undefined>(response.httpStatusCode, "successful operation", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -501,8 +495,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -515,10 +508,10 @@ export class UserApiResponseProcessor {
|
|||||||
public async updateUser(response: ResponseContext): Promise< void> {
|
public async updateUser(response: ResponseContext): Promise< void> {
|
||||||
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
|
||||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Invalid user supplied");
|
throw new ApiException<undefined>(response.httpStatusCode, "Invalid user supplied", undefined);
|
||||||
}
|
}
|
||||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||||
throw new ApiException<string>(response.httpStatusCode, "User not found");
|
throw new ApiException<undefined>(response.httpStatusCode, "User not found", undefined);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work around for missing responses in specification, e.g. for petstore.yaml
|
// Work around for missing responses in specification, e.g. for petstore.yaml
|
||||||
@ -526,8 +519,7 @@ export class UserApiResponseProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let body = response.body || "";
|
throw new ApiException<string | Buffer | undefined>(response.httpStatusCode, "Unknown API Status Code!", await response.getBodyAsAny());
|
||||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export class ApiException<T> extends Error {
|
export class ApiException<T> extends Error {
|
||||||
public constructor(public code: number, public body: T) {
|
public constructor(public code: number, message: string, public body: T) {
|
||||||
super("HTTP-Code: " + code + "\nMessage: " + JSON.stringify(body))
|
super("HTTP-Code: " + code + "\nMessage: " + message + "\nBody: " + JSON.stringify(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,22 @@ export class ResponseContext {
|
|||||||
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
|
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
|
||||||
return { data, name: fileName };
|
return { data, name: fileName };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a heuristic to get a body of unknown data structure.
|
||||||
|
* Return as string if possible, otherwise as binary.
|
||||||
|
*/
|
||||||
|
public getBodyAsAny(): Promise<string | Buffer | undefined> {
|
||||||
|
try {
|
||||||
|
return this.body.text();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return this.body.binary();
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
return Promise.resolve(undefined);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HttpLibrary {
|
export interface HttpLibrary {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
|||||||
import * as petstore from 'ts-petstore-client'
|
import * as petstore from 'ts-petstore-client'
|
||||||
|
|
||||||
import { expect, assert } from "chai";
|
import { expect } from "chai";
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
const configuration = petstore.createConfiguration()
|
const configuration = petstore.createConfiguration()
|
||||||
@ -10,122 +10,96 @@ const tag = new petstore.Tag();
|
|||||||
tag.name = "tag1"
|
tag.name = "tag1"
|
||||||
tag.id = Math.floor(Math.random() * 100000)
|
tag.id = Math.floor(Math.random() * 100000)
|
||||||
|
|
||||||
const pet = new petstore.Pet()
|
let pet: petstore.Pet;
|
||||||
pet.id = Math.floor(Math.random() * 100000)
|
|
||||||
pet.name = "PetName"
|
|
||||||
pet.photoUrls = []
|
|
||||||
pet.status = 'available'
|
|
||||||
pet.tags = [ tag ]
|
|
||||||
pet.category = undefined
|
|
||||||
|
|
||||||
describe("PetApi", () =>{
|
describe("PetApi", () => {
|
||||||
it("addPet", (done) => {
|
beforeEach(async () => {
|
||||||
petApi.addPet(pet).then(() => {
|
pet = new petstore.Pet()
|
||||||
return petApi.getPetById(pet.id)
|
pet.id = Math.floor(Math.random() * 100000)
|
||||||
}).then((createdPet: petstore.Pet) => {
|
pet.name = "PetName"
|
||||||
expect(createdPet).to.deep.equal(pet);
|
pet.photoUrls = []
|
||||||
done()
|
pet.status = 'available'
|
||||||
}).catch((err: any) => {
|
pet.tags = [ tag ]
|
||||||
done(err)
|
pet.category = undefined
|
||||||
})
|
|
||||||
|
await petApi.addPet(pet);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("addPet", async () => {
|
||||||
|
const createdPet = await petApi.getPetById(pet.id)
|
||||||
|
expect(createdPet).to.deep.equal(pet);
|
||||||
})
|
})
|
||||||
|
|
||||||
it("deletePet", (done) => {
|
it("deletePet", async () => {
|
||||||
petApi.addPet(pet).then(() => {
|
await petApi.deletePet(pet.id);
|
||||||
return petApi.deletePet(pet.id)
|
let deletedPet;
|
||||||
}).then(() => {
|
try {
|
||||||
return petApi.getPetById(pet.id)
|
deletedPet = await petApi.getPetById(pet.id)
|
||||||
}).then((pet: petstore.Pet) => {
|
} catch (err) {
|
||||||
done("Pet with id " + pet.id + " was not deleted!");
|
expect(err.code).to.equal(404);
|
||||||
}).catch((err: any) => {
|
expect(err.message).to.include("Pet not found");
|
||||||
if (err.code && err.code == 404) {
|
return;
|
||||||
done();
|
}
|
||||||
} else {
|
throw new Error("Pet with id " + deletedPet.id + " was not deleted!");
|
||||||
done(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("findPetsByStatus", (done) => {
|
it("deleteNonExistantPet", async () => {
|
||||||
petApi.addPet(pet).then(() => {
|
// Use an id that is too big for the server to handle.
|
||||||
return petApi.findPetsByStatus(["available"])
|
const nonExistantId = 100000000000000000000000000;
|
||||||
}).then((pets: petstore.Pet[]) => {
|
try {
|
||||||
expect(pets.length).to.be.at.least(1);
|
await petApi.deletePet(nonExistantId)
|
||||||
done();
|
} catch (err) {
|
||||||
}).catch((err: any) => {
|
// The 404 response for this endpoint is officially documented, but
|
||||||
done(err)
|
// that documentation is not used for generating the client code.
|
||||||
})
|
// That means we get an error about the response being undefined
|
||||||
|
// here.
|
||||||
|
expect(err.code).to.equal(404);
|
||||||
|
expect(err.message).to.include("Unknown API Status Code");
|
||||||
|
expect(err.body).to.include("404");
|
||||||
|
expect(err.body).to.include("message");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new Error("Deleted non-existant pet with id " + nonExistantId + "!");
|
||||||
})
|
})
|
||||||
|
|
||||||
// bugged on server side! Code 500
|
it("findPetsByStatus", async () => {
|
||||||
/* it("findPetsByTag", (done) => {
|
const pets = await petApi.findPetsByStatus(["available"]);
|
||||||
petApi.addPet(pet).then(() => {
|
expect(pets.length).to.be.at.least(1);
|
||||||
return petApi.findPetsByTags([tag.name])
|
|
||||||
}).then((pets: Pet[]) => {
|
|
||||||
expect(pets.length).to.be.at.least(1);
|
|
||||||
done();
|
|
||||||
}).catch((err: any) => {
|
|
||||||
done(err);
|
|
||||||
})
|
|
||||||
})*/
|
|
||||||
|
|
||||||
it("getPetById", (done) => {
|
|
||||||
petApi.addPet(pet).then(() => {
|
|
||||||
return petApi.getPetById(pet.id)
|
|
||||||
}).then((returnedPet: petstore.Pet) => {
|
|
||||||
expect(returnedPet).to.deep.equal(pet);
|
|
||||||
done();
|
|
||||||
}).catch((err: any) => {
|
|
||||||
done(err);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("updatePet", (done) => {
|
it("findPetsByTag", async () => {
|
||||||
const oldName = pet.name
|
const pets = await petApi.findPetsByTags([tag.name])
|
||||||
|
expect(pets.length).to.be.at.least(1);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("getPetById", async () => {
|
||||||
|
const returnedPet = await petApi.getPetById(pet.id);
|
||||||
|
expect(returnedPet).to.deep.equal(pet);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("updatePet", async () => {
|
||||||
|
pet.name = "updated name";
|
||||||
|
await petApi.updatePet(pet);
|
||||||
|
await petApi.updatePet(pet);
|
||||||
|
|
||||||
|
const returnedPet = await petApi.getPetById(pet.id);
|
||||||
|
expect(returnedPet.id).to.equal(pet.id)
|
||||||
|
expect(returnedPet.name).to.equal(pet.name);
|
||||||
|
})
|
||||||
|
|
||||||
|
it("updatePetWithForm", async () => {
|
||||||
const updatedName = "updated name";
|
const updatedName = "updated name";
|
||||||
petApi.addPet(pet).then(() => {
|
await petApi.updatePetWithForm(pet.id, updatedName);
|
||||||
pet.name = updatedName
|
|
||||||
return petApi.updatePet(pet).then(() => {
|
const returnedPet = await petApi.getPetById(pet.id)
|
||||||
pet.name = oldName;
|
expect(returnedPet.id).to.equal(pet.id)
|
||||||
}).catch((err: any) => {
|
expect(returnedPet.name).to.equal(updatedName);
|
||||||
pet.name = oldName
|
|
||||||
throw err;
|
|
||||||
});
|
|
||||||
}).then(() => {
|
|
||||||
return petApi.getPetById(pet.id);
|
|
||||||
}).then((returnedPet: petstore.Pet) => {
|
|
||||||
expect(returnedPet.id).to.equal(pet.id)
|
|
||||||
expect(returnedPet.name).to.equal(updatedName);
|
|
||||||
done();
|
|
||||||
}).catch((err: any) => {
|
|
||||||
done(err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// not supported by online swagger api?
|
it("uploadFile", async () => {
|
||||||
/* it("updatePetWithForm", (done) => {
|
|
||||||
const updatedName = "updated name";
|
|
||||||
petApi.addPet(pet).then(() => {
|
|
||||||
return petApi.updatePetWithForm(pet.id, updatedName)
|
|
||||||
}).then(() => {
|
|
||||||
return petApi.getPetById(pet.id)
|
|
||||||
}).then((returnedPet: Pet) => {
|
|
||||||
expect(returnedPet.id).to.equal(pet.id)
|
|
||||||
expect(returnedPet.name).to.equal(updatedName);
|
|
||||||
done()
|
|
||||||
}).catch((err: any) => {
|
|
||||||
done(err)
|
|
||||||
})
|
|
||||||
})*/
|
|
||||||
|
|
||||||
it("uploadFile", (done) => {
|
|
||||||
const image = fs.readFileSync(__dirname + "/pet.png")
|
const image = fs.readFileSync(__dirname + "/pet.png")
|
||||||
petApi.uploadFile(pet.id, "Metadata", { name: "pet.png", data: image}).then((response: any) => {
|
const response = await petApi.uploadFile(pet.id, "Metadata", { name: "pet.png", data: image});
|
||||||
expect(response.code).to.be.gte(200).and.lt(300);
|
expect(response.code).to.be.gte(200).and.lt(300);
|
||||||
expect(response.message).to.contain("pet.png");
|
expect(response.message).to.contain("pet.png");
|
||||||
done();
|
|
||||||
}).catch((err: any) => {
|
|
||||||
done(err);
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
Loading…
x
Reference in New Issue
Block a user