diff --git a/.changeset/odd-oranges-appear.md b/.changeset/odd-oranges-appear.md new file mode 100644 index 000000000..7627332a7 --- /dev/null +++ b/.changeset/odd-oranges-appear.md @@ -0,0 +1,5 @@ +--- +"@hey-api/openapi-ts": minor +--- + +Use File or Blob type for binary types diff --git a/src/templates/partials/base.hbs b/src/templates/partials/base.hbs index 5afa5801c..c6602ad80 100644 --- a/src/templates/partials/base.hbs +++ b/src/templates/partials/base.hbs @@ -1,9 +1,5 @@ {{~#equals base 'binary'~}} -{{~#equals @root.$config.client 'fetch'}}Blob{{/equals~}} -{{~#equals @root.$config.client 'xhr'}}Blob{{/equals~}} -{{~#equals @root.$config.client 'axios'}}Blob{{/equals~}} -{{~#equals @root.$config.client 'angular'}}Blob{{/equals~}} -{{~#equals @root.$config.client 'node'}}Blob{{/equals~}} +Blob | File {{~else~}} {{~#useDateType @root.$config format~}} Date diff --git a/test/__snapshots__/v2/models.ts.snap b/test/__snapshots__/v2/models.ts.snap index fbf6e0c80..9559cc862 100644 --- a/test/__snapshots__/v2/models.ts.snap +++ b/test/__snapshots__/v2/models.ts.snap @@ -54,7 +54,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob; +export type SimpleFile = Blob | File; /** * This is a simple reference @@ -313,7 +313,7 @@ export type ModelWithReference = { */ export type ModelWithArray = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; diff --git a/test/__snapshots__/v3/models.ts.snap b/test/__snapshots__/v3/models.ts.snap index 1be5f0237..5444e2211 100644 --- a/test/__snapshots__/v3/models.ts.snap +++ b/test/__snapshots__/v3/models.ts.snap @@ -54,7 +54,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob; +export type SimpleFile = Blob | File; /** * This is a simple reference @@ -367,7 +367,7 @@ export type ModelWithReference = { */ export type ModelWithArrayReadOnlyAndWriteOnly = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; @@ -376,7 +376,7 @@ export type ModelWithArrayReadOnlyAndWriteOnly = { */ export type ModelWithArray = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; diff --git a/test/__snapshots__/v3/services/FileResponseService.ts.snap b/test/__snapshots__/v3/services/FileResponseService.ts.snap index ca3412454..15f852507 100644 --- a/test/__snapshots__/v3/services/FileResponseService.ts.snap +++ b/test/__snapshots__/v3/services/FileResponseService.ts.snap @@ -11,7 +11,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public static fileResponse(data: TDataFileResponse): CancelablePromise { + public static fileResponse(data: TDataFileResponse): CancelablePromise { const { id } = data; return __request(OpenAPI, { method: 'GET', diff --git a/test/__snapshots__/v3/services/MultipartService.ts.snap b/test/__snapshots__/v3/services/MultipartService.ts.snap index 7fe7862c5..be7e46083 100644 --- a/test/__snapshots__/v3/services/MultipartService.ts.snap +++ b/test/__snapshots__/v3/services/MultipartService.ts.snap @@ -5,7 +5,7 @@ import { request as __request } from '../core/request'; export type TDataMultipartRequest = { formData?: { - content?: Blob; + content?: Blob | File; data?: ModelWithString | null; }; }; @@ -29,7 +29,7 @@ export class MultipartService { * @throws ApiError */ public static multipartResponse(): CancelablePromise<{ - file?: Blob; + file?: Blob | File; metadata?: { foo?: string; bar?: string; diff --git a/test/__snapshots__/v3/services/UploadService.ts.snap b/test/__snapshots__/v3/services/UploadService.ts.snap index f6da46b23..22847f40c 100644 --- a/test/__snapshots__/v3/services/UploadService.ts.snap +++ b/test/__snapshots__/v3/services/UploadService.ts.snap @@ -6,7 +6,7 @@ export type TDataUploadFile = { /** * Supply a file reference for upload */ - file: Blob; + file: Blob | File; }; export class UploadService { diff --git a/test/__snapshots__/v3_angular/models.ts.snap b/test/__snapshots__/v3_angular/models.ts.snap index 14e52e1c7..ad411322f 100644 --- a/test/__snapshots__/v3_angular/models.ts.snap +++ b/test/__snapshots__/v3_angular/models.ts.snap @@ -54,7 +54,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob; +export type SimpleFile = Blob | File; /** * This is a simple reference @@ -297,7 +297,7 @@ export type ModelWithReference = { */ export type ModelWithArrayReadOnlyAndWriteOnly = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; @@ -306,7 +306,7 @@ export type ModelWithArrayReadOnlyAndWriteOnly = { */ export type ModelWithArray = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; diff --git a/test/__snapshots__/v3_angular/services/FileResponseService.ts.snap b/test/__snapshots__/v3_angular/services/FileResponseService.ts.snap index c068d26f1..477a57612 100644 --- a/test/__snapshots__/v3_angular/services/FileResponseService.ts.snap +++ b/test/__snapshots__/v3_angular/services/FileResponseService.ts.snap @@ -19,7 +19,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public fileResponse(data: TDataFileResponse): Observable { + public fileResponse(data: TDataFileResponse): Observable { const { id } = data; return __request(OpenAPI, this.http, { method: 'GET', diff --git a/test/__snapshots__/v3_angular/services/MultipartService.ts.snap b/test/__snapshots__/v3_angular/services/MultipartService.ts.snap index ec18241ff..6fc5e3a1e 100644 --- a/test/__snapshots__/v3_angular/services/MultipartService.ts.snap +++ b/test/__snapshots__/v3_angular/services/MultipartService.ts.snap @@ -7,7 +7,7 @@ import { request as __request } from '../core/request'; export type TDataMultipartRequest = { formData?: { - content?: Blob; + content?: Blob | File; data?: ModelWithString | null; }; }; @@ -36,7 +36,7 @@ export class MultipartService { * @throws ApiError */ public multipartResponse(): Observable<{ - file?: Blob; + file?: Blob | File; metadata?: { foo?: string; bar?: string; diff --git a/test/__snapshots__/v3_angular/services/UploadService.ts.snap b/test/__snapshots__/v3_angular/services/UploadService.ts.snap index aa86ccb9e..6bdb2979e 100644 --- a/test/__snapshots__/v3_angular/services/UploadService.ts.snap +++ b/test/__snapshots__/v3_angular/services/UploadService.ts.snap @@ -9,7 +9,7 @@ export type TDataUploadFile = { /** * Supply a file reference for upload */ - file: Blob; + file: Blob | File; }; @Injectable({ diff --git a/test/__snapshots__/v3_client/models.ts.snap b/test/__snapshots__/v3_client/models.ts.snap index 7cf430378..e9246c715 100644 --- a/test/__snapshots__/v3_client/models.ts.snap +++ b/test/__snapshots__/v3_client/models.ts.snap @@ -54,7 +54,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob; +export type SimpleFile = Blob | File; /** * This is a simple reference @@ -367,7 +367,7 @@ export type ModelWithReference = { */ export type ModelWithArrayReadOnlyAndWriteOnly = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; @@ -376,7 +376,7 @@ export type ModelWithArrayReadOnlyAndWriteOnly = { */ export type ModelWithArray = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; diff --git a/test/__snapshots__/v3_client/services/FileResponseService.ts.snap b/test/__snapshots__/v3_client/services/FileResponseService.ts.snap index 1ae60f65e..896c7509a 100644 --- a/test/__snapshots__/v3_client/services/FileResponseService.ts.snap +++ b/test/__snapshots__/v3_client/services/FileResponseService.ts.snap @@ -12,7 +12,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public fileResponse(data: TDataFileResponse): CancelablePromise { + public fileResponse(data: TDataFileResponse): CancelablePromise { const { id } = data; return this.httpRequest.request({ method: 'GET', diff --git a/test/__snapshots__/v3_client/services/MultipartService.ts.snap b/test/__snapshots__/v3_client/services/MultipartService.ts.snap index b149f0acb..afbf9e165 100644 --- a/test/__snapshots__/v3_client/services/MultipartService.ts.snap +++ b/test/__snapshots__/v3_client/services/MultipartService.ts.snap @@ -4,7 +4,7 @@ import type { BaseHttpRequest } from '../core/BaseHttpRequest'; export type TDataMultipartRequest = { formData?: { - content?: Blob; + content?: Blob | File; data?: ModelWithString | null; }; }; @@ -30,7 +30,7 @@ export class MultipartService { * @throws ApiError */ public multipartResponse(): CancelablePromise<{ - file?: Blob; + file?: Blob | File; metadata?: { foo?: string; bar?: string; diff --git a/test/__snapshots__/v3_client/services/UploadService.ts.snap b/test/__snapshots__/v3_client/services/UploadService.ts.snap index 3d49884ab..6fe43caa6 100644 --- a/test/__snapshots__/v3_client/services/UploadService.ts.snap +++ b/test/__snapshots__/v3_client/services/UploadService.ts.snap @@ -5,7 +5,7 @@ export type TDataUploadFile = { /** * Supply a file reference for upload */ - file: Blob; + file: Blob | File; }; export class UploadService { diff --git a/test/__snapshots__/v3_enums_typescript/models.ts.snap b/test/__snapshots__/v3_enums_typescript/models.ts.snap index 058bb14c3..8a3a8146a 100644 --- a/test/__snapshots__/v3_enums_typescript/models.ts.snap +++ b/test/__snapshots__/v3_enums_typescript/models.ts.snap @@ -54,7 +54,7 @@ export type NonAsciiStringæøåÆØÅöôêÊ字符串 = string; /** * This is a simple file */ -export type SimpleFile = Blob; +export type SimpleFile = Blob | File; /** * This is a simple reference @@ -333,7 +333,7 @@ export type ModelWithReference = { */ export type ModelWithArrayReadOnlyAndWriteOnly = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; @@ -342,7 +342,7 @@ export type ModelWithArrayReadOnlyAndWriteOnly = { */ export type ModelWithArray = { prop?: Array; - propWithFile?: Array; + propWithFile?: Array; propWithNumber?: Array; }; diff --git a/test/__snapshots__/v3_enums_typescript/services/FileResponseService.ts.snap b/test/__snapshots__/v3_enums_typescript/services/FileResponseService.ts.snap index ca3412454..15f852507 100644 --- a/test/__snapshots__/v3_enums_typescript/services/FileResponseService.ts.snap +++ b/test/__snapshots__/v3_enums_typescript/services/FileResponseService.ts.snap @@ -11,7 +11,7 @@ export class FileResponseService { * @returns binary Success * @throws ApiError */ - public static fileResponse(data: TDataFileResponse): CancelablePromise { + public static fileResponse(data: TDataFileResponse): CancelablePromise { const { id } = data; return __request(OpenAPI, { method: 'GET', diff --git a/test/__snapshots__/v3_enums_typescript/services/MultipartService.ts.snap b/test/__snapshots__/v3_enums_typescript/services/MultipartService.ts.snap index 7fe7862c5..be7e46083 100644 --- a/test/__snapshots__/v3_enums_typescript/services/MultipartService.ts.snap +++ b/test/__snapshots__/v3_enums_typescript/services/MultipartService.ts.snap @@ -5,7 +5,7 @@ import { request as __request } from '../core/request'; export type TDataMultipartRequest = { formData?: { - content?: Blob; + content?: Blob | File; data?: ModelWithString | null; }; }; @@ -29,7 +29,7 @@ export class MultipartService { * @throws ApiError */ public static multipartResponse(): CancelablePromise<{ - file?: Blob; + file?: Blob | File; metadata?: { foo?: string; bar?: string; diff --git a/test/__snapshots__/v3_enums_typescript/services/UploadService.ts.snap b/test/__snapshots__/v3_enums_typescript/services/UploadService.ts.snap index f6da46b23..22847f40c 100644 --- a/test/__snapshots__/v3_enums_typescript/services/UploadService.ts.snap +++ b/test/__snapshots__/v3_enums_typescript/services/UploadService.ts.snap @@ -6,7 +6,7 @@ export type TDataUploadFile = { /** * Supply a file reference for upload */ - file: Blob; + file: Blob | File; }; export class UploadService {