@@ -50,7 +50,7 @@ import Text.Read (readMaybe)
5050import Data.HashMap.Strict.InsOrd (InsOrdHashMap )
5151import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
5252
53- import Data.OpenApi.Aeson.Compat (deleteKey )
53+ import Data.OpenApi.Aeson.Compat (deleteKey , filterKeys , keyToText , objectToList )
5454import Data.OpenApi.Internal.AesonUtils (AesonDefaultValue (.. ), HasSwaggerAesonOptions (.. ),
5555 mkSwaggerAesonOptions , saoAdditionalPairs , saoSubObject ,
5656 sopSwaggerGenericParseJSON , sopSwaggerGenericToEncoding ,
@@ -649,7 +649,7 @@ data ParamLocation
649649 | ParamCookie
650650 deriving (Eq , Ord , Show , Generic , Data , Typeable )
651651
652- instance Hashable ParamLocation
652+ instance Hashable ParamLocation
653653
654654type Format = Text
655655
@@ -1018,7 +1018,7 @@ data Referenced a
10181018instance IsString a => IsString (Referenced a ) where
10191019 fromString = Inline . fromString
10201020
1021- newtype URL = URL { getUrl :: Text }
1021+ newtype URL = URL { getUrl :: Text }
10221022 deriving (Eq , Ord , Show , Hashable , ToJSON , FromJSON , Data , Typeable , AesonDefaultValue )
10231023
10241024data AdditionalProperties
@@ -1555,19 +1555,19 @@ instance FromJSON Param where
15551555 parseJSON = sopSwaggerGenericParseJSON
15561556
15571557instance FromJSON Responses where
1558- parseJSON (Object o) = Responses
1559- <$> o .:? " default"
1560- <*> parseJSON
1561- ( Object
1562- ( HashMap. filterWithKey ( \ k _ -> not $ isExt k)
1563- $ HashMap. delete " default" o
1564- )
1565- )
1566- <*> case HashMap. filterWithKey ( \ k _ -> isExt k ) o of
1567- exts
1568- | HashMap. null exts -> pure (SpecificationExtensions mempty )
1569- | otherwise -> parseJSON (Object exts)
1570-
1558+ parseJSON (Object o) = Responses
1559+ <$> o .:? " default"
1560+ <*> parseJSON
1561+ ( Object
1562+ ( filterKeys ( not . isExt . keyToText) $
1563+ deleteKey " default" o
1564+ )
1565+ )
1566+ <*> case filterKeys ( isExt . keyToText ) o of
1567+ exts
1568+ | null exts -> pure (SpecificationExtensions mempty )
1569+ | otherwise -> parseJSON (Object exts)
1570+
15711571 parseJSON _ = empty
15721572
15731573isExt :: Text -> Bool
@@ -1642,7 +1642,7 @@ instance FromJSON SpecificationExtensions where
16421642 parseJSON = withObject " SpecificationExtensions" extFieldsParser
16431643 where
16441644 extFieldsParser = pure . SpecificationExtensions . InsOrdHashMap. fromList . catMaybes . filterExtFields
1645- filterExtFields = fmap (\ (k, v) -> (, v) <$> Text. stripPrefix " x-" k) . HashMap. toList
1645+ filterExtFields = fmap (\ (k, v) -> (, v) <$> Text. stripPrefix " x-" (keyToText k)) . objectToList
16461646
16471647
16481648instance FromJSON Info where
@@ -1695,7 +1695,7 @@ instance HasSwaggerAesonOptions SecurityScheme where
16951695instance HasSwaggerAesonOptions Schema where
16961696 swaggerAesonOptions _ = mkSwaggerAesonOptions " schema" & saoSubObject .~ [" paramSchema" , " extensions" ]
16971697instance HasSwaggerAesonOptions OpenApi where
1698- swaggerAesonOptions _ = mkSwaggerAesonOptions " swagger" & saoAdditionalPairs .~ [(" openapi" , " 3.0.0" )]
1698+ swaggerAesonOptions _ = mkSwaggerAesonOptions " swagger" & saoAdditionalPairs .~ [(" openapi" , " 3.0.0" )]
16991699 & saoSubObject .~ [" extensions" ]
17001700instance HasSwaggerAesonOptions Example where
17011701 swaggerAesonOptions _ = mkSwaggerAesonOptions " example" & saoSubObject .~ [" extensions" ]
0 commit comments