forked from loafle/openapi-generator-original
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:
parent
659369c3ea
commit
e315d48636
@ -52,7 +52,7 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.{{httpMethod}});
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
{{#queryParams}}
|
||||
@ -96,9 +96,9 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
|
||||
{{#node}}
|
||||
localVarFormParams.append('{{baseName}}', {{paramName}}.data, {{paramName}}.name);
|
||||
{{/node}}
|
||||
{{^node}}
|
||||
{{#browser}}
|
||||
localVarFormParams.append('{{baseName}}', {{paramName}}, {{paramName}}.name);
|
||||
{{/node}}
|
||||
{{/browser}}
|
||||
{{/platforms}}
|
||||
{{/isFile}}
|
||||
}
|
||||
@ -110,15 +110,14 @@ export class {{classname}}RequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Body Params
|
||||
{{#bodyParam}}
|
||||
{{^consumes}}
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
{{/consumes}}
|
||||
{{#consumes.0}}
|
||||
requestContext.setHeaderParam("Content-Type", "{{{mediaType}}}");
|
||||
{{/consumes.0}}
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"{{dataType}}" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify({{paramName}} || {}) : ({{paramName}} || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([{{#consumes}}
|
||||
"{{{mediaType}}}"{{#hasMore}},{{/hasMore}}
|
||||
{{/consumes}}]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize({{paramName}}, "{{{dataType}}}", "{{dataFormat}}"),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
{{/bodyParam}}
|
||||
|
||||
@ -153,12 +152,20 @@ export class {{classname}}ResponseProcessor {
|
||||
* @params response Response returned by the server for a request to {{nickname}}
|
||||
* @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}}
|
||||
if (isCodeInRange("{{code}}", response.httpStatusCode)) {
|
||||
{{#dataType}}
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: {{{dataType}}} = ObjectSerializer.deserialize(jsonBody, "{{{dataType}}}", "{{returnFormat}}") as {{{dataType}}};
|
||||
{{#isBinary}}
|
||||
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}}
|
||||
return body;
|
||||
{{/isSuccessCode}}
|
||||
@ -173,21 +180,29 @@ export class {{classname}}ResponseProcessor {
|
||||
{{^isSuccessCode}}
|
||||
throw new ApiException<string>(response.httpStatusCode, "{{message}}");
|
||||
{{/isSuccessCode}}
|
||||
{{/dataType}}
|
||||
{{/dataType}}
|
||||
}
|
||||
{{/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) {
|
||||
{{#returnType}}
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: {{{returnType}}} = ObjectSerializer.deserialize(jsonBody, "{{{returnType}}}", "{{returnFormat}}") as {{{returnType}}};
|
||||
return body;
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
return;
|
||||
{{/returnType}}
|
||||
{{#returnType}}
|
||||
{{#isBinary}}
|
||||
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;
|
||||
{{/returnType}}
|
||||
{{^returnType}}
|
||||
return;
|
||||
{{/returnType}}
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
|
@ -43,9 +43,9 @@ export type HttpFile = {
|
||||
name: string
|
||||
};
|
||||
{{/node}}
|
||||
{{^node}}
|
||||
{{#browser}}
|
||||
export type HttpFile = {{{fileContentDataType}}} & { readonly name: string };
|
||||
{{/node}}
|
||||
{{/browser}}
|
||||
{{/platforms}}
|
||||
|
||||
|
||||
@ -141,12 +141,104 @@ export class RequestContext {
|
||||
}
|
||||
}
|
||||
|
||||
export class ResponseContext {
|
||||
export interface ResponseBody {
|
||||
text(): Promise<string>;
|
||||
binary(): Promise<{{{fileContentDataType}}}>;
|
||||
}
|
||||
|
||||
public constructor(public httpStatusCode: number,
|
||||
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 {
|
||||
|
@ -1,33 +1,52 @@
|
||||
declare var fetch: any;
|
||||
|
||||
import {HttpLibrary, RequestContext, ResponseContext} from './http';
|
||||
import 'es6-promise/auto';
|
||||
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 {
|
||||
|
||||
public send(request: RequestContext): Observable<ResponseContext> {
|
||||
let method = request.getHttpMethod().toString();
|
||||
let body = request.getBody();
|
||||
|
||||
|
||||
const resultPromise = fetch(request.getUrl(), {
|
||||
method: method,
|
||||
body: body as any,
|
||||
headers: request.getHeaders(),
|
||||
{{#platforms}}
|
||||
{{#browser}}
|
||||
credentials: "same-origin"
|
||||
{{/browser}}
|
||||
{{/platforms}}
|
||||
}).then((resp: any) => {
|
||||
// hack
|
||||
let headers = (resp.headers as any)._headers;
|
||||
for (let key in headers) {
|
||||
headers[key] = (headers[key] as Array<string>).join("; ");
|
||||
}
|
||||
|
||||
return resp.text().then((body: string) => {
|
||||
return new ResponseContext(resp.status, headers, body)
|
||||
const headers: { [name: string]: string } = {};
|
||||
resp.headers.forEach((value: string, name: string) => {
|
||||
headers[name] = value;
|
||||
});
|
||||
|
||||
{{#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);
|
||||
|
||||
}
|
||||
|
@ -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 { from, Observable } from {{#useRxJS}}'rxjs'{{/useRxJS}}{{^useRxJS}}'../rxjsStub'{{/useRxJS}};
|
||||
e6p.polyfill();
|
||||
import * as $ from 'jquery';
|
||||
{{#platforms}}
|
||||
{{#node}}
|
||||
import * as FormData from "form-data";
|
||||
{{/node}}
|
||||
{{/platforms}}
|
||||
|
||||
|
||||
export class JQueryHttpLibrary implements HttpLibrary {
|
||||
|
||||
@ -21,10 +17,20 @@ export class JQueryHttpLibrary implements HttpLibrary {
|
||||
type: method,
|
||||
headers: request.getHeaders(),
|
||||
processData: false,
|
||||
xhrFields: { withCredentials: true },
|
||||
xhrFields: { withCredentials: true },
|
||||
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']) {
|
||||
requestOptions.contentType = headerParams['Content-Type'];
|
||||
}
|
||||
@ -48,9 +54,12 @@ export class JQueryHttpLibrary implements HttpLibrary {
|
||||
const sentRequest = $.ajax(requestOptions);
|
||||
|
||||
const resultPromise = new Promise<ResponseContext>((resolve, reject) => {
|
||||
sentRequest.done((resp, _, jqXHR) => {
|
||||
const headers = this.getResponseHeaders(jqXHR)
|
||||
const result = new ResponseContext(jqXHR.status, headers, JSON.stringify(resp));
|
||||
sentRequest.done((data, _, jqXHR) => {
|
||||
const result = new ResponseContext(
|
||||
jqXHR.status,
|
||||
this.getResponseHeaders(jqXHR),
|
||||
new SelfDecodingBody(Promise.resolve(data))
|
||||
);
|
||||
resolve(result);
|
||||
})
|
||||
sentRequest.fail((jqXHR: any) => {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'es6-promise/auto';
|
||||
|
||||
export * from './http/http';
|
||||
export * from './auth/auth';
|
||||
export * from './models/all';
|
||||
|
@ -21,6 +21,12 @@ let primitives = [
|
||||
"number",
|
||||
"any"
|
||||
];
|
||||
|
||||
const supportedMediaTypes: { [mediaType: string]: number } = {
|
||||
"application/json": Infinity,
|
||||
"application/octet-stream": 0
|
||||
}
|
||||
|
||||
|
||||
let enumsMap: Set<string> = new Set<string>([
|
||||
{{#models}}
|
||||
@ -162,4 +168,73 @@ export class ObjectSerializer {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
@ -19,8 +19,15 @@
|
||||
"dependencies": {
|
||||
{{#frameworks}}
|
||||
{{#fetch-api}}
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"@types/isomorphic-fetch": "0.0.34",
|
||||
{{#platforms}}
|
||||
{{#node}}
|
||||
"node-fetch": "^2.6.0",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
{{/node}}
|
||||
{{#browser}}
|
||||
"whatwg-fetch": "^3.0.0",
|
||||
{{/browser}}
|
||||
{{/platforms}}
|
||||
{{/fetch-api}}
|
||||
{{#jquery}}
|
||||
"@types/jquery": "^3.3.29",
|
||||
|
@ -16,7 +16,14 @@
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"noLib": false,
|
||||
{{#platforms}}
|
||||
{{#node}}
|
||||
"lib": [ "es6" ]
|
||||
{{/node}}
|
||||
{{#browser}}
|
||||
"lib": [ "es6", "dom" ]
|
||||
{{/browser}}
|
||||
{{/platforms}}
|
||||
},
|
||||
"exclude": [
|
||||
"dist",
|
||||
|
@ -33,7 +33,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -43,10 +43,16 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([
|
||||
"application/json",
|
||||
|
||||
"application/xml"
|
||||
]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Pet", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
let authMethod = null;
|
||||
@ -80,7 +86,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -121,7 +127,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
if (status !== undefined) {
|
||||
@ -164,7 +170,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
if (tags !== undefined) {
|
||||
@ -208,7 +214,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -247,7 +253,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -257,10 +263,16 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([
|
||||
"application/json",
|
||||
|
||||
"application/xml"
|
||||
]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Pet", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
let authMethod = null;
|
||||
@ -296,7 +308,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -350,7 +362,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -394,15 +406,17 @@ export class PetApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to addPet
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>;
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Array<Pet>", ""
|
||||
) as Array<Pet>;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>;
|
||||
return body;
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Array<Pet>", ""
|
||||
) as Array<Pet>;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>;
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Array<Pet>", ""
|
||||
) as Array<Pet>;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>;
|
||||
return body;
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Array<Pet>", ""
|
||||
) as Array<Pet>;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Pet = ObjectSerializer.deserialize(jsonBody, "Pet", "") as Pet;
|
||||
const body: Pet = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Pet", ""
|
||||
) as Pet;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
@ -500,13 +531,16 @@ export class PetApiResponseProcessor {
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Pet = ObjectSerializer.deserialize(jsonBody, "Pet", "") as Pet;
|
||||
return body;
|
||||
const body: Pet = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Pet", ""
|
||||
) as Pet;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
||||
}
|
||||
@ -528,11 +563,12 @@ export class PetApiResponseProcessor {
|
||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: ApiResponse = ObjectSerializer.deserialize(jsonBody, "ApiResponse", "") as ApiResponse;
|
||||
const body: ApiResponse = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"ApiResponse", ""
|
||||
) as ApiResponse;
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: ApiResponse = ObjectSerializer.deserialize(jsonBody, "ApiResponse", "") as ApiResponse;
|
||||
return body;
|
||||
const body: ApiResponse = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"ApiResponse", ""
|
||||
) as ApiResponse;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -62,7 +62,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -103,7 +103,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -137,7 +137,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -147,10 +147,12 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Order" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Order", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -171,18 +173,20 @@ export class StoreApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to deleteOrder
|
||||
* @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)) {
|
||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
||||
}
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: { [key: string]: number; } = ObjectSerializer.deserialize(jsonBody, "{ [key: string]: number; }", "int32") as { [key: string]: number; };
|
||||
const body: { [key: string]: number; } = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"{ [key: string]: number; }", "int32"
|
||||
) as { [key: string]: number; };
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: { [key: string]: number; } = ObjectSerializer.deserialize(jsonBody, "{ [key: string]: number; }", "int32") as { [key: string]: number; };
|
||||
return body;
|
||||
const body: { [key: string]: number; } = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"{ [key: string]: number; }", "int32"
|
||||
) as { [key: string]: number; };
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order;
|
||||
const body: Order = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Order", ""
|
||||
) as Order;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
@ -230,13 +243,16 @@ export class StoreApiResponseProcessor {
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order;
|
||||
return body;
|
||||
const body: Order = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Order", ""
|
||||
) as Order;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order;
|
||||
const body: Order = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Order", ""
|
||||
) as Order;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order;
|
||||
return body;
|
||||
const body: Order = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Order", ""
|
||||
) as Order;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -43,10 +43,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "User", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -72,7 +74,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -82,10 +84,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Array<User>" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Array<User>", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -111,7 +115,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -121,10 +125,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Array<User>" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Array<User>", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -152,7 +158,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -187,7 +193,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -228,7 +234,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
if (username !== undefined) {
|
||||
@ -261,7 +267,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -304,7 +310,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -314,10 +320,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "User", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -338,15 +346,17 @@ export class UserApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to createUser
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
@ -398,18 +412,20 @@ export class UserApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to deleteUser
|
||||
* @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)) {
|
||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
||||
}
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: User = ObjectSerializer.deserialize(jsonBody, "User", "") as User;
|
||||
const body: User = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"User", ""
|
||||
) as User;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
@ -433,13 +452,16 @@ export class UserApiResponseProcessor {
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: User = ObjectSerializer.deserialize(jsonBody, "User", "") as User;
|
||||
return body;
|
||||
const body: User = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"User", ""
|
||||
) as User;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: string = ObjectSerializer.deserialize(jsonBody, "string", "") as string;
|
||||
const body: string = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"string", ""
|
||||
) as string;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: string = ObjectSerializer.deserialize(jsonBody, "string", "") as string;
|
||||
return body;
|
||||
const body: string = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"string", ""
|
||||
) as string;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
@ -498,18 +528,20 @@ export class UserApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to updateUser
|
||||
* @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)) {
|
||||
throw new ApiException<string>(response.httpStatusCode, "Invalid user supplied");
|
||||
}
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
|
@ -123,12 +123,70 @@ export class RequestContext {
|
||||
}
|
||||
}
|
||||
|
||||
export class ResponseContext {
|
||||
export interface ResponseBody {
|
||||
text(): Promise<string>;
|
||||
binary(): Promise<Buffer>;
|
||||
}
|
||||
|
||||
public constructor(public httpStatusCode: number,
|
||||
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 {
|
||||
|
@ -1,33 +1,30 @@
|
||||
declare var fetch: any;
|
||||
|
||||
import {HttpLibrary, RequestContext, ResponseContext} from './http';
|
||||
import 'es6-promise/auto';
|
||||
import { from, Observable } from '../rxjsStub';
|
||||
import 'isomorphic-fetch';
|
||||
import fetch from "node-fetch";
|
||||
|
||||
export class IsomorphicFetchHttpLibrary implements HttpLibrary {
|
||||
|
||||
public send(request: RequestContext): Observable<ResponseContext> {
|
||||
let method = request.getHttpMethod().toString();
|
||||
let body = request.getBody();
|
||||
|
||||
|
||||
const resultPromise = fetch(request.getUrl(), {
|
||||
method: method,
|
||||
body: body as any,
|
||||
headers: request.getHeaders(),
|
||||
credentials: "same-origin"
|
||||
}).then((resp: any) => {
|
||||
// hack
|
||||
let headers = (resp.headers as any)._headers;
|
||||
for (let key in headers) {
|
||||
headers[key] = (headers[key] as Array<string>).join("; ");
|
||||
}
|
||||
|
||||
return resp.text().then((body: string) => {
|
||||
return new ResponseContext(resp.status, headers, body)
|
||||
const headers: { [name: string]: string } = {};
|
||||
resp.headers.forEach((value: string, name: string) => {
|
||||
headers[name] = value;
|
||||
});
|
||||
|
||||
const body = {
|
||||
text: () => resp.text(),
|
||||
binary: () => resp.buffer()
|
||||
};
|
||||
return new ResponseContext(resp.status, headers, body);
|
||||
});
|
||||
|
||||
|
||||
return from<Promise<ResponseContext>>(resultPromise);
|
||||
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'es6-promise/auto';
|
||||
|
||||
export * from './http/http';
|
||||
export * from './auth/auth';
|
||||
export * from './models/all';
|
||||
|
@ -23,6 +23,12 @@ let primitives = [
|
||||
"number",
|
||||
"any"
|
||||
];
|
||||
|
||||
const supportedMediaTypes: { [mediaType: string]: number } = {
|
||||
"application/json": Infinity,
|
||||
"application/octet-stream": 0
|
||||
}
|
||||
|
||||
|
||||
let enumsMap: Set<string> = new Set<string>([
|
||||
"OrderStatusEnum",
|
||||
@ -156,4 +162,73 @@ export class ObjectSerializer {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,32 @@
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"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": {
|
||||
"version": "12.12.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.7.tgz",
|
||||
"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": {
|
||||
"version": "0.4.0",
|
||||
"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",
|
||||
"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": {
|
||||
"version": "4.2.5",
|
||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz",
|
||||
@ -60,28 +68,6 @@
|
||||
"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": {
|
||||
"version": "1.40.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz",
|
||||
@ -96,13 +82,9 @@
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
||||
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
|
||||
"requires": {
|
||||
"encoding": "^0.1.11",
|
||||
"is-stream": "^1.0.1"
|
||||
}
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
|
||||
},
|
||||
"querystringify": {
|
||||
"version": "2.1.0",
|
||||
@ -114,14 +96,9 @@
|
||||
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
||||
"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": {
|
||||
"version": "2.9.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-2.9.2.tgz",
|
||||
"resolved": false,
|
||||
"integrity": "sha512-Gr4p6nFNaoufRIY4NMdpQRNmgxVIGMs4Fcu/ujdYk3nAZqk7supzBE9idmvfZIlH/Cuj//dvi+019qEue9lV0w==",
|
||||
"dev": true
|
||||
},
|
||||
@ -133,11 +110,6 @@
|
||||
"querystringify": "^2.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=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"@types/isomorphic-fetch": "0.0.34",
|
||||
"node-fetch": "^2.6.0",
|
||||
"@types/node-fetch": "^2.5.7",
|
||||
"@types/node": "*",
|
||||
"form-data": "^2.5.0",
|
||||
"btoa": "^1.2.1",
|
||||
|
@ -16,7 +16,7 @@
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"noLib": false,
|
||||
"lib": [ "es6", "dom" ]
|
||||
"lib": [ "es6" ]
|
||||
},
|
||||
"exclude": [
|
||||
"dist",
|
||||
|
@ -32,7 +32,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -42,10 +42,16 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([
|
||||
"application/json",
|
||||
|
||||
"application/xml"
|
||||
]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Pet", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
let authMethod = null;
|
||||
@ -79,7 +85,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -120,7 +126,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
if (status !== undefined) {
|
||||
@ -163,7 +169,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
if (tags !== undefined) {
|
||||
@ -207,7 +213,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -246,7 +252,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -256,10 +262,16 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([
|
||||
"application/json",
|
||||
|
||||
"application/xml"
|
||||
]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Pet", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
let authMethod = null;
|
||||
@ -295,7 +307,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -349,7 +361,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -393,15 +405,17 @@ export class PetApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to addPet
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>;
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Array<Pet>", ""
|
||||
) as Array<Pet>;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>;
|
||||
return body;
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Array<Pet>", ""
|
||||
) as Array<Pet>;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>;
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Array<Pet>", ""
|
||||
) as Array<Pet>;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(jsonBody, "Array<Pet>", "") as Array<Pet>;
|
||||
return body;
|
||||
const body: Array<Pet> = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Array<Pet>", ""
|
||||
) as Array<Pet>;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Pet = ObjectSerializer.deserialize(jsonBody, "Pet", "") as Pet;
|
||||
const body: Pet = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Pet", ""
|
||||
) as Pet;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
@ -499,13 +530,16 @@ export class PetApiResponseProcessor {
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Pet = ObjectSerializer.deserialize(jsonBody, "Pet", "") as Pet;
|
||||
return body;
|
||||
const body: Pet = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Pet", ""
|
||||
) as Pet;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
||||
}
|
||||
@ -527,11 +562,12 @@ export class PetApiResponseProcessor {
|
||||
if (isCodeInRange("405", response.httpStatusCode)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: ApiResponse = ObjectSerializer.deserialize(jsonBody, "ApiResponse", "") as ApiResponse;
|
||||
const body: ApiResponse = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"ApiResponse", ""
|
||||
) as ApiResponse;
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: ApiResponse = ObjectSerializer.deserialize(jsonBody, "ApiResponse", "") as ApiResponse;
|
||||
return body;
|
||||
const body: ApiResponse = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"ApiResponse", ""
|
||||
) as ApiResponse;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -61,7 +61,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -102,7 +102,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -136,7 +136,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -146,10 +146,12 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Order" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Order", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -170,18 +172,20 @@ export class StoreApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to deleteOrder
|
||||
* @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)) {
|
||||
throw new ApiException<string>(response.httpStatusCode, "Invalid ID supplied");
|
||||
}
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: { [key: string]: number; } = ObjectSerializer.deserialize(jsonBody, "{ [key: string]: number; }", "int32") as { [key: string]: number; };
|
||||
const body: { [key: string]: number; } = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"{ [key: string]: number; }", "int32"
|
||||
) as { [key: string]: number; };
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: { [key: string]: number; } = ObjectSerializer.deserialize(jsonBody, "{ [key: string]: number; }", "int32") as { [key: string]: number; };
|
||||
return body;
|
||||
const body: { [key: string]: number; } = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"{ [key: string]: number; }", "int32"
|
||||
) as { [key: string]: number; };
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order;
|
||||
const body: Order = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Order", ""
|
||||
) as Order;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
@ -229,13 +242,16 @@ export class StoreApiResponseProcessor {
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order;
|
||||
return body;
|
||||
const body: Order = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Order", ""
|
||||
) as Order;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order;
|
||||
const body: Order = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Order", ""
|
||||
) as Order;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: Order = ObjectSerializer.deserialize(jsonBody, "Order", "") as Order;
|
||||
return body;
|
||||
const body: Order = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"Order", ""
|
||||
) as Order;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -42,10 +42,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "User", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -71,7 +73,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -81,10 +83,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Array<User>" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Array<User>", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -110,7 +114,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.POST);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -120,10 +124,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"Array<User>" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "Array<User>", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -151,7 +157,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.DELETE);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -186,7 +192,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -227,7 +233,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
if (username !== undefined) {
|
||||
@ -260,7 +266,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.GET);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -303,7 +309,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
// Make Request Context
|
||||
const requestContext = config.baseServer.makeRequestContext(localVarPath, HttpMethod.PUT);
|
||||
requestContext.setHeaderParam("Accept", "application/json")
|
||||
requestContext.setHeaderParam("Accept", "application/json, */*;q=0.8")
|
||||
|
||||
// Query Params
|
||||
|
||||
@ -313,10 +319,12 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory {
|
||||
|
||||
|
||||
// Body Params
|
||||
requestContext.setHeaderParam("Content-Type", "application/json");
|
||||
// TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent
|
||||
const needsSerialization = (<any>"User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json';
|
||||
const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body || "").toString(); // TODO: `toString` call is unnecessary
|
||||
const contentType = ObjectSerializer.getPreferredMediaType([]);
|
||||
requestContext.setHeaderParam("Content-Type", contentType);
|
||||
const serializedBody = ObjectSerializer.stringify(
|
||||
ObjectSerializer.serialize(body, "User", ""),
|
||||
contentType
|
||||
);
|
||||
requestContext.setBody(serializedBody);
|
||||
|
||||
// Apply auth methods
|
||||
@ -337,15 +345,17 @@ export class UserApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to createUser
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
@ -397,18 +411,20 @@ export class UserApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to deleteUser
|
||||
* @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)) {
|
||||
throw new ApiException<string>(response.httpStatusCode, "Invalid username supplied");
|
||||
}
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: User = ObjectSerializer.deserialize(jsonBody, "User", "") as User;
|
||||
const body: User = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"User", ""
|
||||
) as User;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
@ -432,13 +451,16 @@ export class UserApiResponseProcessor {
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: User = ObjectSerializer.deserialize(jsonBody, "User", "") as User;
|
||||
return body;
|
||||
const body: User = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"User", ""
|
||||
) as User;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: string = ObjectSerializer.deserialize(jsonBody, "string", "") as string;
|
||||
const body: string = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"string", ""
|
||||
) as string;
|
||||
return body;
|
||||
}
|
||||
if (isCodeInRange("400", response.httpStatusCode)) {
|
||||
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) {
|
||||
const jsonBody = JSON.parse(response.body);
|
||||
const body: string = ObjectSerializer.deserialize(jsonBody, "string", "") as string;
|
||||
return body;
|
||||
const body: string = ObjectSerializer.deserialize(
|
||||
ObjectSerializer.parse(await response.body.text(), contentType),
|
||||
"string", ""
|
||||
) as string;
|
||||
return body;
|
||||
}
|
||||
|
||||
let body = response.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
|
||||
* @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)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
@ -497,18 +527,20 @@ export class UserApiResponseProcessor {
|
||||
* @params response Response returned by the server for a request to updateUser
|
||||
* @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)) {
|
||||
throw new ApiException<string>(response.httpStatusCode, "Invalid user supplied");
|
||||
}
|
||||
if (isCodeInRange("404", response.httpStatusCode)) {
|
||||
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) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
let body = response.body || "";
|
||||
throw new ApiException<string>(response.httpStatusCode, "Unknown API Status Code!\nBody: \"" + body + "\"");
|
||||
}
|
||||
|
@ -118,12 +118,90 @@ export class RequestContext {
|
||||
}
|
||||
}
|
||||
|
||||
export class ResponseContext {
|
||||
export interface ResponseBody {
|
||||
text(): Promise<string>;
|
||||
binary(): Promise<Blob>;
|
||||
}
|
||||
|
||||
public constructor(public httpStatusCode: number,
|
||||
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 {
|
||||
|
@ -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 { from, Observable } from '../rxjsStub';
|
||||
e6p.polyfill();
|
||||
import * as $ from 'jquery';
|
||||
|
||||
|
||||
export class JQueryHttpLibrary implements HttpLibrary {
|
||||
|
||||
public send(request: RequestContext): Observable<ResponseContext> {
|
||||
@ -16,10 +17,20 @@ export class JQueryHttpLibrary implements HttpLibrary {
|
||||
type: method,
|
||||
headers: request.getHeaders(),
|
||||
processData: false,
|
||||
xhrFields: { withCredentials: true },
|
||||
xhrFields: { withCredentials: true },
|
||||
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']) {
|
||||
requestOptions.contentType = headerParams['Content-Type'];
|
||||
}
|
||||
@ -43,9 +54,12 @@ export class JQueryHttpLibrary implements HttpLibrary {
|
||||
const sentRequest = $.ajax(requestOptions);
|
||||
|
||||
const resultPromise = new Promise<ResponseContext>((resolve, reject) => {
|
||||
sentRequest.done((resp, _, jqXHR) => {
|
||||
const headers = this.getResponseHeaders(jqXHR)
|
||||
const result = new ResponseContext(jqXHR.status, headers, JSON.stringify(resp));
|
||||
sentRequest.done((data, _, jqXHR) => {
|
||||
const result = new ResponseContext(
|
||||
jqXHR.status,
|
||||
this.getResponseHeaders(jqXHR),
|
||||
new SelfDecodingBody(Promise.resolve(data))
|
||||
);
|
||||
resolve(result);
|
||||
})
|
||||
sentRequest.fail((jqXHR: any) => {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'es6-promise/auto';
|
||||
|
||||
export * from './http/http';
|
||||
export * from './auth/auth';
|
||||
export * from './models/all';
|
||||
|
@ -23,6 +23,12 @@ let primitives = [
|
||||
"number",
|
||||
"any"
|
||||
];
|
||||
|
||||
const supportedMediaTypes: { [mediaType: string]: number } = {
|
||||
"application/json": Infinity,
|
||||
"application/octet-stream": 0
|
||||
}
|
||||
|
||||
|
||||
let enumsMap: Set<string> = new Set<string>([
|
||||
"OrderStatusEnum",
|
||||
@ -156,4 +162,73 @@ export class ObjectSerializer {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
@ -28,9 +28,9 @@
|
||||
"integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q=="
|
||||
},
|
||||
"jquery": {
|
||||
"version": "3.4.1",
|
||||
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz",
|
||||
"integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw=="
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz",
|
||||
"integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg=="
|
||||
},
|
||||
"querystringify": {
|
||||
"version": "2.1.1",
|
||||
|
@ -34,9 +34,9 @@
|
||||
"integrity": "sha512-uD0j/AQOa5le7afuK+u+woi8jNKF1vf3DN0H7LCJhft/lNNibUr7VcAesdgtWfEKveZol3ZG1CJqwx2Bhrnl8w=="
|
||||
},
|
||||
"acorn": {
|
||||
"version": "5.7.3",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.3.tgz",
|
||||
"integrity": "sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw=="
|
||||
"version": "5.7.4",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-5.7.4.tgz",
|
||||
"integrity": "sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg=="
|
||||
},
|
||||
"acorn-jsx": {
|
||||
"version": "3.0.1",
|
||||
@ -748,9 +748,9 @@
|
||||
}
|
||||
},
|
||||
"lodash": {
|
||||
"version": "4.17.11",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
|
||||
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
|
||||
"version": "4.17.15",
|
||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
|
||||
},
|
||||
"lru-cache": {
|
||||
"version": "4.1.5",
|
||||
@ -803,23 +803,16 @@
|
||||
}
|
||||
},
|
||||
"minimist": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||
"version": "1.2.5",
|
||||
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
|
||||
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
|
||||
},
|
||||
"mkdirp": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
|
||||
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
|
||||
"version": "0.5.5",
|
||||
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
|
||||
"integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
|
||||
"requires": {
|
||||
"minimist": "0.0.8"
|
||||
},
|
||||
"dependencies": {
|
||||
"minimist": {
|
||||
"version": "0.0.8",
|
||||
"resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
|
||||
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
|
||||
}
|
||||
"minimist": "^1.2.5"
|
||||
}
|
||||
},
|
||||
"mocha": {
|
||||
@ -841,6 +834,21 @@
|
||||
"supports-color": "5.4.0"
|
||||
},
|
||||
"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": {
|
||||
"version": "5.4.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",
|
||||
@ -1215,12 +1223,11 @@
|
||||
"ts-petstore-client": {
|
||||
"version": "file:../../builds/default",
|
||||
"requires": {
|
||||
"@types/isomorphic-fetch": "0.0.34",
|
||||
"@types/node": "*",
|
||||
"btoa": "^1.2.1",
|
||||
"es6-promise": "^4.2.4",
|
||||
"form-data": "^2.5.0",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"node-fetch": "^2.6.0",
|
||||
"url-parse": "^1.4.3"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -1257,14 +1264,6 @@
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"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": {
|
||||
"version": "4.2.5",
|
||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.5.tgz",
|
||||
@ -1280,25 +1279,11 @@
|
||||
"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"
|
||||
}
|
||||
},
|
||||
@ -1316,13 +1301,9 @@
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
||||
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
|
||||
"requires": {
|
||||
"encoding": "^0.1.11",
|
||||
"is-stream": "^1.0.1"
|
||||
}
|
||||
"version": "2.6.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
|
||||
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
|
||||
},
|
||||
"querystringify": {
|
||||
"version": "2.1.0",
|
||||
@ -1334,11 +1315,6 @@
|
||||
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
|
||||
"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": {
|
||||
"version": "2.9.2",
|
||||
"resolved": false,
|
||||
|
@ -18,17 +18,15 @@ for (let libName in libs) {
|
||||
requestContext.addCookie("test-cookie", "cookie-value");
|
||||
lib.send(requestContext).toPromise().then((resp: petstore.ResponseContext) => {
|
||||
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"]["X-Test-Token"]).to.equal("Test-Token");
|
||||
expect(body["headers"]["Cookie"]).to.equal("test-cookie=cookie-value;");
|
||||
done();
|
||||
},
|
||||
(e: any) => {
|
||||
done(e);
|
||||
}
|
||||
)
|
||||
})
|
||||
}).catch(done)
|
||||
});
|
||||
|
||||
it("POST-Request", (done) => {
|
||||
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(
|
||||
(resp: petstore.ResponseContext) => {
|
||||
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"]["X-Test-Token"]).to.equal("Test-Token");
|
||||
expect(body["headers"]["Cookie"]).to.equal("test-cookie=cookie-value;");
|
||||
expect(body["files"]["testFile"]).to.equal("abc");
|
||||
expect(body["form"]["test"]).to.equal("test2");
|
||||
done();
|
||||
},
|
||||
(e: any) => {
|
||||
done(e);
|
||||
})
|
||||
}).catch(done)
|
||||
});
|
||||
|
||||
it("Cookies-Request", (done) => {
|
||||
@ -62,13 +59,12 @@ for (let libName in libs) {
|
||||
lib.send(requestContext).toPromise().then(
|
||||
(resp: petstore.ResponseContext) => {
|
||||
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");
|
||||
done();
|
||||
},
|
||||
(e: any) => {
|
||||
done(e);
|
||||
})
|
||||
}).catch(done)
|
||||
})
|
||||
})
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user