@@ -342,7 +342,7 @@ getBodySchemaFromOperation operation = OAM.nested "requestBody" $ do
342
342
getRequestBodySchema :: OAT. RequestBodyObject -> OAM. Generator (Maybe RequestBodyDefinition , [Text ])
343
343
getRequestBodySchema body = OAM. nested " content" $ do
344
344
let contentMap = OAT. requestBodyObjectContent body
345
- content = getValueByContentTypeIgnoringCharset " application/json " contentMap
345
+ content = getJsonMediaTypeObject contentMap
346
346
createRequestBodyDefinition encoding schema =
347
347
Just $
348
348
RequestBodyDefinition
@@ -391,7 +391,7 @@ getRequestBodyObject operation =
391
391
getResponseSchema :: OAT. ResponseObject -> OAM. Generator (Maybe OAT. Schema , [Text ])
392
392
getResponseSchema response = OAM. nested " content" $ do
393
393
let contentMap = OAT. responseObjectContent response
394
- schema = getValueByContentTypeIgnoringCharset " application/json " contentMap >>= OAT. mediaTypeObjectSchema
394
+ schema = getJsonMediaTypeObject contentMap >>= OAT. mediaTypeObjectSchema
395
395
when (Maybe. isNothing schema && not (Map. null contentMap)) $ OAM. logWarning " Only content type application/json is supported for response bodies."
396
396
path <- OAM. appendToPath [" application/json" , " schema" ]
397
397
pure (schema, path)
@@ -400,10 +400,26 @@ getValueByContentTypeIgnoringCharset :: Text -> Map.Map Text OAT.MediaTypeObject
400
400
getValueByContentTypeIgnoringCharset contentType contentMap =
401
401
case Map. lookup contentType contentMap of
402
402
Just content -> Just content
403
- Nothing -> case Map. elems $ Map. filterWithKey (\ key _ -> Maybe. listToMaybe ( T. splitOn " ; " key) == Just contentType) contentMap of
403
+ Nothing -> case Map. elems $ Map. filterWithKey (\ key _ -> getMediaTypeWithoutCharset key == Just contentType) contentMap of
404
404
[] -> Nothing
405
405
content : _ -> Just content
406
406
407
+ getMediaTypeWithoutCharset :: Text -> Maybe Text
408
+ getMediaTypeWithoutCharset = Maybe. listToMaybe . T. splitOn " ;"
409
+
410
+ getJsonMediaTypeObject :: Map. Map Text OAT. MediaTypeObject -> Maybe OAT. MediaTypeObject
411
+ getJsonMediaTypeObject contentMap =
412
+ case getValueByContentTypeIgnoringCharset " application/json" contentMap of
413
+ Just content -> Just content
414
+ Nothing -> case Map. elems $ Map. filterWithKey (\ key _ -> maybe False isCustomJsonMediaType $ Maybe. listToMaybe (T. splitOn " ;" key)) contentMap of
415
+ [] -> Nothing
416
+ content : _ -> Just content
417
+
418
+ isCustomJsonMediaType :: Text -> Bool
419
+ isCustomJsonMediaType mediaType = case T. splitOn " +" mediaType of
420
+ [_, " json" ] -> True
421
+ _ -> False
422
+
407
423
-- | Resolve a possibly referenced response to a concrete value.
408
424
--
409
425
-- A warning is logged if the reference is not found.
0 commit comments