Skip to content

Commit 8925f81

Browse files
zeriongjypark
andauthored
fix(core): detect isBlob from content type instead of resolved type name (#3182)
Previously isBlob used success === 'Blob' which failed when the resolved type was a union (e.g. 'Blob | OtherType'). Now uses isBinaryContentType() against each success response's content type, making blob detection reliable for Angular Query and other clients. Closes #3075 Signed-off-by: jypark <jypark@elonsoft.co.kr> Co-authored-by: jypark <jypark@elonsoft.co.kr>
1 parent b954d56 commit 8925f81

2 files changed

Lines changed: 102 additions & 2 deletions

File tree

packages/core/src/getters/response.test.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,100 @@ describe('getResponse', () => {
129129
// (responses parameter is typed as non-optional OpenApiResponsesObject)
130130
});
131131

132+
describe('isBlob detection', () => {
133+
it('should set isBlob to true for application/octet-stream response', () => {
134+
const responses: OpenApiResponsesObject = {
135+
'200': {
136+
description: 'Binary file',
137+
content: {
138+
'application/octet-stream': {
139+
schema: { type: 'string', format: 'binary' },
140+
},
141+
},
142+
},
143+
};
144+
145+
const result = getResponse({
146+
responses,
147+
operationName: 'downloadFile',
148+
context,
149+
});
150+
151+
expect(result.isBlob).toBe(true);
152+
});
153+
154+
it('should set isBlob to true when success has both json and octet-stream responses', () => {
155+
const responses: OpenApiResponsesObject = {
156+
'200': {
157+
description: 'Binary file',
158+
content: {
159+
'application/octet-stream': {
160+
schema: { type: 'string', format: 'binary' },
161+
},
162+
},
163+
},
164+
'400': {
165+
description: 'Error',
166+
content: {
167+
'application/json': {
168+
schema: { $ref: '#/components/schemas/Error' },
169+
},
170+
},
171+
},
172+
};
173+
174+
const result = getResponse({
175+
responses,
176+
operationName: 'downloadFileWithError',
177+
context,
178+
});
179+
180+
expect(result.isBlob).toBe(true);
181+
});
182+
183+
it('should set isBlob to false for application/json response', () => {
184+
const responses: OpenApiResponsesObject = {
185+
'200': {
186+
description: 'JSON response',
187+
content: {
188+
'application/json': {
189+
schema: { $ref: '#/components/schemas/Pet' },
190+
},
191+
},
192+
},
193+
};
194+
195+
const result = getResponse({
196+
responses,
197+
operationName: 'getPet',
198+
context,
199+
});
200+
201+
expect(result.isBlob).toBe(false);
202+
});
203+
204+
it('should set isBlob to true for image content type', () => {
205+
const responses: OpenApiResponsesObject = {
206+
'200': {
207+
description: 'Image file',
208+
content: {
209+
'image/png': {
210+
schema: { type: 'string', format: 'binary' },
211+
},
212+
},
213+
},
214+
};
215+
216+
const result = getResponse({
217+
responses,
218+
operationName: 'getImage',
219+
context,
220+
});
221+
222+
expect(result.isBlob).toBe(true);
223+
});
224+
});
225+
132226
describe('duplicate union types', () => {
133227
it('should dedupe success types when multiple status codes reference the same schema', () => {
134228
const responses: OpenApiResponsesObject = {

packages/core/src/getters/response.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import type {
55
OverrideOutputContentType,
66
ResReqTypesValue,
77
} from '../types';
8-
import { dedupeUnionType, filterByContentType } from '../utils';
8+
import {
9+
dedupeUnionType,
10+
filterByContentType,
11+
isBinaryContentType,
12+
} from '../utils';
913
import { getResReqTypes } from './res-req-types';
1014

1115
interface GetResponseOptions {
@@ -67,7 +71,9 @@ export function getResponse({
6771
success: success || (defaultType ?? 'unknown'),
6872
errors: errors || (defaultType ?? 'unknown'),
6973
},
70-
isBlob: success === 'Blob',
74+
isBlob: groupedByStatus.success.some(
75+
(t) => !!t.contentType && isBinaryContentType(t.contentType),
76+
),
7177
types: groupedByStatus,
7278
contentTypes,
7379
schemas,

0 commit comments

Comments
 (0)