Skip to content

Commit ba82979

Browse files
chore(tests): add tests and examples for blob response
1 parent 5e9d5f7 commit ba82979

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

src/templates/core/fetch/getResponseBody.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const getResponseBody = async (response: Response): Promise<any> => {
99
const isBinary = binaryTypes.some(type => contentType.toLowerCase().startsWith(type));
1010
if (isJSON) {
1111
return await response.json();
12-
} else if (isBinary) {}
12+
} else if (isBinary) {
1313
return await response.blob();
1414
} else {
1515
return await response.text();

src/templates/core/node/getResponseBody.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const getResponseBody = async (response: Response): Promise<any> => {
99
const isBinary = binaryTypes.some(type => contentType.toLowerCase().startsWith(type));
1010
if (isJSON) {
1111
return await response.json();
12-
} else if (isBinary) {}
12+
} else if (isBinary) {
1313
return await response.blob();
1414
} else {
1515
return await response.text();

test/__snapshots__/index.spec.ts.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4393,6 +4393,7 @@ export { DeprecatedService } from './services/DeprecatedService';
43934393
export { DescriptionsService } from './services/DescriptionsService';
43944394
export { DuplicateService } from './services/DuplicateService';
43954395
export { ErrorService } from './services/ErrorService';
4396+
export { FileResponseService } from './services/FileResponseService';
43964397
export { FormDataService } from './services/FormDataService';
43974398
export { HeaderService } from './services/HeaderService';
43984399
export { MultipartService } from './services/MultipartService';
@@ -7595,6 +7596,30 @@ export class ErrorService {
75957596
"
75967597
`;
75977598

7599+
exports[`v3 should generate: test/generated/v3/services/FileResponseService.ts 1`] = `
7600+
"import type { CancelablePromise } from '../core/CancelablePromise';
7601+
import { OpenAPI } from '../core/OpenAPI';
7602+
import { request as __request } from '../core/request';
7603+
7604+
export class FileResponseService {
7605+
/**
7606+
* @param id
7607+
* @returns binary Success
7608+
* @throws ApiError
7609+
*/
7610+
public static fileResponse(id: string): CancelablePromise<Blob> {
7611+
return __request(OpenAPI, {
7612+
method: 'GET',
7613+
url: '/api/v{api-version}/file/{id}',
7614+
path: {
7615+
id: id,
7616+
},
7617+
});
7618+
}
7619+
}
7620+
"
7621+
`;
7622+
75987623
exports[`v3 should generate: test/generated/v3/services/FormDataService.ts 1`] = `
75997624
"import type { ModelWithString } from '../models/ModelWithString';
76007625
import type { CancelablePromise } from '../core/CancelablePromise';

test/e2e/v3.fetch.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ describe('v3.fetch', () => {
7575
expect(result).toBeDefined();
7676
});
7777

78+
it('support blob response data', async () => {
79+
const result = await browser.evaluate(async () => {
80+
const { FileResponseService } = (window as any).api;
81+
return await FileResponseService.fileResponse('test');
82+
});
83+
expect(result).toBeDefined();
84+
});
85+
7886
it('can abort the request', async () => {
7987
let error;
8088
try {

test/e2e/v3.node.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ describe('v3.node', () => {
6262
expect(result).toBeDefined();
6363
});
6464

65+
it('support blob response data', async () => {
66+
const { FileResponseService } = require('./generated/v3/node/index.js');
67+
const result = await FileResponseService.fileResponse('test');
68+
expect(result).toBeDefined();
69+
});
70+
6571
it('can abort the request', async () => {
6672
let error;
6773
try {

test/spec/v3.json

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,49 @@
12291229
}
12301230
}
12311231
},
1232+
"/api/v{api-version}/file/{id}": {
1233+
"get": {
1234+
"tags": [
1235+
"FileResponse"
1236+
],
1237+
"operationId": "FileResponse",
1238+
"parameters": [
1239+
{
1240+
"name": "id",
1241+
"in": "path",
1242+
"required": true,
1243+
"schema": {
1244+
"type": "string"
1245+
}
1246+
},
1247+
{
1248+
"name": "api-version",
1249+
"in": "path",
1250+
"required": true,
1251+
"schema": {
1252+
"type": "string"
1253+
}
1254+
}
1255+
],
1256+
"responses": {
1257+
"200": {
1258+
"description": "Success",
1259+
"content": {
1260+
"audio/*": {
1261+
"schema": {
1262+
"type": "file"
1263+
}
1264+
},
1265+
"video/*": {
1266+
"schema": {
1267+
"type": "file"
1268+
}
1269+
}
1270+
}
1271+
}
1272+
}
1273+
}
1274+
},
12321275
"/api/v{api-version}/complex": {
12331276
"get": {
12341277
"tags": [
@@ -3135,4 +3178,4 @@
31353178
}
31363179
}
31373180
}
3138-
}
3181+
}

0 commit comments

Comments
 (0)