Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[typescript-fetch] support 2.x version of typescript & update samples
  • Loading branch information
mkusaka committed Apr 10, 2022
commit 1921df7bed24c21d70677feb63fe2e59a6492d26
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -183,14 +181,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
16 changes: 3 additions & 13 deletions samples/client/petstore/typescript-fetch/builds/default/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
16 changes: 3 additions & 13 deletions samples/client/petstore/typescript-fetch/builds/enum/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,11 @@ export class BaseAPI {
context
})

const createRequestBody = (body: HTTPBody) => (isFormData(body) || isURLSearchParams(body) || isBlob(body))
? body
: JSON.stringify(body);

const init: RequestInit = {
...initWithOverride,
body: createRequestBody(initWithOverride.body)
body: ((typeof FormData !== "undefined" && initWithOverride.body instanceof FormData) || initWithOverride.body instanceof URLSearchParams || isBlob(initWithOverride.body))
? initWithOverride.body
: JSON.stringify(initWithOverride.body)
}

return { url, init };
Expand Down Expand Up @@ -194,14 +192,6 @@ export class BaseAPI {
}
};

function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData
}

function isURLSearchParams(value: any): value is URLSearchParams {
return value instanceof URLSearchParams
}

function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob
}
Expand Down
Loading