diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache index 6f8038f5bdf2..cb7f747ea45f 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/runtime.mustache @@ -3,6 +3,8 @@ 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. */ @@ -47,7 +49,9 @@ export class BaseAPI { // do not handle correctly sometimes. 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 = { method: context.method, headers: context.headers, diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/InlineObject.ts b/samples/client/petstore/typescript-fetch/builds/default/models/InlineObject.ts new file mode 100644 index 000000000000..2998b1463ce5 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/default/models/InlineObject.ts @@ -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, + }; +} + + diff --git a/samples/client/petstore/typescript-fetch/builds/default/models/InlineObject1.ts b/samples/client/petstore/typescript-fetch/builds/default/models/InlineObject1.ts new file mode 100644 index 000000000000..4cd90b137959 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/default/models/InlineObject1.ts @@ -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, + }; +} + + diff --git a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts index 67a45b169fde..5b07f8111862 100644 --- a/samples/client/petstore/typescript-fetch/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/default/runtime.ts @@ -14,6 +14,8 @@ 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. */ @@ -58,7 +60,9 @@ export class BaseAPI { // do not handle correctly sometimes. 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 = { method: context.method, headers: context.headers, diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/models/InlineObject.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/models/InlineObject.ts new file mode 100644 index 000000000000..2998b1463ce5 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/models/InlineObject.ts @@ -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, + }; +} + + diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/models/InlineObject1.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/models/InlineObject1.ts new file mode 100644 index 000000000000..4cd90b137959 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/models/InlineObject1.ts @@ -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, + }; +} + + diff --git a/samples/client/petstore/typescript-fetch/builds/es6-target/runtime.ts b/samples/client/petstore/typescript-fetch/builds/es6-target/runtime.ts index 67a45b169fde..5b07f8111862 100644 --- a/samples/client/petstore/typescript-fetch/builds/es6-target/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/es6-target/runtime.ts @@ -14,6 +14,8 @@ 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. */ @@ -58,7 +60,9 @@ export class BaseAPI { // do not handle correctly sometimes. 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 = { method: context.method, headers: context.headers, diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/InlineObject.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/InlineObject.ts new file mode 100644 index 000000000000..2998b1463ce5 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/InlineObject.ts @@ -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, + }; +} + + diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/InlineObject1.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/InlineObject1.ts new file mode 100644 index 000000000000..4cd90b137959 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/models/InlineObject1.ts @@ -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, + }; +} + + diff --git a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts index 67a45b169fde..5b07f8111862 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-interfaces/runtime.ts @@ -14,6 +14,8 @@ 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. */ @@ -58,7 +60,9 @@ export class BaseAPI { // do not handle correctly sometimes. 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 = { method: context.method, headers: context.headers, diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/models/InlineObject.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/models/InlineObject.ts new file mode 100644 index 000000000000..2998b1463ce5 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/models/InlineObject.ts @@ -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, + }; +} + + diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/models/InlineObject1.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/models/InlineObject1.ts new file mode 100644 index 000000000000..4cd90b137959 --- /dev/null +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/models/InlineObject1.ts @@ -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, + }; +} + + diff --git a/samples/client/petstore/typescript-fetch/builds/with-npm-version/runtime.ts b/samples/client/petstore/typescript-fetch/builds/with-npm-version/runtime.ts index 67a45b169fde..5b07f8111862 100644 --- a/samples/client/petstore/typescript-fetch/builds/with-npm-version/runtime.ts +++ b/samples/client/petstore/typescript-fetch/builds/with-npm-version/runtime.ts @@ -14,6 +14,8 @@ 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. */ @@ -58,7 +60,9 @@ export class BaseAPI { // do not handle correctly sometimes. 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 = { method: context.method, headers: context.headers,