forked from loafle/openapi-generator-original
[typescript-fetch] Fix uploading files (#2900)
* [typescript-fetch] Fix uploading files * Check for Blob instead of File * Update samples * Update samples * Update samples * Update samples * Regenerate samples * Bug * Manually fix samples * Implement support for Buffer and Blob in a backwards-compatible way * Rework how blob and buffer instance checking works * Check for Blob/Buffer existence properly * Avoid using Buffer and Blob in type declarations * Remove Buffer support * Update samples/client/petstore/typescript-fetch/tests/default/test/PetApi.ts Co-Authored-By: Esteban Marin <estebanmarin@gmx.ch> * Update samples/client/petstore/typescript-fetch/tests/default/test/PetApi.ts Co-Authored-By: Esteban Marin <estebanmarin@gmx.ch>
This commit is contained in:
parent
ddf21f0ca5
commit
c509d9897a
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
export const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
|
export const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
|
||||||
|
|
||||||
|
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the base class for all generated API classes.
|
* This is the base class for all generated API classes.
|
||||||
*/
|
*/
|
||||||
@ -47,7 +49,9 @@ export class BaseAPI {
|
|||||||
// do not handle correctly sometimes.
|
// do not handle correctly sometimes.
|
||||||
url += '?' + querystring(context.query);
|
url += '?' + querystring(context.query);
|
||||||
}
|
}
|
||||||
const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body);
|
const body = (context.body instanceof FormData || isBlob(context.body))
|
||||||
|
? context.body
|
||||||
|
: JSON.stringify(context.body);
|
||||||
const init = {
|
const init = {
|
||||||
method: context.method,
|
method: context.method,
|
||||||
headers: context.headers,
|
headers: context.headers,
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
// tslint:disable
|
||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { exists, mapValues } from '../runtime';
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @interface InlineObject
|
||||||
|
*/
|
||||||
|
export interface InlineObject {
|
||||||
|
/**
|
||||||
|
* Updated name of the pet
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject
|
||||||
|
*/
|
||||||
|
name?: string;
|
||||||
|
/**
|
||||||
|
* Updated status of the pet
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject
|
||||||
|
*/
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObjectFromJSON(json: any): InlineObject {
|
||||||
|
return {
|
||||||
|
'name': !exists(json, 'name') ? undefined : json['name'],
|
||||||
|
'status': !exists(json, 'status') ? undefined : json['status'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObjectToJSON(value?: InlineObject): any {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'name': value.name,
|
||||||
|
'status': value.status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
|||||||
|
// tslint:disable
|
||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { exists, mapValues } from '../runtime';
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @interface InlineObject1
|
||||||
|
*/
|
||||||
|
export interface InlineObject1 {
|
||||||
|
/**
|
||||||
|
* Additional data to pass to server
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject1
|
||||||
|
*/
|
||||||
|
additionalMetadata?: string;
|
||||||
|
/**
|
||||||
|
* file to upload
|
||||||
|
* @type {Blob}
|
||||||
|
* @memberof InlineObject1
|
||||||
|
*/
|
||||||
|
file?: Blob;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObject1FromJSON(json: any): InlineObject1 {
|
||||||
|
return {
|
||||||
|
'additionalMetadata': !exists(json, 'additionalMetadata') ? undefined : json['additionalMetadata'],
|
||||||
|
'file': !exists(json, 'file') ? undefined : json['file'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObject1ToJSON(value?: InlineObject1): any {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'additionalMetadata': value.additionalMetadata,
|
||||||
|
'file': value.file,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
||||||
|
|
||||||
|
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the base class for all generated API classes.
|
* This is the base class for all generated API classes.
|
||||||
*/
|
*/
|
||||||
@ -58,7 +60,9 @@ export class BaseAPI {
|
|||||||
// do not handle correctly sometimes.
|
// do not handle correctly sometimes.
|
||||||
url += '?' + querystring(context.query);
|
url += '?' + querystring(context.query);
|
||||||
}
|
}
|
||||||
const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body);
|
const body = (context.body instanceof FormData || isBlob(context.body))
|
||||||
|
? context.body
|
||||||
|
: JSON.stringify(context.body);
|
||||||
const init = {
|
const init = {
|
||||||
method: context.method,
|
method: context.method,
|
||||||
headers: context.headers,
|
headers: context.headers,
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
// tslint:disable
|
||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { exists, mapValues } from '../runtime';
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @interface InlineObject
|
||||||
|
*/
|
||||||
|
export interface InlineObject {
|
||||||
|
/**
|
||||||
|
* Updated name of the pet
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject
|
||||||
|
*/
|
||||||
|
name?: string;
|
||||||
|
/**
|
||||||
|
* Updated status of the pet
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject
|
||||||
|
*/
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObjectFromJSON(json: any): InlineObject {
|
||||||
|
return {
|
||||||
|
'name': !exists(json, 'name') ? undefined : json['name'],
|
||||||
|
'status': !exists(json, 'status') ? undefined : json['status'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObjectToJSON(value?: InlineObject): any {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'name': value.name,
|
||||||
|
'status': value.status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
|||||||
|
// tslint:disable
|
||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { exists, mapValues } from '../runtime';
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @interface InlineObject1
|
||||||
|
*/
|
||||||
|
export interface InlineObject1 {
|
||||||
|
/**
|
||||||
|
* Additional data to pass to server
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject1
|
||||||
|
*/
|
||||||
|
additionalMetadata?: string;
|
||||||
|
/**
|
||||||
|
* file to upload
|
||||||
|
* @type {Blob}
|
||||||
|
* @memberof InlineObject1
|
||||||
|
*/
|
||||||
|
file?: Blob;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObject1FromJSON(json: any): InlineObject1 {
|
||||||
|
return {
|
||||||
|
'additionalMetadata': !exists(json, 'additionalMetadata') ? undefined : json['additionalMetadata'],
|
||||||
|
'file': !exists(json, 'file') ? undefined : json['file'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObject1ToJSON(value?: InlineObject1): any {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'additionalMetadata': value.additionalMetadata,
|
||||||
|
'file': value.file,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
||||||
|
|
||||||
|
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the base class for all generated API classes.
|
* This is the base class for all generated API classes.
|
||||||
*/
|
*/
|
||||||
@ -58,7 +60,9 @@ export class BaseAPI {
|
|||||||
// do not handle correctly sometimes.
|
// do not handle correctly sometimes.
|
||||||
url += '?' + querystring(context.query);
|
url += '?' + querystring(context.query);
|
||||||
}
|
}
|
||||||
const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body);
|
const body = (context.body instanceof FormData || isBlob(context.body))
|
||||||
|
? context.body
|
||||||
|
: JSON.stringify(context.body);
|
||||||
const init = {
|
const init = {
|
||||||
method: context.method,
|
method: context.method,
|
||||||
headers: context.headers,
|
headers: context.headers,
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
// tslint:disable
|
||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { exists, mapValues } from '../runtime';
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @interface InlineObject
|
||||||
|
*/
|
||||||
|
export interface InlineObject {
|
||||||
|
/**
|
||||||
|
* Updated name of the pet
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject
|
||||||
|
*/
|
||||||
|
name?: string;
|
||||||
|
/**
|
||||||
|
* Updated status of the pet
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject
|
||||||
|
*/
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObjectFromJSON(json: any): InlineObject {
|
||||||
|
return {
|
||||||
|
'name': !exists(json, 'name') ? undefined : json['name'],
|
||||||
|
'status': !exists(json, 'status') ? undefined : json['status'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObjectToJSON(value?: InlineObject): any {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'name': value.name,
|
||||||
|
'status': value.status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
|||||||
|
// tslint:disable
|
||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { exists, mapValues } from '../runtime';
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @interface InlineObject1
|
||||||
|
*/
|
||||||
|
export interface InlineObject1 {
|
||||||
|
/**
|
||||||
|
* Additional data to pass to server
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject1
|
||||||
|
*/
|
||||||
|
additionalMetadata?: string;
|
||||||
|
/**
|
||||||
|
* file to upload
|
||||||
|
* @type {Blob}
|
||||||
|
* @memberof InlineObject1
|
||||||
|
*/
|
||||||
|
file?: Blob;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObject1FromJSON(json: any): InlineObject1 {
|
||||||
|
return {
|
||||||
|
'additionalMetadata': !exists(json, 'additionalMetadata') ? undefined : json['additionalMetadata'],
|
||||||
|
'file': !exists(json, 'file') ? undefined : json['file'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObject1ToJSON(value?: InlineObject1): any {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'additionalMetadata': value.additionalMetadata,
|
||||||
|
'file': value.file,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
||||||
|
|
||||||
|
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the base class for all generated API classes.
|
* This is the base class for all generated API classes.
|
||||||
*/
|
*/
|
||||||
@ -58,7 +60,9 @@ export class BaseAPI {
|
|||||||
// do not handle correctly sometimes.
|
// do not handle correctly sometimes.
|
||||||
url += '?' + querystring(context.query);
|
url += '?' + querystring(context.query);
|
||||||
}
|
}
|
||||||
const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body);
|
const body = (context.body instanceof FormData || isBlob(context.body))
|
||||||
|
? context.body
|
||||||
|
: JSON.stringify(context.body);
|
||||||
const init = {
|
const init = {
|
||||||
method: context.method,
|
method: context.method,
|
||||||
headers: context.headers,
|
headers: context.headers,
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
// tslint:disable
|
||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { exists, mapValues } from '../runtime';
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @interface InlineObject
|
||||||
|
*/
|
||||||
|
export interface InlineObject {
|
||||||
|
/**
|
||||||
|
* Updated name of the pet
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject
|
||||||
|
*/
|
||||||
|
name?: string;
|
||||||
|
/**
|
||||||
|
* Updated status of the pet
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject
|
||||||
|
*/
|
||||||
|
status?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObjectFromJSON(json: any): InlineObject {
|
||||||
|
return {
|
||||||
|
'name': !exists(json, 'name') ? undefined : json['name'],
|
||||||
|
'status': !exists(json, 'status') ? undefined : json['status'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObjectToJSON(value?: InlineObject): any {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'name': value.name,
|
||||||
|
'status': value.status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
|||||||
|
// tslint:disable
|
||||||
|
/**
|
||||||
|
* OpenAPI Petstore
|
||||||
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||||
|
*
|
||||||
|
* The version of the OpenAPI document: 1.0.0
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
||||||
|
* https://openapi-generator.tech
|
||||||
|
* Do not edit the class manually.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { exists, mapValues } from '../runtime';
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @export
|
||||||
|
* @interface InlineObject1
|
||||||
|
*/
|
||||||
|
export interface InlineObject1 {
|
||||||
|
/**
|
||||||
|
* Additional data to pass to server
|
||||||
|
* @type {string}
|
||||||
|
* @memberof InlineObject1
|
||||||
|
*/
|
||||||
|
additionalMetadata?: string;
|
||||||
|
/**
|
||||||
|
* file to upload
|
||||||
|
* @type {Blob}
|
||||||
|
* @memberof InlineObject1
|
||||||
|
*/
|
||||||
|
file?: Blob;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObject1FromJSON(json: any): InlineObject1 {
|
||||||
|
return {
|
||||||
|
'additionalMetadata': !exists(json, 'additionalMetadata') ? undefined : json['additionalMetadata'],
|
||||||
|
'file': !exists(json, 'file') ? undefined : json['file'],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function InlineObject1ToJSON(value?: InlineObject1): any {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
'additionalMetadata': value.additionalMetadata,
|
||||||
|
'file': value.file,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
export const BASE_PATH = "http://petstore.swagger.io/v2".replace(/\/+$/, "");
|
||||||
|
|
||||||
|
const isBlob = (value: any) => typeof Blob !== 'undefined' && value instanceof Blob;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the base class for all generated API classes.
|
* This is the base class for all generated API classes.
|
||||||
*/
|
*/
|
||||||
@ -58,7 +60,9 @@ export class BaseAPI {
|
|||||||
// do not handle correctly sometimes.
|
// do not handle correctly sometimes.
|
||||||
url += '?' + querystring(context.query);
|
url += '?' + querystring(context.query);
|
||||||
}
|
}
|
||||||
const body = context.body instanceof FormData ? context.body : JSON.stringify(context.body);
|
const body = (context.body instanceof FormData || isBlob(context.body))
|
||||||
|
? context.body
|
||||||
|
: JSON.stringify(context.body);
|
||||||
const init = {
|
const init = {
|
||||||
method: context.method,
|
method: context.method,
|
||||||
headers: context.headers,
|
headers: context.headers,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user