@@ -1,3 +1,5 @@
1+{-# OPTIONS_GHC -fconstraint-solver-iterations=5 #-}
1{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveDataTypeable #-}
4{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE DeriveGeneric #-}
5{-# LANGUAGE DeriveGeneric #-}
@@ -39,8 +41,8 @@ import Data.Text.Encoding (encodeUtf8)
39import GHC.Generics (Generic)
41import GHC.Generics (Generic)
40import Network.HTTP.Media (MediaType, mainType, parameters, parseAccept, subType, (//),
42import Network.HTTP.Media (MediaType, mainType, parameters, parseAccept, subType, (//),
42−import Network.Socket (HostName, PortNumber)
43import Text.Read (readMaybe)
44import Text.Read (readMaybe)
45+import Test.QuickCheck.Arbitrary.Generic
45import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
47import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
46import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
48import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
@@ -774,6 +776,20 @@ data Header = Header
774 , _headerSchema :: Maybe (Referenced Schema)
776 , _headerSchema :: Maybe (Referenced Schema)
775 } deriving (Eq, Show, Generic, Data, Typeable)
777 } deriving (Eq, Show, Generic, Data, Typeable)
779+-- | According to RFC7235
791+ deriving (Eq, Show, Generic, Data, Typeable)
777-- | The location of the API key.
793-- | The location of the API key.
778data ApiKeyLocation
794data ApiKeyLocation
779 = ApiKeyQuery
795 = ApiKeyQuery
@@ -839,7 +855,7 @@ data OAuth2Flows = OAuth2Flows
839 } deriving (Eq, Show, Generic, Data, Typeable)
855 } deriving (Eq, Show, Generic, Data, Typeable)
841data SecuritySchemeType
857data SecuritySchemeType
842− = SecuritySchemeHttp
858+ = SecuritySchemeHttp HttpScheme
843 | SecuritySchemeApiKey ApiKeyParams
859 | SecuritySchemeApiKey ApiKeyParams
844 | SecuritySchemeOAuth2 OAuth2Flows
860 | SecuritySchemeOAuth2 OAuth2Flows
845 | SecuritySchemeOpenIdConnect URL
861 | SecuritySchemeOpenIdConnect URL
@@ -1127,6 +1143,13 @@ instance ToJSON License where
1127instance ToJSON ServerVariable where
1143instance ToJSON ServerVariable where
1128 toJSON = genericToJSON (jsonPrefix "ServerVariable")
1144 toJSON = genericToJSON (jsonPrefix "ServerVariable")
1146+instance ToJSON HttpScheme where
1147+ toJSON scheme = case scheme of
1148+ SCRAM_SHA_1 -> "SCRAM-SHA-1"
1149+ SCRAM_SHA_256 -> "SCRAM-SHA-256"
1151+ other -> genericToJSON defaultOptions other
1130instance ToJSON ApiKeyLocation where
1153instance ToJSON ApiKeyLocation where
1131 toJSON = genericToJSON (jsonPrefix "ApiKey")
1154 toJSON = genericToJSON (jsonPrefix "ApiKey")
@@ -1182,6 +1205,13 @@ instance FromJSON License where
1182instance FromJSON ServerVariable where
1205instance FromJSON ServerVariable where
1183 parseJSON = genericParseJSON (jsonPrefix "ServerVariable")
1206 parseJSON = genericParseJSON (jsonPrefix "ServerVariable")
1208+instance FromJSON HttpScheme where
1209+ parseJSON = withText "HttpScheme" $ \txt -> case txt of
1210+ "SCRAM-SHA-1" -> pure SCRAM_SHA_1
1211+ "SCRAM-SHA-256" -> pure SCRAM_SHA_256
1212+ "vapid" -> pure Vapid
1213+ _ -> genericParseJSON defaultOptions $ String txt
1185instance FromJSON ApiKeyLocation where
1215instance FromJSON ApiKeyLocation where
1186 parseJSON = genericParseJSON (jsonPrefix "ApiKey")
1216 parseJSON = genericParseJSON (jsonPrefix "ApiKey")
@@ -1229,8 +1259,8 @@ instance ToJSON OAuth2Flows where
1229 toEncoding = sopSwaggerGenericToEncoding
1259 toEncoding = sopSwaggerGenericToEncoding
1231instance ToJSON SecuritySchemeType where
1261instance ToJSON SecuritySchemeType where
1232− toJSON SecuritySchemeHttp
1262+ toJSON (SecuritySchemeHttp scheme)
1233− = object [ "type" .= ("http" :: Text) ]
1263+ = object [ "type" .= ("http" :: Text), "scheme" .= toJSON scheme ]
1234 toJSON (SecuritySchemeApiKey params)
1264 toJSON (SecuritySchemeApiKey params)
1235 = toJSON params
1265 = toJSON params
1236 <+> object [ "type" .= ("apiKey" :: Text) ]
1266 <+> object [ "type" .= ("apiKey" :: Text) ]
@@ -1379,7 +1409,7 @@ instance FromJSON SecuritySchemeType where
1379 parseJSON js@(Object o) = do
1409 parseJSON js@(Object o) = do
1380 (t :: Text) <- o .: "type"
1410 (t :: Text) <- o .: "type"
1381 case t of
1411 case t of
1382− "http" -> pure SecuritySchemeHttp
1412+ "http" -> SecuritySchemeHttp <$> o .: "scheme"
1383 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
1413 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
1384 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
1414 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
1385 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
1415 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
@@ -1550,3 +1580,6 @@ instance AesonDefaultValue MimeList where defaultValue = Just mempty
1550instance AesonDefaultValue Info
1580instance AesonDefaultValue Info
1551instance AesonDefaultValue ParamLocation
1581instance AesonDefaultValue ParamLocation
1552instance AesonDefaultValue Link
1582instance AesonDefaultValue Link
1584+instance Arbitrary HttpScheme where
1585+ arbitrary = genericArbitrary