5
5
getTypeName ,
6
6
getURL ,
7
7
HTTPMethod ,
8
- JSON_RESPONSE_TYPE ,
9
8
XHRResponseType ,
10
9
} from '../../common/utils' ;
11
10
import {
@@ -43,7 +42,7 @@ import { ResolveRefContext, fromString, getRelativePath, Ref } from '../../../..
43
42
import { OperationObject } from '../../../../schema/3.0/operation-object' ;
44
43
import { ParameterObject , ParameterObjectCodec } from '../../../../schema/3.0/parameter-object' ;
45
44
import { RequestBodyObjectCodec } from '../../../../schema/3.0/request-body-object' ;
46
- import { chain , exists , getOrElse , isSome , none , Option , some , map } from 'fp-ts/lib/Option' ;
45
+ import { chain , isSome , none , Option , some , map , fromEither , fold } from 'fp-ts/lib/Option' ;
47
46
import { constFalse } from 'fp-ts/lib/function' ;
48
47
import { clientRef } from '../../common/bundled/client' ;
49
48
import { Kind } from '../../../../utils/types' ;
@@ -57,8 +56,8 @@ import {
57
56
serializedFragment ,
58
57
SerializedFragment ,
59
58
} from '../../common/data/serialized-fragment' ;
60
- import { PrimitiveSchemaObjectCodec , SchemaObjectCodec } from '../../../../schema/3.0/schema-object' ;
61
- import { lookup } from 'fp-ts/lib/Record' ;
59
+ import { SchemaObjectCodec } from '../../../../schema/3.0/schema-object' ;
60
+ import { lookup , keys } from 'fp-ts/lib/Record' ;
62
61
import { ResponseObjectCodec } from '../../../../schema/3.0/response-object' ;
63
62
64
63
const getOperationName = ( pattern : string , operation : OperationObject , method : HTTPMethod ) : string =>
@@ -261,28 +260,25 @@ export const serializeOperationObject = combineReader(
261
260
262
261
const responseType : XHRResponseType = pipe (
263
262
lookup ( '200' , operation . responses ) ,
264
- chain ( response => e . deepLookup ( response , ResponseObjectCodec , ReferenceObjectCodec ) ) ,
263
+ chain ( response =>
264
+ ReferenceObjectCodec . is ( response )
265
+ ? fromEither ( e . resolveRef ( response . $ref , ResponseObjectCodec ) )
266
+ : some ( response ) ,
267
+ ) ,
265
268
chain ( response => response . content ) ,
266
- chain ( content => lookup ( 'application/json' , content ) ) ,
267
- chain ( contentBody => contentBody . schema ) ,
268
- chain ( schema => e . deepLookup ( schema , PrimitiveSchemaObjectCodec , ReferenceObjectCodec ) ) ,
269
- map ( schema => {
270
- const isBinary = pipe (
271
- schema . format ,
272
- exists ( format => format === 'binary' ) ,
273
- ) ;
274
-
275
- if ( schema . type === 'string' && isBinary ) {
276
- return 'blob' ;
277
- }
278
-
279
- if ( schema . type === 'string' ) {
280
- return 'text' ;
281
- }
282
-
283
- return 'json' ;
284
- } ) ,
285
- getOrElse ( ( ) => JSON_RESPONSE_TYPE ) ,
269
+ map ( keys ) ,
270
+ fold (
271
+ ( ) => 'json' ,
272
+ types => {
273
+ if ( types . includes ( 'application/octet-stream' ) ) {
274
+ return 'blob' ;
275
+ }
276
+ if ( types . includes ( 'text/plain' ) ) {
277
+ return 'text' ;
278
+ }
279
+ return 'json' ;
280
+ } ,
281
+ ) ,
286
282
) ;
287
283
288
284
return combineEither (
0 commit comments