Support media types other than json (#6177)

List of changes:

* Add */* as fallback to accept header

* Use more sophisticated media type selection

* Handle object stringify in ObjectSerializer

* Parse response with ObejctSerializer

* Fix: Correctly extract response headers in browser

* Create HttpFile objects from responses

* Handle binary responses

* Clean up dependencies and replace isomorphic-fetch

Instead of isomorphic-fetch, which is unmaintained, we directly use
node-fetch and whatwg-fetch polyfills.
This commit is contained in:
Bodo Graumann 2020-05-22 21:54:52 +02:00 committed by GitHub
parent 659369c3ea
commit e315d48636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 1528 additions and 1226 deletions

View File

@ -52,7 +52,7 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.{{httpMethod}}); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.{{httpMethod}});
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
{{#queryParams}} {{#queryParams}}
@ -96,9 +96,9 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
{{#node}} {{#node}}
localVarFormParams.append('{{baseName}}', {{paramName}}.data, {{paramName}}.name); localVarFormParams.append('{{baseName}}', {{paramName}}.data, {{paramName}}.name);
{{/node}} {{/node}}
{{^node}} {{#browser}}
localVarFormParams.append('{{baseName}}', {{paramName}}, {{paramName}}.name); localVarFormParams.append('{{baseName}}', {{paramName}}, {{paramName}}.name);
{{/node}} {{/browser}}
{{/platforms}} {{/platforms}}
{{/isFile}} {{/isFile}}
} }
@ -110,15 +110,14 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
{{#bodyParam}} {{#bodyParam}}
{{^consumes}} const contentType = ObjectSerializer.getPreferredMediaType([{{#consumes}}
requestContext.setHeaderParam("Content-Type", "application/json"); "{{{mediaType}}}"{{#hasMore}},{{/hasMore}}
{{/consumes}} {{/consumes}}]);
{{#consumes.0}} requestContext.setHeaderParam("Content-Type", contentType);
requestContext.setHeaderParam("Content-Type", "{{{mediaType}}}"); const serializedBody = ObjectSerializer.stringify(
{{/consumes.0}} ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"),
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent contentType
const needsSerialization = (<any>"{{dataType}}" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; );
const serializedBody = needsSerialization ? JSON.stringify({{paramName}} || {}) : ({{paramName}} || "").toString(); // TODO: `toString` call is unnecessary
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
{{/bodyParam}} {{/bodyParam}}
@ -153,12 +152,20 @@ export class {{classname}}ResponseProcessor {
* @params response Response returned by the server for a request to {{nickname}} * @params response Response returned by the server for a request to {{nickname}}
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public {{nickname}}(response: ResponseContext): {{#returnType}} {{{returnType}}}{{/returnType}} {{^returnType}} void {{/returnType}} { public async {{nickname}}(response: ResponseContext): Promise<{{#returnType}}{{{returnType}}}{{/returnType}} {{^returnType}}void{{/returnType}}> {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
{{#responses}} {{#responses}}
if (isCodeInRange("{{code}}", response.httpStatusCode)) { if (isCodeInRange("{{code}}", response.httpStatusCode)) {
{{#dataType}} {{#dataType}}
const jsonBody = JSON.parse(response.body); {{#isBinary}}
const body: {{{dataType}}} = ObjectSerializer.deserialize(jsonBody, "{{{dataType}}}", "{{returnFormat}}") as {{{dataType}}}; const body: {{{dataType}}} = await response.getBodyAsFile() as any as {{{returnType}}};
{{/isBinary}}
{{^isBinary}}
const body: {{{dataType}}} = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"{{{dataType}}}", "{{returnFormat}}"
) as {{{dataType}}};
{{/isBinary}}
{{#isSuccessCode}} {{#isSuccessCode}}
return body; return body;
{{/isSuccessCode}} {{/isSuccessCode}}
@ -177,17 +184,25 @@ export class {{classname}}ResponseProcessor {
} }
{{/responses}} {{/responses}}
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
{{#returnType}} {{#returnType}}
const jsonBody = JSON.parse(response.body); {{#isBinary}}
const body: {{{returnType}}} = ObjectSerializer.deserialize(jsonBody, "{{{returnType}}}", "{{returnFormat}}") as {{{returnType}}}; const body: {{{returnType}}} = await response.getBodyAsFile() as any as {{{returnType}}};
{{/isBinary}}
{{^isBinary}}
const body: {{{returnType}}} = ObjectSerializer.deserialize(
ObjectSerializer.parse(await response.body.text(), contentType),
"{{{returnType}}}", "{{returnFormat}}"
) as {{{returnType}}};
{{/isBinary}}
return body; return body;
{{/returnType}} {{/returnType}}
{{^returnType}} {{^returnType}}
return; return;
{{/returnType}} {{/returnType}}
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }

View File

@ -43,9 +43,9 @@ export type HttpFile = {
name: string name: string
}; };
{{/node}} {{/node}}
{{^node}} {{#browser}}
export type HttpFile = {{{fileContentDataType}}} & { readonly name: string }; export type HttpFile = {{{fileContentDataType}}} & { readonly name: string };
{{/node}} {{/browser}}
{{/platforms}} {{/platforms}}
@ -141,12 +141,104 @@ export class RequestContext {
} }
} }
export class ResponseContext { export interface ResponseBody {
text(): Promise<string>;
public constructor(public httpStatusCode: number, binary(): Promise<{{{fileContentDataType}}}>;
public headers: { [key: string]: string }, public body: string) {
} }
/**
* Helper class to generate a `ResponseBody` from binary data
*/
export class SelfDecodingBody implements ResponseBody {
constructor(private dataSource: Promise<{{{fileContentDataType}}}>) {}
binary(): Promise<{{{fileContentDataType}}}> {
return this.dataSource;
}
async text(): Promise<string> {
const data: {{{fileContentDataType}}} = await this.dataSource;
{{#platforms}}
{{#node}}
return data.toString();
{{/node}}
{{#browser}}
// @ts-ignore
if (data.text) {
// @ts-ignore
return data.text();
}
return new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener("load", () => resolve(reader.result));
reader.addEventListener("error", () => reject(reader.error));
reader.readAsText(data);
});
{{/browser}}
{{/platforms}}
}
}
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public body: ResponseBody
) {}
/**
* Parse header value in the form `value; param1="value1"`
*
* E.g. for Content-Type or Content-Disposition
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
if (!this.headers[headerName]) {
return result;
}
const parameters = this.headers[headerName].split(";");
for (const parameter of parameters) {
let [key, value] = parameter.split("=", 2);
key = key.toLowerCase().trim();
if (value === undefined) {
result[""] = key;
} else {
value = value.trim();
if (value.startsWith('"') && value.endsWith('"')) {
value = value.substring(1, value.length - 1);
}
result[key] = value;
}
}
return result;
}
public async getBodyAsFile(): Promise<HttpFile> {
const data = await this.body.binary();
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
{{#platforms}}
{{#node}}
return { data, name: fileName };
{{/node}}
{{#browser}}
const contentType = this.headers["content-type"] || "";
try {
return new File([data], fileName, { type: contentType });
} catch (error) {
/** Fallback for when the File constructor is not available */
return Object.assign(data, {
name: fileName,
type: contentType
});
}
{{/browser}}
{{/platforms}}
}
} }
export interface HttpLibrary { export interface HttpLibrary {

View File

@ -1,9 +1,13 @@
declare var fetch: any;
import {HttpLibrary, RequestContext, ResponseContext} from './http'; import {HttpLibrary, RequestContext, ResponseContext} from './http';
import 'es6-promise/auto';
import { from, Observable } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub'{{/useRxJS}}; import { from, Observable } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub'{{/useRxJS}};
import 'isomorphic-fetch'; {{#platforms}}
{{#node}}
import fetch from "node-fetch";
{{/node}}
{{#browser}}
import "whatwg-fetch";
{{/browser}}
{{/platforms}}
export class IsomorphicFetchHttpLibrary implements HttpLibrary { export class IsomorphicFetchHttpLibrary implements HttpLibrary {
@ -15,17 +19,32 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
method: method, method: method,
body: body as any, body: body as any,
headers: request.getHeaders(), headers: request.getHeaders(),
{{#platforms}}
{{#browser}}
credentials: "same-origin" credentials: "same-origin"
{{/browser}}
{{/platforms}}
}).then((resp: any) => { }).then((resp: any) => {
// hack const headers: { [name: string]: string } = {};
let headers = (resp.headers as any)._headers; resp.headers.forEach((value: string, name: string) => {
for (let key in headers) { headers[name] = value;
headers[key] = (headers[key] as Array<string>).join("; ");
}
return resp.text().then((body: string) => {
return new ResponseContext(resp.status, headers, body)
}); });
{{#platforms}}
{{#node}}
const body = {
text: () => resp.text(),
binary: () => resp.buffer()
};
{{/node}}
{{^node}}
const body = {
text: () => resp.text(),
binary: () => resp.blob()
};
{{/node}}
{{/platforms}}
return new ResponseContext(resp.status, headers, body);
}); });
return from<Promise<ResponseContext>>(resultPromise); return from<Promise<ResponseContext>>(resultPromise);

View File

@ -1,13 +1,9 @@
import {HttpLibrary, RequestContext, ResponseContext, HttpException} from './http'; import { HttpLibrary, RequestContext, ResponseContext, HttpException, SelfDecodingBody } from './http';
import * as e6p from 'es6-promise' import * as e6p from 'es6-promise'
import { from, Observable } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub'{{/useRxJS}}; import { from, Observable } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub'{{/useRxJS}};
e6p.polyfill(); e6p.polyfill();
import * as $ from 'jquery'; import * as $ from 'jquery';
{{#platforms}}
{{#node}}
import * as FormData from "form-data";
{{/node}}
{{/platforms}}
export class JQueryHttpLibrary implements HttpLibrary { export class JQueryHttpLibrary implements HttpLibrary {
@ -25,6 +21,16 @@ export class JQueryHttpLibrary implements HttpLibrary {
data: body data: body
}; };
/**
* Allow receiving binary data with jquery ajax
*
* Source: https://keyangxiang.com/2017/09/01/HTML5-XHR-download-binary-content-as-Blob/
*/
requestOptions.beforeSend = (jqXHR: any, settings: any) => {
settings.xhr().responseType = "blob";
};
if (request.getHeaders()['Content-Type']) { if (request.getHeaders()['Content-Type']) {
requestOptions.contentType = headerParams['Content-Type']; requestOptions.contentType = headerParams['Content-Type'];
} }
@ -48,9 +54,12 @@ export class JQueryHttpLibrary implements HttpLibrary {
const sentRequest = $.ajax(requestOptions); const sentRequest = $.ajax(requestOptions);
const resultPromise = new Promise<ResponseContext>((resolve, reject) => { const resultPromise = new Promise<ResponseContext>((resolve, reject) => {
sentRequest.done((resp, _, jqXHR) => { sentRequest.done((data, _, jqXHR) => {
const headers = this.getResponseHeaders(jqXHR) const result = new ResponseContext(
const result = new ResponseContext(jqXHR.status, headers, JSON.stringify(resp)); jqXHR.status,
this.getResponseHeaders(jqXHR),
new SelfDecodingBody(Promise.resolve(data))
);
resolve(result); resolve(result);
}) })
sentRequest.fail((jqXHR: any) => { sentRequest.fail((jqXHR: any) => {

View File

@ -1,3 +1,5 @@
import 'es6-promise/auto';
export * from './http/http'; export * from './http/http';
export * from './auth/auth'; export * from './auth/auth';
export * from './models/all'; export * from './models/all';

View File

@ -22,6 +22,12 @@ let primitives = [
"any" "any"
]; ];
const supportedMediaTypes: { [mediaType: string]: number } = {
"application/json": Infinity,
"application/octet-stream": 0
}
let enumsMap: Set<string> = new Set<string>([ let enumsMap: Set<string> = new Set<string>([
{{#models}} {{#models}}
{{#model}} {{#model}}
@ -162,4 +168,73 @@ export class ObjectSerializer {
return instance; return instance;
} }
} }
/**
* Normalize media type
*
* We currently do not handle any media types attributes, i.e. anything
* after a semicolon. All content is assumed to be UTF-8 compatible.
*/
public static normalizeMediaType(mediaType: string | undefined): string | undefined {
if (mediaType === undefined) {
return undefined;
}
return mediaType.split(";")[0].trim().toLowerCase();
}
/**
* From a list of possible media types, choose the one we can handle best.
*
* The order of the given media types does not have any impact on the choice
* made.
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
return "application/json";
}
const normalMediaTypes = mediaTypes.map(this.normalizeMediaType);
let selectedMediaType: string | undefined = undefined;
let selectedRank: number = -Infinity;
for (const mediaType of normalMediaTypes) {
if (supportedMediaTypes[mediaType!] > selectedRank) {
selectedMediaType = mediaType;
selectedRank = supportedMediaTypes[mediaType!];
}
}
if (selectedMediaType === undefined) {
throw new Error("None of the given media types are supported: " + mediaTypes.join(", "));
}
return selectedMediaType!;
}
/**
* Convert data to a string according the given media type
*/
public static stringify(data: any, mediaType: string): string {
if (mediaType === "application/json") {
return JSON.stringify(data);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify.");
}
/**
* Parse data from a string according to the given media type
*/
public static parse(rawData: string, mediaType: string | undefined) {
if (mediaType === undefined) {
throw new Error("Cannot parse content. No Content-Type defined.");
}
if (mediaType === "application/json") {
return JSON.parse(rawData);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse.");
}
} }

View File

@ -19,8 +19,15 @@
"dependencies": { "dependencies": {
{{#frameworks}} {{#frameworks}}
{{#fetch-api}} {{#fetch-api}}
"isomorphic-fetch": "^2.2.1", {{#platforms}}
"@types/isomorphic-fetch": "0.0.34", {{#node}}
"node-fetch": "^2.6.0",
"@types/node-fetch": "^2.5.7",
{{/node}}
{{#browser}}
"whatwg-fetch": "^3.0.0",
{{/browser}}
{{/platforms}}
{{/fetch-api}} {{/fetch-api}}
{{#jquery}} {{#jquery}}
"@types/jquery": "^3.3.29", "@types/jquery": "^3.3.29",

View File

@ -16,7 +16,14 @@
"sourceMap": true, "sourceMap": true,
"outDir": "./dist", "outDir": "./dist",
"noLib": false, "noLib": false,
{{#platforms}}
{{#node}}
"lib": [ "es6" ]
{{/node}}
{{#browser}}
"lib": [ "es6", "dom" ] "lib": [ "es6", "dom" ]
{{/browser}}
{{/platforms}}
}, },
"exclude": [ "exclude": [
"dist", "dist",

View File

@ -33,7 +33,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -43,10 +43,16 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent "application/json",
const needsSerialization = (<any>"Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary "application/xml"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(body, "Pet", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
let authMethod = null; let authMethod = null;
@ -80,7 +86,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -121,7 +127,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
if (status !== undefined) { if (status !== undefined) {
@ -164,7 +170,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
if (tags !== undefined) { if (tags !== undefined) {
@ -208,7 +214,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -247,7 +253,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -257,10 +263,16 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent "application/json",
const needsSerialization = (<any>"Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary "application/xml"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(body, "Pet", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
let authMethod = null; let authMethod = null;
@ -296,7 +308,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -350,7 +362,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -394,15 +406,17 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to addPet * @params response Response returned by the server for a request to addPet
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public addPet(response: ResponseContext): void { public async addPet(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid input");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -414,15 +428,17 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to deletePet * @params response Response returned by the server for a request to deletePet
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public deletePet(response: ResponseContext): void { public async deletePet(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid pet value");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -434,22 +450,28 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to findPetsByStatus * @params response Response returned by the server for a request to findPetsByStatus
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public findPetsByStatus(response: ResponseContext): Array<Pet> { public async findPetsByStatus(response: ResponseContext): Promise<Array<Pet> > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Array<Pet> = ObjectSerializer.deserialize(
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>; ObjectSerializer.parse(await response.body.text(), contentType),
"Array<Pet>", ""
) as Array<Pet>;
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<string>(response.httpStatusCode, "Invalid status value");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Array<Pet> = ObjectSerializer.deserialize(
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>; ObjectSerializer.parse(await response.body.text(), contentType),
"Array<Pet>", ""
) as Array<Pet>;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -461,22 +483,28 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to findPetsByTags * @params response Response returned by the server for a request to findPetsByTags
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public findPetsByTags(response: ResponseContext): Array<Pet> { public async findPetsByTags(response: ResponseContext): Promise<Array<Pet> > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Array<Pet> = ObjectSerializer.deserialize(
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>; ObjectSerializer.parse(await response.body.text(), contentType),
"Array<Pet>", ""
) as Array<Pet>;
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<string>(response.httpStatusCode, "Invalid tag value");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Array<Pet> = ObjectSerializer.deserialize(
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>; ObjectSerializer.parse(await response.body.text(), contentType),
"Array<Pet>", ""
) as Array<Pet>;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -488,10 +516,13 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to getPetById * @params response Response returned by the server for a request to getPetById
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public getPetById(response: ResponseContext): Pet { public async getPetById(response: ResponseContext): Promise<Pet > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Pet = ObjectSerializer.deserialize(
const body: Pet = ObjectSerializer.deserialize(jsonBody, "Pet", "") as Pet; ObjectSerializer.parse(await response.body.text(), contentType),
"Pet", ""
) as Pet;
return body; return body;
} }
if (isCodeInRange("400", response.httpStatusCode)) { if (isCodeInRange("400", response.httpStatusCode)) {
@ -501,12 +532,15 @@ export class PetApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "Pet not found"); throw new ApiException<string>(response.httpStatusCode, "Pet not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Pet = ObjectSerializer.deserialize(
const body: Pet = ObjectSerializer.deserialize(jsonBody, "Pet", "") as Pet; ObjectSerializer.parse(await response.body.text(), contentType),
"Pet", ""
) as Pet;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -518,7 +552,8 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to updatePet * @params response Response returned by the server for a request to updatePet
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public updatePet(response: ResponseContext): void { public async updatePet(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid ID supplied");
} }
@ -529,10 +564,11 @@ export class PetApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "Validation exception"); throw new ApiException<string>(response.httpStatusCode, "Validation exception");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -544,15 +580,17 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to updatePetWithForm * @params response Response returned by the server for a request to updatePetWithForm
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public updatePetWithForm(response: ResponseContext): void { public async updatePetWithForm(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid input");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -564,19 +602,25 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to uploadFile * @params response Response returned by the server for a request to uploadFile
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public uploadFile(response: ResponseContext): ApiResponse { public async uploadFile(response: ResponseContext): Promise<ApiResponse > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: ApiResponse = ObjectSerializer.deserialize(
const body: ApiResponse = ObjectSerializer.deserialize(jsonBody, "ApiResponse", "") as ApiResponse; ObjectSerializer.parse(await response.body.text(), contentType),
"ApiResponse", ""
) as ApiResponse;
return body; return body;
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: ApiResponse = ObjectSerializer.deserialize(
const body: ApiResponse = ObjectSerializer.deserialize(jsonBody, "ApiResponse", "") as ApiResponse; ObjectSerializer.parse(await response.body.text(), contentType),
"ApiResponse", ""
) as ApiResponse;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }

View File

@ -34,7 +34,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -62,7 +62,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -103,7 +103,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -137,7 +137,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -147,10 +147,12 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"Order" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "Order", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -171,7 +173,8 @@ export class StoreApiResponseProcessor {
* @params response Response returned by the server for a request to deleteOrder * @params response Response returned by the server for a request to deleteOrder
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public deleteOrder(response: ResponseContext): void { public async deleteOrder(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid ID supplied");
} }
@ -179,10 +182,11 @@ export class StoreApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "Order not found"); throw new ApiException<string>(response.httpStatusCode, "Order not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -194,19 +198,25 @@ export class StoreApiResponseProcessor {
* @params response Response returned by the server for a request to getInventory * @params response Response returned by the server for a request to getInventory
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public getInventory(response: ResponseContext): { [key: string]: number; } { public async getInventory(response: ResponseContext): Promise<{ [key: string]: number; } > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: { [key: string]: number; } = ObjectSerializer.deserialize(
const body: { [key: string]: number; } = ObjectSerializer.deserialize(jsonBody, "{ [key: string]: number; }", "int32") as { [key: string]: number; }; ObjectSerializer.parse(await response.body.text(), contentType),
"{ [key: string]: number; }", "int32"
) as { [key: string]: number; };
return body; return body;
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: { [key: string]: number; } = ObjectSerializer.deserialize(
const body: { [key: string]: number; } = ObjectSerializer.deserialize(jsonBody, "{ [key: string]: number; }", "int32") as { [key: string]: number; }; ObjectSerializer.parse(await response.body.text(), contentType),
"{ [key: string]: number; }", "int32"
) as { [key: string]: number; };
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -218,10 +228,13 @@ export class StoreApiResponseProcessor {
* @params response Response returned by the server for a request to getOrderById * @params response Response returned by the server for a request to getOrderById
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public getOrderById(response: ResponseContext): Order { public async getOrderById(response: ResponseContext): Promise<Order > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Order = ObjectSerializer.deserialize(
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order; ObjectSerializer.parse(await response.body.text(), contentType),
"Order", ""
) as Order;
return body; return body;
} }
if (isCodeInRange("400", response.httpStatusCode)) { if (isCodeInRange("400", response.httpStatusCode)) {
@ -231,12 +244,15 @@ export class StoreApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "Order not found"); throw new ApiException<string>(response.httpStatusCode, "Order not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Order = ObjectSerializer.deserialize(
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order; ObjectSerializer.parse(await response.body.text(), contentType),
"Order", ""
) as Order;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -248,22 +264,28 @@ export class StoreApiResponseProcessor {
* @params response Response returned by the server for a request to placeOrder * @params response Response returned by the server for a request to placeOrder
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public placeOrder(response: ResponseContext): Order { public async placeOrder(response: ResponseContext): Promise<Order > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Order = ObjectSerializer.deserialize(
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order; ObjectSerializer.parse(await response.body.text(), contentType),
"Order", ""
) as Order;
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<string>(response.httpStatusCode, "Invalid Order");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Order = ObjectSerializer.deserialize(
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order; ObjectSerializer.parse(await response.body.text(), contentType),
"Order", ""
) as Order;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }

View File

@ -33,7 +33,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -43,10 +43,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "User", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -72,7 +74,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -82,10 +84,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"Array&lt;User&gt;" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "Array<User>", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -111,7 +115,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -121,10 +125,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"Array&lt;User&gt;" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "Array<User>", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -152,7 +158,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -187,7 +193,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -228,7 +234,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
if (username !== undefined) { if (username !== undefined) {
@ -261,7 +267,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -304,7 +310,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -314,10 +320,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "User", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -338,15 +346,17 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to createUser * @params response Response returned by the server for a request to createUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public createUser(response: ResponseContext): void { public async createUser(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "successful operation");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -358,15 +368,17 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to createUsersWithArrayInput * @params response Response returned by the server for a request to createUsersWithArrayInput
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public createUsersWithArrayInput(response: ResponseContext): void { public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "successful operation");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -378,15 +390,17 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to createUsersWithListInput * @params response Response returned by the server for a request to createUsersWithListInput
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public createUsersWithListInput(response: ResponseContext): void { public async createUsersWithListInput(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "successful operation");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -398,7 +412,8 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to deleteUser * @params response Response returned by the server for a request to deleteUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public deleteUser(response: ResponseContext): void { public async deleteUser(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid username supplied");
} }
@ -406,10 +421,11 @@ export class UserApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "User not found"); throw new ApiException<string>(response.httpStatusCode, "User not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -421,10 +437,13 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to getUserByName * @params response Response returned by the server for a request to getUserByName
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public getUserByName(response: ResponseContext): User { public async getUserByName(response: ResponseContext): Promise<User > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: User = ObjectSerializer.deserialize(
const body: User = ObjectSerializer.deserialize(jsonBody, "User", "") as User; ObjectSerializer.parse(await response.body.text(), contentType),
"User", ""
) as User;
return body; return body;
} }
if (isCodeInRange("400", response.httpStatusCode)) { if (isCodeInRange("400", response.httpStatusCode)) {
@ -434,12 +453,15 @@ export class UserApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "User not found"); throw new ApiException<string>(response.httpStatusCode, "User not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: User = ObjectSerializer.deserialize(
const body: User = ObjectSerializer.deserialize(jsonBody, "User", "") as User; ObjectSerializer.parse(await response.body.text(), contentType),
"User", ""
) as User;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -451,22 +473,28 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to loginUser * @params response Response returned by the server for a request to loginUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public loginUser(response: ResponseContext): string { public async loginUser(response: ResponseContext): Promise<string > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: string = ObjectSerializer.deserialize(
const body: string = ObjectSerializer.deserialize(jsonBody, "string", "") as string; ObjectSerializer.parse(await response.body.text(), contentType),
"string", ""
) as string;
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<string>(response.httpStatusCode, "Invalid username/password supplied");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: string = ObjectSerializer.deserialize(
const body: string = ObjectSerializer.deserialize(jsonBody, "string", "") as string; ObjectSerializer.parse(await response.body.text(), contentType),
"string", ""
) as string;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -478,15 +506,17 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to logoutUser * @params response Response returned by the server for a request to logoutUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public logoutUser(response: ResponseContext): void { public async logoutUser(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "successful operation");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -498,7 +528,8 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to updateUser * @params response Response returned by the server for a request to updateUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public updateUser(response: ResponseContext): void { public async updateUser(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid user supplied");
} }
@ -506,10 +537,11 @@ export class UserApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "User not found"); throw new ApiException<string>(response.httpStatusCode, "User not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }

View File

@ -123,12 +123,70 @@ export class RequestContext {
} }
} }
export class ResponseContext { export interface ResponseBody {
text(): Promise<string>;
public constructor(public httpStatusCode: number, binary(): Promise<Buffer>;
public headers: { [key: string]: string }, public body: string) {
} }
/**
* Helper class to generate a `ResponseBody` from binary data
*/
export class SelfDecodingBody implements ResponseBody {
constructor(private dataSource: Promise<Buffer>) {}
binary(): Promise<Buffer> {
return this.dataSource;
}
async text(): Promise<string> {
const data: Buffer = await this.dataSource;
return data.toString();
}
}
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public body: ResponseBody
) {}
/**
* Parse header value in the form `value; param1="value1"`
*
* E.g. for Content-Type or Content-Disposition
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
if (!this.headers[headerName]) {
return result;
}
const parameters = this.headers[headerName].split(";");
for (const parameter of parameters) {
let [key, value] = parameter.split("=", 2);
key = key.toLowerCase().trim();
if (value === undefined) {
result[""] = key;
} else {
value = value.trim();
if (value.startsWith('"') && value.endsWith('"')) {
value = value.substring(1, value.length - 1);
}
result[key] = value;
}
}
return result;
}
public async getBodyAsFile(): Promise<HttpFile> {
const data = await this.body.binary();
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
return { data, name: fileName };
}
} }
export interface HttpLibrary { export interface HttpLibrary {

View File

@ -1,9 +1,6 @@
declare var fetch: any;
import {HttpLibrary, RequestContext, ResponseContext} from './http'; import {HttpLibrary, RequestContext, ResponseContext} from './http';
import 'es6-promise/auto';
import { from, Observable } from '../rxjsStub'; import { from, Observable } from '../rxjsStub';
import 'isomorphic-fetch'; import fetch from "node-fetch";
export class IsomorphicFetchHttpLibrary implements HttpLibrary { export class IsomorphicFetchHttpLibrary implements HttpLibrary {
@ -15,17 +12,17 @@ export class IsomorphicFetchHttpLibrary implements HttpLibrary {
method: method, method: method,
body: body as any, body: body as any,
headers: request.getHeaders(), headers: request.getHeaders(),
credentials: "same-origin"
}).then((resp: any) => { }).then((resp: any) => {
// hack const headers: { [name: string]: string } = {};
let headers = (resp.headers as any)._headers; resp.headers.forEach((value: string, name: string) => {
for (let key in headers) { headers[name] = value;
headers[key] = (headers[key] as Array<string>).join("; ");
}
return resp.text().then((body: string) => {
return new ResponseContext(resp.status, headers, body)
}); });
const body = {
text: () => resp.text(),
binary: () => resp.buffer()
};
return new ResponseContext(resp.status, headers, body);
}); });
return from<Promise<ResponseContext>>(resultPromise); return from<Promise<ResponseContext>>(resultPromise);

View File

@ -1,3 +1,5 @@
import 'es6-promise/auto';
export * from './http/http'; export * from './http/http';
export * from './auth/auth'; export * from './auth/auth';
export * from './models/all'; export * from './models/all';

View File

@ -24,6 +24,12 @@ let primitives = [
"any" "any"
]; ];
const supportedMediaTypes: { [mediaType: string]: number } = {
"application/json": Infinity,
"application/octet-stream": 0
}
let enumsMap: Set<string> = new Set<string>([ let enumsMap: Set<string> = new Set<string>([
"OrderStatusEnum", "OrderStatusEnum",
"PetStatusEnum", "PetStatusEnum",
@ -156,4 +162,73 @@ export class ObjectSerializer {
return instance; return instance;
} }
} }
/**
* Normalize media type
*
* We currently do not handle any media types attributes, i.e. anything
* after a semicolon. All content is assumed to be UTF-8 compatible.
*/
public static normalizeMediaType(mediaType: string | undefined): string | undefined {
if (mediaType === undefined) {
return undefined;
}
return mediaType.split(";")[0].trim().toLowerCase();
}
/**
* From a list of possible media types, choose the one we can handle best.
*
* The order of the given media types does not have any impact on the choice
* made.
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
return "application/json";
}
const normalMediaTypes = mediaTypes.map(this.normalizeMediaType);
let selectedMediaType: string | undefined = undefined;
let selectedRank: number = -Infinity;
for (const mediaType of normalMediaTypes) {
if (supportedMediaTypes[mediaType!] > selectedRank) {
selectedMediaType = mediaType;
selectedRank = supportedMediaTypes[mediaType!];
}
}
if (selectedMediaType === undefined) {
throw new Error("None of the given media types are supported: " + mediaTypes.join(", "));
}
return selectedMediaType!;
}
/**
* Convert data to a string according the given media type
*/
public static stringify(data: any, mediaType: string): string {
if (mediaType === "application/json") {
return JSON.stringify(data);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify.");
}
/**
* Parse data from a string according to the given media type
*/
public static parse(rawData: string, mediaType: string | undefined) {
if (mediaType === undefined) {
throw new Error("Cannot parse content. No Content-Type defined.");
}
if (mediaType === "application/json") {
return JSON.parse(rawData);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse.");
}
} }

View File

@ -4,16 +4,32 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@types/isomorphic-fetch": {
"version": "0.0.34",
"resolved": "https://registry.npmjs.org/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.34.tgz",
"integrity": "sha1-PDSD5gbAQTeEOOlRRk8A5OYHBtY="
},
"@types/node": { "@types/node": {
"version": "12.12.7", "version": "12.12.7",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.7.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.7.tgz",
"integrity": "sha512-E6Zn0rffhgd130zbCbAr/JdXfXkoOUFAKNs/rF8qnafSJ8KYaA/j3oz7dcwal+lYjLA7xvdd5J4wdYpCTlP8+w==" "integrity": "sha512-E6Zn0rffhgd130zbCbAr/JdXfXkoOUFAKNs/rF8qnafSJ8KYaA/j3oz7dcwal+lYjLA7xvdd5J4wdYpCTlP8+w=="
}, },
"@types/node-fetch": {
"version": "2.5.7",
"resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.7.tgz",
"integrity": "sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==",
"requires": {
"@types/node": "*",
"form-data": "^3.0.0"
},
"dependencies": {
"form-data": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
}
}
},
"asynckit": { "asynckit": {
"version": "0.4.0", "version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
@ -37,14 +53,6 @@
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
}, },
"encoding": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
"requires": {
"iconv-lite": "~0.4.13"
}
},
"es6-promise": { "es6-promise": {
"version": "4.2.5", "version": "4.2.5",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz",
@ -60,28 +68,6 @@
"mime-types": "^2.1.12" "mime-types": "^2.1.12"
} }
}, },
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
},
"isomorphic-fetch": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz",
"integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=",
"requires": {
"node-fetch": "^1.0.1",
"whatwg-fetch": ">=0.10.0"
}
},
"mime-db": { "mime-db": {
"version": "1.40.0", "version": "1.40.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz",
@ -96,13 +82,9 @@
} }
}, },
"node-fetch": { "node-fetch": {
"version": "1.7.3", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
"requires": {
"encoding": "^0.1.11",
"is-stream": "^1.0.1"
}
}, },
"querystringify": { "querystringify": {
"version": "2.1.0", "version": "2.1.0",
@ -114,14 +96,9 @@
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=" "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
}, },
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"typescript": { "typescript": {
"version": "2.9.2", "version": "2.9.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz", "resolved": false,
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==", "integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
"dev": true "dev": true
}, },
@ -133,11 +110,6 @@
"querystringify": "^2.0.0", "querystringify": "^2.0.0",
"requires-port": "^1.0.0" "requires-port": "^1.0.0"
} }
},
"whatwg-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz",
"integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q=="
} }
} }
} }

View File

@ -17,8 +17,8 @@
"prepublishOnly": "npm run build" "prepublishOnly": "npm run build"
}, },
"dependencies": { "dependencies": {
"isomorphic-fetch": "^2.2.1", "node-fetch": "^2.6.0",
"@types/isomorphic-fetch": "0.0.34", "@types/node-fetch": "^2.5.7",
"@types/node": "*", "@types/node": "*",
"form-data": "^2.5.0", "form-data": "^2.5.0",
"btoa": "^1.2.1", "btoa": "^1.2.1",

View File

@ -16,7 +16,7 @@
"sourceMap": true, "sourceMap": true,
"outDir": "./dist", "outDir": "./dist",
"noLib": false, "noLib": false,
"lib": [ "es6", "dom" ] "lib": [ "es6" ]
}, },
"exclude": [ "exclude": [
"dist", "dist",

View File

@ -32,7 +32,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -42,10 +42,16 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent "application/json",
const needsSerialization = (<any>"Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary "application/xml"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(body, "Pet", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
let authMethod = null; let authMethod = null;
@ -79,7 +85,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -120,7 +126,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
if (status !== undefined) { if (status !== undefined) {
@ -163,7 +169,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
if (tags !== undefined) { if (tags !== undefined) {
@ -207,7 +213,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -246,7 +252,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -256,10 +262,16 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent "application/json",
const needsSerialization = (<any>"Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary "application/xml"
]);
requestContext.setHeaderParam("Content-Type", contentType);
const serializedBody = ObjectSerializer.stringify(
ObjectSerializer.serialize(body, "Pet", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
let authMethod = null; let authMethod = null;
@ -295,7 +307,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -349,7 +361,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -393,15 +405,17 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to addPet * @params response Response returned by the server for a request to addPet
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public addPet(response: ResponseContext): void { public async addPet(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid input");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -413,15 +427,17 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to deletePet * @params response Response returned by the server for a request to deletePet
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public deletePet(response: ResponseContext): void { public async deletePet(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid pet value");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -433,22 +449,28 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to findPetsByStatus * @params response Response returned by the server for a request to findPetsByStatus
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public findPetsByStatus(response: ResponseContext): Array<Pet> { public async findPetsByStatus(response: ResponseContext): Promise<Array<Pet> > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Array<Pet> = ObjectSerializer.deserialize(
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>; ObjectSerializer.parse(await response.body.text(), contentType),
"Array<Pet>", ""
) as Array<Pet>;
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<string>(response.httpStatusCode, "Invalid status value");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Array<Pet> = ObjectSerializer.deserialize(
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>; ObjectSerializer.parse(await response.body.text(), contentType),
"Array<Pet>", ""
) as Array<Pet>;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -460,22 +482,28 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to findPetsByTags * @params response Response returned by the server for a request to findPetsByTags
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public findPetsByTags(response: ResponseContext): Array<Pet> { public async findPetsByTags(response: ResponseContext): Promise<Array<Pet> > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Array<Pet> = ObjectSerializer.deserialize(
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>; ObjectSerializer.parse(await response.body.text(), contentType),
"Array<Pet>", ""
) as Array<Pet>;
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<string>(response.httpStatusCode, "Invalid tag value");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Array<Pet> = ObjectSerializer.deserialize(
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>; ObjectSerializer.parse(await response.body.text(), contentType),
"Array<Pet>", ""
) as Array<Pet>;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -487,10 +515,13 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to getPetById * @params response Response returned by the server for a request to getPetById
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public getPetById(response: ResponseContext): Pet { public async getPetById(response: ResponseContext): Promise<Pet > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Pet = ObjectSerializer.deserialize(
const body: Pet = ObjectSerializer.deserialize(jsonBody, "Pet", "") as Pet; ObjectSerializer.parse(await response.body.text(), contentType),
"Pet", ""
) as Pet;
return body; return body;
} }
if (isCodeInRange("400", response.httpStatusCode)) { if (isCodeInRange("400", response.httpStatusCode)) {
@ -500,12 +531,15 @@ export class PetApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "Pet not found"); throw new ApiException<string>(response.httpStatusCode, "Pet not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Pet = ObjectSerializer.deserialize(
const body: Pet = ObjectSerializer.deserialize(jsonBody, "Pet", "") as Pet; ObjectSerializer.parse(await response.body.text(), contentType),
"Pet", ""
) as Pet;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -517,7 +551,8 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to updatePet * @params response Response returned by the server for a request to updatePet
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public updatePet(response: ResponseContext): void { public async updatePet(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid ID supplied");
} }
@ -528,10 +563,11 @@ export class PetApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "Validation exception"); throw new ApiException<string>(response.httpStatusCode, "Validation exception");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -543,15 +579,17 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to updatePetWithForm * @params response Response returned by the server for a request to updatePetWithForm
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public updatePetWithForm(response: ResponseContext): void { public async updatePetWithForm(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid input");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -563,19 +601,25 @@ export class PetApiResponseProcessor {
* @params response Response returned by the server for a request to uploadFile * @params response Response returned by the server for a request to uploadFile
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public uploadFile(response: ResponseContext): ApiResponse { public async uploadFile(response: ResponseContext): Promise<ApiResponse > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: ApiResponse = ObjectSerializer.deserialize(
const body: ApiResponse = ObjectSerializer.deserialize(jsonBody, "ApiResponse", "") as ApiResponse; ObjectSerializer.parse(await response.body.text(), contentType),
"ApiResponse", ""
) as ApiResponse;
return body; return body;
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: ApiResponse = ObjectSerializer.deserialize(
const body: ApiResponse = ObjectSerializer.deserialize(jsonBody, "ApiResponse", "") as ApiResponse; ObjectSerializer.parse(await response.body.text(), contentType),
"ApiResponse", ""
) as ApiResponse;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }

View File

@ -33,7 +33,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -61,7 +61,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -102,7 +102,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -136,7 +136,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -146,10 +146,12 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"Order" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "Order", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -170,7 +172,8 @@ export class StoreApiResponseProcessor {
* @params response Response returned by the server for a request to deleteOrder * @params response Response returned by the server for a request to deleteOrder
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public deleteOrder(response: ResponseContext): void { public async deleteOrder(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid ID supplied");
} }
@ -178,10 +181,11 @@ export class StoreApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "Order not found"); throw new ApiException<string>(response.httpStatusCode, "Order not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -193,19 +197,25 @@ export class StoreApiResponseProcessor {
* @params response Response returned by the server for a request to getInventory * @params response Response returned by the server for a request to getInventory
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public getInventory(response: ResponseContext): { [key: string]: number; } { public async getInventory(response: ResponseContext): Promise<{ [key: string]: number; } > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: { [key: string]: number; } = ObjectSerializer.deserialize(
const body: { [key: string]: number; } = ObjectSerializer.deserialize(jsonBody, "{ [key: string]: number; }", "int32") as { [key: string]: number; }; ObjectSerializer.parse(await response.body.text(), contentType),
"{ [key: string]: number; }", "int32"
) as { [key: string]: number; };
return body; return body;
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: { [key: string]: number; } = ObjectSerializer.deserialize(
const body: { [key: string]: number; } = ObjectSerializer.deserialize(jsonBody, "{ [key: string]: number; }", "int32") as { [key: string]: number; }; ObjectSerializer.parse(await response.body.text(), contentType),
"{ [key: string]: number; }", "int32"
) as { [key: string]: number; };
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -217,10 +227,13 @@ export class StoreApiResponseProcessor {
* @params response Response returned by the server for a request to getOrderById * @params response Response returned by the server for a request to getOrderById
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public getOrderById(response: ResponseContext): Order { public async getOrderById(response: ResponseContext): Promise<Order > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Order = ObjectSerializer.deserialize(
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order; ObjectSerializer.parse(await response.body.text(), contentType),
"Order", ""
) as Order;
return body; return body;
} }
if (isCodeInRange("400", response.httpStatusCode)) { if (isCodeInRange("400", response.httpStatusCode)) {
@ -230,12 +243,15 @@ export class StoreApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "Order not found"); throw new ApiException<string>(response.httpStatusCode, "Order not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Order = ObjectSerializer.deserialize(
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order; ObjectSerializer.parse(await response.body.text(), contentType),
"Order", ""
) as Order;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -247,22 +263,28 @@ export class StoreApiResponseProcessor {
* @params response Response returned by the server for a request to placeOrder * @params response Response returned by the server for a request to placeOrder
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public placeOrder(response: ResponseContext): Order { public async placeOrder(response: ResponseContext): Promise<Order > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: Order = ObjectSerializer.deserialize(
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order; ObjectSerializer.parse(await response.body.text(), contentType),
"Order", ""
) as Order;
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<string>(response.httpStatusCode, "Invalid Order");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: Order = ObjectSerializer.deserialize(
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order; ObjectSerializer.parse(await response.body.text(), contentType),
"Order", ""
) as Order;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }

View File

@ -32,7 +32,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -42,10 +42,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "User", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -71,7 +73,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -81,10 +83,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"Array&lt;User&gt;" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "Array<User>", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -110,7 +114,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -120,10 +124,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"Array&lt;User&gt;" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "Array<User>", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -151,7 +157,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -186,7 +192,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -227,7 +233,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
if (username !== undefined) { if (username !== undefined) {
@ -260,7 +266,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -303,7 +309,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Make Request Context // Make Request Context
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT); const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
requestContext.setHeaderParam("Accept", "application/json") requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
// Query Params // Query Params
@ -313,10 +319,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
// Body Params // Body Params
requestContext.setHeaderParam("Content-Type", "application/json"); const contentType = ObjectSerializer.getPreferredMediaType([]);
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent requestContext.setHeaderParam("Content-Type", contentType);
const needsSerialization = (<any>"User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; const serializedBody = ObjectSerializer.stringify(
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary ObjectSerializer.serialize(body, "User", ""),
contentType
);
requestContext.setBody(serializedBody); requestContext.setBody(serializedBody);
// Apply auth methods // Apply auth methods
@ -337,15 +345,17 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to createUser * @params response Response returned by the server for a request to createUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public createUser(response: ResponseContext): void { public async createUser(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "successful operation");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -357,15 +367,17 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to createUsersWithArrayInput * @params response Response returned by the server for a request to createUsersWithArrayInput
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public createUsersWithArrayInput(response: ResponseContext): void { public async createUsersWithArrayInput(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "successful operation");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -377,15 +389,17 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to createUsersWithListInput * @params response Response returned by the server for a request to createUsersWithListInput
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public createUsersWithListInput(response: ResponseContext): void { public async createUsersWithListInput(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "successful operation");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -397,7 +411,8 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to deleteUser * @params response Response returned by the server for a request to deleteUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public deleteUser(response: ResponseContext): void { public async deleteUser(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid username supplied");
} }
@ -405,10 +420,11 @@ export class UserApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "User not found"); throw new ApiException<string>(response.httpStatusCode, "User not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -420,10 +436,13 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to getUserByName * @params response Response returned by the server for a request to getUserByName
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public getUserByName(response: ResponseContext): User { public async getUserByName(response: ResponseContext): Promise<User > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: User = ObjectSerializer.deserialize(
const body: User = ObjectSerializer.deserialize(jsonBody, "User", "") as User; ObjectSerializer.parse(await response.body.text(), contentType),
"User", ""
) as User;
return body; return body;
} }
if (isCodeInRange("400", response.httpStatusCode)) { if (isCodeInRange("400", response.httpStatusCode)) {
@ -433,12 +452,15 @@ export class UserApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "User not found"); throw new ApiException<string>(response.httpStatusCode, "User not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: User = ObjectSerializer.deserialize(
const body: User = ObjectSerializer.deserialize(jsonBody, "User", "") as User; ObjectSerializer.parse(await response.body.text(), contentType),
"User", ""
) as User;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -450,22 +472,28 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to loginUser * @params response Response returned by the server for a request to loginUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public loginUser(response: ResponseContext): string { public async loginUser(response: ResponseContext): Promise<string > {
const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
if (isCodeInRange("200", response.httpStatusCode)) { if (isCodeInRange("200", response.httpStatusCode)) {
const jsonBody = JSON.parse(response.body); const body: string = ObjectSerializer.deserialize(
const body: string = ObjectSerializer.deserialize(jsonBody, "string", "") as string; ObjectSerializer.parse(await response.body.text(), contentType),
"string", ""
) as string;
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<string>(response.httpStatusCode, "Invalid username/password supplied");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
const jsonBody = JSON.parse(response.body); const body: string = ObjectSerializer.deserialize(
const body: string = ObjectSerializer.deserialize(jsonBody, "string", "") as string; ObjectSerializer.parse(await response.body.text(), contentType),
"string", ""
) as string;
return body; return body;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -477,15 +505,17 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to logoutUser * @params response Response returned by the server for a request to logoutUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public logoutUser(response: ResponseContext): void { public async logoutUser(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "successful operation");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }
@ -497,7 +527,8 @@ export class UserApiResponseProcessor {
* @params response Response returned by the server for a request to updateUser * @params response Response returned by the server for a request to updateUser
* @throws ApiException if the response code was not in [200, 299] * @throws ApiException if the response code was not in [200, 299]
*/ */
public updateUser(response: ResponseContext): void { public async updateUser(response: ResponseContext): Promise< void> {
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<string>(response.httpStatusCode, "Invalid user supplied");
} }
@ -505,10 +536,11 @@ export class UserApiResponseProcessor {
throw new ApiException<string>(response.httpStatusCode, "User not found"); throw new ApiException<string>(response.httpStatusCode, "User not found");
} }
// Work around for incorrect api specification in petstore.yaml // Work around for missing responses in specification, e.g. for petstore.yaml
if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) { if (response.httpStatusCode >= 200 && response.httpStatusCode <= 299) {
return; return;
} }
let body = response.body || ""; let body = response.body || "";
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\""); throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
} }

View File

@ -118,12 +118,90 @@ export class RequestContext {
} }
} }
export class ResponseContext { export interface ResponseBody {
text(): Promise<string>;
public constructor(public httpStatusCode: number, binary(): Promise<Blob>;
public headers: { [key: string]: string }, public body: string) {
} }
/**
* Helper class to generate a `ResponseBody` from binary data
*/
export class SelfDecodingBody implements ResponseBody {
constructor(private dataSource: Promise<Blob>) {}
binary(): Promise<Blob> {
return this.dataSource;
}
async text(): Promise<string> {
const data: Blob = await this.dataSource;
// @ts-ignore
if (data.text) {
// @ts-ignore
return data.text();
}
return new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.addEventListener("load", () => resolve(reader.result));
reader.addEventListener("error", () => reject(reader.error));
reader.readAsText(data);
});
}
}
export class ResponseContext {
public constructor(
public httpStatusCode: number,
public headers: { [key: string]: string },
public body: ResponseBody
) {}
/**
* Parse header value in the form `value; param1="value1"`
*
* E.g. for Content-Type or Content-Disposition
* Parameter names are converted to lower case
* The first parameter is returned with the key `""`
*/
public getParsedHeader(headerName: string): { [parameter: string]: string } {
const result: { [parameter: string]: string } = {};
if (!this.headers[headerName]) {
return result;
}
const parameters = this.headers[headerName].split(";");
for (const parameter of parameters) {
let [key, value] = parameter.split("=", 2);
key = key.toLowerCase().trim();
if (value === undefined) {
result[""] = key;
} else {
value = value.trim();
if (value.startsWith('"') && value.endsWith('"')) {
value = value.substring(1, value.length - 1);
}
result[key] = value;
}
}
return result;
}
public async getBodyAsFile(): Promise<HttpFile> {
const data = await this.body.binary();
const fileName = this.getParsedHeader("content-disposition")["filename"] || "";
const contentType = this.headers["content-type"] || "";
try {
return new File([data], fileName, { type: contentType });
} catch (error) {
/** Fallback for when the File constructor is not available */
return Object.assign(data, {
name: fileName,
type: contentType
});
}
}
} }
export interface HttpLibrary { export interface HttpLibrary {

View File

@ -1,9 +1,10 @@
import {HttpLibrary, RequestContext, ResponseContext, HttpException} from './http'; import { HttpLibrary, RequestContext, ResponseContext, HttpException, SelfDecodingBody } from './http';
import * as e6p from 'es6-promise' import * as e6p from 'es6-promise'
import { from, Observable } from '../rxjsStub'; import { from, Observable } from '../rxjsStub';
e6p.polyfill(); e6p.polyfill();
import * as $ from 'jquery'; import * as $ from 'jquery';
export class JQueryHttpLibrary implements HttpLibrary { export class JQueryHttpLibrary implements HttpLibrary {
public send(request: RequestContext): Observable<ResponseContext> { public send(request: RequestContext): Observable<ResponseContext> {
@ -20,6 +21,16 @@ export class JQueryHttpLibrary implements HttpLibrary {
data: body data: body
}; };
/**
* Allow receiving binary data with jquery ajax
*
* Source: https://keyangxiang.com/2017/09/01/HTML5-XHR-download-binary-content-as-Blob/
*/
requestOptions.beforeSend = (jqXHR: any, settings: any) => {
settings.xhr().responseType = "blob";
};
if (request.getHeaders()['Content-Type']) { if (request.getHeaders()['Content-Type']) {
requestOptions.contentType = headerParams['Content-Type']; requestOptions.contentType = headerParams['Content-Type'];
} }
@ -43,9 +54,12 @@ export class JQueryHttpLibrary implements HttpLibrary {
const sentRequest = $.ajax(requestOptions); const sentRequest = $.ajax(requestOptions);
const resultPromise = new Promise<ResponseContext>((resolve, reject) => { const resultPromise = new Promise<ResponseContext>((resolve, reject) => {
sentRequest.done((resp, _, jqXHR) => { sentRequest.done((data, _, jqXHR) => {
const headers = this.getResponseHeaders(jqXHR) const result = new ResponseContext(
const result = new ResponseContext(jqXHR.status, headers, JSON.stringify(resp)); jqXHR.status,
this.getResponseHeaders(jqXHR),
new SelfDecodingBody(Promise.resolve(data))
);
resolve(result); resolve(result);
}) })
sentRequest.fail((jqXHR: any) => { sentRequest.fail((jqXHR: any) => {

View File

@ -1,3 +1,5 @@
import 'es6-promise/auto';
export * from './http/http'; export * from './http/http';
export * from './auth/auth'; export * from './auth/auth';
export * from './models/all'; export * from './models/all';

View File

@ -24,6 +24,12 @@ let primitives = [
"any" "any"
]; ];
const supportedMediaTypes: { [mediaType: string]: number } = {
"application/json": Infinity,
"application/octet-stream": 0
}
let enumsMap: Set<string> = new Set<string>([ let enumsMap: Set<string> = new Set<string>([
"OrderStatusEnum", "OrderStatusEnum",
"PetStatusEnum", "PetStatusEnum",
@ -156,4 +162,73 @@ export class ObjectSerializer {
return instance; return instance;
} }
} }
/**
* Normalize media type
*
* We currently do not handle any media types attributes, i.e. anything
* after a semicolon. All content is assumed to be UTF-8 compatible.
*/
public static normalizeMediaType(mediaType: string | undefined): string | undefined {
if (mediaType === undefined) {
return undefined;
}
return mediaType.split(";")[0].trim().toLowerCase();
}
/**
* From a list of possible media types, choose the one we can handle best.
*
* The order of the given media types does not have any impact on the choice
* made.
*/
public static getPreferredMediaType(mediaTypes: Array<string>): string {
/** According to OAS 3 we should default to json */
if (!mediaTypes) {
return "application/json";
}
const normalMediaTypes = mediaTypes.map(this.normalizeMediaType);
let selectedMediaType: string | undefined = undefined;
let selectedRank: number = -Infinity;
for (const mediaType of normalMediaTypes) {
if (supportedMediaTypes[mediaType!] > selectedRank) {
selectedMediaType = mediaType;
selectedRank = supportedMediaTypes[mediaType!];
}
}
if (selectedMediaType === undefined) {
throw new Error("None of the given media types are supported: " + mediaTypes.join(", "));
}
return selectedMediaType!;
}
/**
* Convert data to a string according the given media type
*/
public static stringify(data: any, mediaType: string): string {
if (mediaType === "application/json") {
return JSON.stringify(data);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.stringify.");
}
/**
* Parse data from a string according to the given media type
*/
public static parse(rawData: string, mediaType: string | undefined) {
if (mediaType === undefined) {
throw new Error("Cannot parse content. No Content-Type defined.");
}
if (mediaType === "application/json") {
return JSON.parse(rawData);
}
throw new Error("The mediaType " + mediaType + " is not supported by ObjectSerializer.parse.");
}
} }

View File

@ -28,9 +28,9 @@
"integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q==" "integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q=="
}, },
"jquery": { "jquery": {
"version": "3.4.1", "version": "3.5.1",
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz",
"integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==" "integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg=="
}, },
"querystringify": { "querystringify": {
"version": "2.1.1", "version": "2.1.1",

View File

@ -34,9 +34,9 @@
"integrity": "sha512-uD0j/AQOa5le7afuK+u+woi8jNKF1vf3DN0H7LCJhft/lNNibUr7VcAesdgtWfEKveZol3ZG1CJqwx2Bhrnl8w==" "integrity": "sha512-uD0j/AQOa5le7afuK+u+woi8jNKF1vf3DN0H7LCJhft/lNNibUr7VcAesdgtWfEKveZol3ZG1CJqwx2Bhrnl8w=="
}, },
"acorn": { "acorn": {
"version": "5.7.3", "version": "5.7.4",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz", "resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz",
"integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw==" "integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg=="
}, },
"acorn-jsx": { "acorn-jsx": {
"version": "3.0.1", "version": "3.0.1",
@ -748,9 +748,9 @@
} }
}, },
"lodash": { "lodash": {
"version": "4.17.11", "version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
}, },
"lru-cache": { "lru-cache": {
"version": "4.1.5", "version": "4.1.5",
@ -803,23 +803,16 @@
} }
}, },
"minimist": { "minimist": {
"version": "1.2.0", "version": "1.2.5",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
}, },
"mkdirp": { "mkdirp": {
"version": "0.5.1", "version": "0.5.5",
"resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "^1.2.5"
},
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
}
} }
}, },
"mocha": { "mocha": {
@ -841,6 +834,21 @@
"supports-color": "5.4.0" "supports-color": "5.4.0"
}, },
"dependencies": { "dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true,
"requires": {
"minimist": "0.0.8"
}
},
"supports-color": { "supports-color": {
"version": "5.4.0", "version": "5.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",
@ -1215,12 +1223,11 @@
"ts-petstore-client": { "ts-petstore-client": {
"version": "file:../../builds/default", "version": "file:../../builds/default",
"requires": { "requires": {
"@types/isomorphic-fetch": "0.0.34",
"@types/node": "*", "@types/node": "*",
"btoa": "^1.2.1", "btoa": "^1.2.1",
"es6-promise": "^4.2.4", "es6-promise": "^4.2.4",
"form-data": "^2.5.0", "form-data": "^2.5.0",
"isomorphic-fetch": "^2.2.1", "node-fetch": "^2.6.0",
"url-parse": "^1.4.3" "url-parse": "^1.4.3"
}, },
"dependencies": { "dependencies": {
@ -1257,14 +1264,6 @@
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
}, },
"encoding": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
"requires": {
"iconv-lite": "~0.4.13"
}
},
"es6-promise": { "es6-promise": {
"version": "4.2.5", "version": "4.2.5",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz", "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz",
@ -1280,25 +1279,11 @@
"mime-types": "^2.1.12" "mime-types": "^2.1.12"
} }
}, },
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
},
"isomorphic-fetch": { "isomorphic-fetch": {
"version": "2.2.1", "version": "2.2.1",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz",
"integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=",
"requires": { "requires": {
"node-fetch": "^1.0.1",
"whatwg-fetch": ">=0.10.0" "whatwg-fetch": ">=0.10.0"
} }
}, },
@ -1316,13 +1301,9 @@
} }
}, },
"node-fetch": { "node-fetch": {
"version": "1.7.3", "version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
"requires": {
"encoding": "^0.1.11",
"is-stream": "^1.0.1"
}
}, },
"querystringify": { "querystringify": {
"version": "2.1.0", "version": "2.1.0",
@ -1334,11 +1315,6 @@
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=" "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8="
}, },
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"typescript": { "typescript": {
"version": "2.9.2", "version": "2.9.2",
"resolved": false, "resolved": false,

View File

@ -18,17 +18,15 @@ for (let libName in libs) {
requestContext.addCookie("test-cookie", "cookie-value"); requestContext.addCookie("test-cookie", "cookie-value");
lib.send(requestContext).toPromise().then((resp: petstore.ResponseContext) => { lib.send(requestContext).toPromise().then((resp: petstore.ResponseContext) => {
expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
let body = JSON.parse(resp.body); return resp.body.text();
}).then((bodyText: string) => {
let body = JSON.parse(bodyText);
expect(body["headers"]).to.exist; expect(body["headers"]).to.exist;
expect(body["headers"]["X-Test-Token"]).to.equal("Test-Token"); expect(body["headers"]["X-Test-Token"]).to.equal("Test-Token");
expect(body["headers"]["Cookie"]).to.equal("test-cookie=cookie-value;"); expect(body["headers"]["Cookie"]).to.equal("test-cookie=cookie-value;");
done(); done();
}, }).catch(done)
(e: any) => { });
done(e);
}
)
})
it("POST-Request", (done) => { it("POST-Request", (done) => {
let requestContext = new petstore.RequestContext("http://httpbin.org/post", petstore.HttpMethod.POST); let requestContext = new petstore.RequestContext("http://httpbin.org/post", petstore.HttpMethod.POST);
@ -42,17 +40,16 @@ for (let libName in libs) {
lib.send(requestContext).toPromise().then( lib.send(requestContext).toPromise().then(
(resp: petstore.ResponseContext) => { (resp: petstore.ResponseContext) => {
expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
let body = JSON.parse(resp.body); return resp.body.text();
}).then((bodyText: string) => {
let body = JSON.parse(bodyText);
expect(body["headers"]).to.exist; expect(body["headers"]).to.exist;
expect(body["headers"]["X-Test-Token"]).to.equal("Test-Token"); expect(body["headers"]["X-Test-Token"]).to.equal("Test-Token");
expect(body["headers"]["Cookie"]).to.equal("test-cookie=cookie-value;"); expect(body["headers"]["Cookie"]).to.equal("test-cookie=cookie-value;");
expect(body["files"]["testFile"]).to.equal("abc"); expect(body["files"]["testFile"]).to.equal("abc");
expect(body["form"]["test"]).to.equal("test2"); expect(body["form"]["test"]).to.equal("test2");
done(); done();
}, }).catch(done)
(e: any) => {
done(e);
})
}); });
it("Cookies-Request", (done) => { it("Cookies-Request", (done) => {
@ -62,13 +59,12 @@ for (let libName in libs) {
lib.send(requestContext).toPromise().then( lib.send(requestContext).toPromise().then(
(resp: petstore.ResponseContext) => { (resp: petstore.ResponseContext) => {
expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200); expect(resp.httpStatusCode, "Expected status code to be 200").to.eq(200);
let body = JSON.parse(resp.body); return resp.body.text();
}).then((bodyText: string) => {
let body = JSON.parse(bodyText);
expect(body["cookies"]["test-cookie"]).to.equal("cookie-value"); expect(body["cookies"]["test-cookie"]).to.equal("cookie-value");
done(); done();
}, }).catch(done)
(e: any) => {
done(e);
})
}) })
}) })
} }

File diff suppressed because it is too large Load Diff