@@ -1,3 +1,5 @@
1+{-# OPTIONS_GHC -fconstraint-solver-iterations=5 #-}
2+
13{-# LANGUAGE DataKinds #-}
24{-# LANGUAGE DeriveDataTypeable #-}
35{-# LANGUAGE DeriveGeneric #-}
@@ -39,8 +41,8 @@ import Data.Text.Encoding (encodeUtf8)
3941import GHC.Generics (Generic)
4042import Network.HTTP.Media (MediaType, mainType, parameters, parseAccept, subType, (//),
4143 (/:))
42−import Network.Socket (HostName, PortNumber)
4344import Text.Read (readMaybe)
45+import Test.QuickCheck.Arbitrary.Generic
4446
4547import Data.HashMap.Strict.InsOrd (InsOrdHashMap)
4648import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
@@ -774,6 +776,20 @@ data Header = Header
774776 , _headerSchema :: Maybe (Referenced Schema)
775777 } deriving (Eq, Show, Generic, Data, Typeable)
776778
779+-- | According to RFC7235
780+data HttpScheme
781+ = Basic
782+ | Bearer
783+ | Digest
784+ | HOBA
785+ | Mutual
786+ | Negotiate
787+ | OAuth
788+ | SCRAM_SHA_1
789+ | SCRAM_SHA_256
790+ | Vapid
791+ deriving (Eq, Show, Generic, Data, Typeable)
792+
777793-- | The location of the API key.
778794data ApiKeyLocation
779795 = ApiKeyQuery
@@ -839,7 +855,7 @@ data OAuth2Flows = OAuth2Flows
839855 } deriving (Eq, Show, Generic, Data, Typeable)
840856
841857data SecuritySchemeType
842− = SecuritySchemeHttp
858+ = SecuritySchemeHttp HttpScheme
843859 | SecuritySchemeApiKey ApiKeyParams
844860 | SecuritySchemeOAuth2 OAuth2Flows
845861 | SecuritySchemeOpenIdConnect URL
@@ -1127,6 +1143,13 @@ instance ToJSON License where
11271143instance ToJSON ServerVariable where
11281144 toJSON = genericToJSON (jsonPrefix "ServerVariable")
11291145
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"
1150+ Vapid -> "vapid"
1151+ other -> genericToJSON defaultOptions other
1152+
11301153instance ToJSON ApiKeyLocation where
11311154 toJSON = genericToJSON (jsonPrefix "ApiKey")
11321155
@@ -1182,6 +1205,13 @@ instance FromJSON License where
11821205instance FromJSON ServerVariable where
11831206 parseJSON = genericParseJSON (jsonPrefix "ServerVariable")
11841207
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
1214+
11851215instance FromJSON ApiKeyLocation where
11861216 parseJSON = genericParseJSON (jsonPrefix "ApiKey")
11871217
@@ -1229,8 +1259,8 @@ instance ToJSON OAuth2Flows where
12291259 toEncoding = sopSwaggerGenericToEncoding
12301260
12311261instance ToJSON SecuritySchemeType where
1232− toJSON SecuritySchemeHttp
1233− = object [ "type" .= ("http" :: Text) ]
1262+ toJSON (SecuritySchemeHttp scheme)
1263+ = object [ "type" .= ("http" :: Text), "scheme" .= toJSON scheme ]
12341264 toJSON (SecuritySchemeApiKey params)
12351265 = toJSON params
12361266 <+> object [ "type" .= ("apiKey" :: Text) ]
@@ -1379,7 +1409,7 @@ instance FromJSON SecuritySchemeType where
13791409 parseJSON js@(Object o) = do
13801410 (t :: Text) <- o .: "type"
13811411 case t of
1382− "http" -> pure SecuritySchemeHttp
1412+ "http" -> SecuritySchemeHttp <$> o .: "scheme"
13831413 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
13841414 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
13851415 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
@@ -1550,3 +1580,6 @@ instance AesonDefaultValue MimeList where defaultValue = Just mempty
15501580instance AesonDefaultValue Info
15511581instance AesonDefaultValue ParamLocation
15521582instance AesonDefaultValue Link
1583+
1584+instance Arbitrary HttpScheme where
1585+ arbitrary = genericArbitrary