Skip to content

Commit

Permalink
feat(client): use File or Blob for binary types
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Mar 30, 2024
1 parent 7b66dfa commit 1f8f651
Show file tree
Hide file tree
Showing 19 changed files with 36 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-oranges-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": minor
---

Use File or Blob type for binary types
6 changes: 1 addition & 5 deletions src/templates/partials/base.hbs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/v2/models.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -313,7 +313,7 @@ export type ModelWithReference = {
*/
export type ModelWithArray = {
prop?: Array<ModelWithString>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/v3/models.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -367,7 +367,7 @@ export type ModelWithReference = {
*/
export type ModelWithArrayReadOnlyAndWriteOnly = {
prop?: Array<ModelWithReadOnlyAndWriteOnly>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand All @@ -376,7 +376,7 @@ export type ModelWithArrayReadOnlyAndWriteOnly = {
*/
export type ModelWithArray = {
prop?: Array<ModelWithString>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/v3/services/FileResponseService.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class FileResponseService {
* @returns binary Success
* @throws ApiError
*/
public static fileResponse(data: TDataFileResponse): CancelablePromise<Blob> {
public static fileResponse(data: TDataFileResponse): CancelablePromise<Blob | File> {
const { id } = data;
return __request(OpenAPI, {
method: 'GET',
Expand Down
4 changes: 2 additions & 2 deletions test/__snapshots__/v3/services/MultipartService.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { request as __request } from '../core/request';

export type TDataMultipartRequest = {
formData?: {
content?: Blob;
content?: Blob | File;
data?: ModelWithString | null;
};
};
Expand All @@ -29,7 +29,7 @@ export class MultipartService {
* @throws ApiError
*/
public static multipartResponse(): CancelablePromise<{
file?: Blob;
file?: Blob | File;
metadata?: {
foo?: string;
bar?: string;
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/v3/services/UploadService.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type TDataUploadFile = {
/**
* Supply a file reference for upload
*/
file: Blob;
file: Blob | File;
};

export class UploadService {
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/v3_angular/models.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -297,7 +297,7 @@ export type ModelWithReference = {
*/
export type ModelWithArrayReadOnlyAndWriteOnly = {
prop?: Array<ModelWithReadOnlyAndWriteOnly>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand All @@ -306,7 +306,7 @@ export type ModelWithArrayReadOnlyAndWriteOnly = {
*/
export type ModelWithArray = {
prop?: Array<ModelWithString>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class FileResponseService {
* @returns binary Success
* @throws ApiError
*/
public fileResponse(data: TDataFileResponse): Observable<Blob> {
public fileResponse(data: TDataFileResponse): Observable<Blob | File> {
const { id } = data;
return __request(OpenAPI, this.http, {
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { request as __request } from '../core/request';

export type TDataMultipartRequest = {
formData?: {
content?: Blob;
content?: Blob | File;
data?: ModelWithString | null;
};
};
Expand Down Expand Up @@ -36,7 +36,7 @@ export class MultipartService {
* @throws ApiError
*/
public multipartResponse(): Observable<{
file?: Blob;
file?: Blob | File;
metadata?: {
foo?: string;
bar?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type TDataUploadFile = {
/**
* Supply a file reference for upload
*/
file: Blob;
file: Blob | File;
};

@Injectable({
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/v3_client/models.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -367,7 +367,7 @@ export type ModelWithReference = {
*/
export type ModelWithArrayReadOnlyAndWriteOnly = {
prop?: Array<ModelWithReadOnlyAndWriteOnly>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand All @@ -376,7 +376,7 @@ export type ModelWithArrayReadOnlyAndWriteOnly = {
*/
export type ModelWithArray = {
prop?: Array<ModelWithString>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class FileResponseService {
* @returns binary Success
* @throws ApiError
*/
public fileResponse(data: TDataFileResponse): CancelablePromise<Blob> {
public fileResponse(data: TDataFileResponse): CancelablePromise<Blob | File> {
const { id } = data;
return this.httpRequest.request({
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { BaseHttpRequest } from '../core/BaseHttpRequest';

export type TDataMultipartRequest = {
formData?: {
content?: Blob;
content?: Blob | File;
data?: ModelWithString | null;
};
};
Expand All @@ -30,7 +30,7 @@ export class MultipartService {
* @throws ApiError
*/
public multipartResponse(): CancelablePromise<{
file?: Blob;
file?: Blob | File;
metadata?: {
foo?: string;
bar?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type TDataUploadFile = {
/**
* Supply a file reference for upload
*/
file: Blob;
file: Blob | File;
};

export class UploadService {
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/v3_enums_typescript/models.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -333,7 +333,7 @@ export type ModelWithReference = {
*/
export type ModelWithArrayReadOnlyAndWriteOnly = {
prop?: Array<ModelWithReadOnlyAndWriteOnly>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand All @@ -342,7 +342,7 @@ export type ModelWithArrayReadOnlyAndWriteOnly = {
*/
export type ModelWithArray = {
prop?: Array<ModelWithString>;
propWithFile?: Array<Blob>;
propWithFile?: Array<Blob | File>;
propWithNumber?: Array<number>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class FileResponseService {
* @returns binary Success
* @throws ApiError
*/
public static fileResponse(data: TDataFileResponse): CancelablePromise<Blob> {
public static fileResponse(data: TDataFileResponse): CancelablePromise<Blob | File> {
const { id } = data;
return __request(OpenAPI, {
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { request as __request } from '../core/request';

export type TDataMultipartRequest = {
formData?: {
content?: Blob;
content?: Blob | File;
data?: ModelWithString | null;
};
};
Expand All @@ -29,7 +29,7 @@ export class MultipartService {
* @throws ApiError
*/
public static multipartResponse(): CancelablePromise<{
file?: Blob;
file?: Blob | File;
metadata?: {
foo?: string;
bar?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type TDataUploadFile = {
/**
* Supply a file reference for upload
*/
file: Blob;
file: Blob | File;
};

export class UploadService {
Expand Down

0 comments on commit 1f8f651

Please sign in to comment.