@@ -9,21 +9,13 @@ import {
9
9
SerializedType ,
10
10
} from '../../common/data/serialized-type' ;
11
11
import { pipe } from 'fp-ts/lib/pipeable' ;
12
- import { getOrElse , isSome , map , chain , Option , exists } from 'fp-ts/lib/Option' ;
12
+ import { getOrElse , isSome , map , Option , fold } from 'fp-ts/lib/Option' ;
13
13
import { serializeOperationResponses } from './responses-object' ;
14
14
import { fromSerializedType } from '../../common/data/serialized-parameter' ;
15
15
import { getSerializedKindDependency , serializedDependency } from '../../common/data/serialized-dependency' ;
16
16
import { concatIf } from '../../../../utils/array' ;
17
17
import { when } from '../../../../utils/string' ;
18
- import {
19
- getJSDoc ,
20
- getKindValue ,
21
- getSafePropertyName ,
22
- getURL ,
23
- HTTPMethod ,
24
- JSON_RESPONSE_TYPE ,
25
- XHRResponseType ,
26
- } from '../../common/utils' ;
18
+ import { getJSDoc , getKindValue , getSafePropertyName , getURL , HTTPMethod , XHRResponseType } from '../../common/utils' ;
27
19
import { Either , isLeft , left , right } from 'fp-ts/lib/Either' ;
28
20
import { array , either , nonEmptyArray , option , record } from 'fp-ts' ;
29
21
import { combineEither } from '@devexperts/utils/dist/adt/either.utils' ;
@@ -61,9 +53,6 @@ import {
61
53
} from '../../common/data/serialized-fragment' ;
62
54
import { sequenceOptionEither } from '../../../../utils/option' ;
63
55
import { identity } from 'fp-ts/lib/function' ;
64
- import { lookup } from 'fp-ts/lib/Record' ;
65
- import { PrimitiveSchemaObjectCodec } from '../../../../schema/2.0/schema-object' ;
66
- import { ResponseObject } from '../../../../schema/2.0/response-object' ;
67
56
68
57
interface Parameters {
69
58
readonly pathParameters : PathParameterObject [ ] ;
@@ -264,29 +253,24 @@ export const serializeOperationObject = combineReader(
264
253
) ;
265
254
266
255
const responseType : XHRResponseType = pipe (
267
- lookup ( '200' , operation . responses ) ,
268
- chain ( response => e . deepLookup ( response , ResponseObject , ReferenceObjectCodec ) ) ,
269
- chain ( response => response . schema ) ,
270
- chain ( schema => e . deepLookup ( schema , PrimitiveSchemaObjectCodec , ReferenceObjectCodec ) ) ,
271
- map ( schema => {
272
- const isBinary = pipe (
273
- schema . format ,
274
- exists ( format => format === 'binary' ) ,
275
- ) ;
276
-
277
- if ( schema . type === 'string' && isBinary ) {
278
- return 'blob' ;
279
- }
280
-
281
- if ( schema . type === 'string' ) {
282
- return 'text' ;
283
- }
284
-
285
- return 'json' ;
286
- } ) ,
287
- getOrElse ( ( ) => JSON_RESPONSE_TYPE ) ,
256
+ operation . produces ,
257
+ fold (
258
+ ( ) => 'json' ,
259
+ produces => {
260
+ console . log ( produces ) ;
261
+ if ( produces . includes ( 'application/octet-stream' ) ) {
262
+ return 'blob' ;
263
+ }
264
+ if ( produces . includes ( 'text/plain' ) ) {
265
+ return 'text' ;
266
+ }
267
+ return 'json' ;
268
+ } ,
269
+ ) ,
288
270
) ;
289
271
272
+ console . log ( responseType , operation . produces ) ;
273
+
290
274
return combineEither (
291
275
parameters ,
292
276
serializedResponses ,
0 commit comments