git.iko.soy/typeable/openapi3
on master help sign in
Include the scheme when using http security (#10)
fc1d9a6Tommy Engström
src/Data/OpenApi.hs+1
@@ -91,6 +91,7 @@ module Data.OpenApi (
91 -- ** Security
91 -- ** Security
92 SecurityScheme(..),
92 SecurityScheme(..),
93 SecuritySchemeType(..),
93 SecuritySchemeType(..),
94+ HttpSchemeType(..),
94 SecurityDefinitions(..),
95 SecurityDefinitions(..),
95 SecurityRequirement(..),
96 SecurityRequirement(..),
96
97
src/Data/OpenApi/Internal.hs+28−4
@@ -838,8 +838,16 @@ data OAuth2Flows = OAuth2Flows
838 , _oAuth2FlowsAuthorizationCode :: Maybe (OAuth2Flow OAuth2AuthorizationCodeFlow)
838 , _oAuth2FlowsAuthorizationCode :: Maybe (OAuth2Flow OAuth2AuthorizationCodeFlow)
839 } deriving (Eq, Show, Generic, Data, Typeable)
839 } deriving (Eq, Show, Generic, Data, Typeable)
840
840
841+type BearerFormat = Text
842+
843+data HttpSchemeType
844+ = HttpSchemeBearer (Maybe BearerFormat)
845+ | HttpSchemeBasic
846+ | HttpSchemeCustom Text
847+ deriving (Eq, Show, Generic, Data, Typeable)
848+
841data SecuritySchemeType
849data SecuritySchemeType
842− = SecuritySchemeHttp
850+ = SecuritySchemeHttp HttpSchemeType
843 | SecuritySchemeApiKey ApiKeyParams
851 | SecuritySchemeApiKey ApiKeyParams
844 | SecuritySchemeOAuth2 OAuth2Flows
852 | SecuritySchemeOAuth2 OAuth2Flows
845 | SecuritySchemeOpenIdConnect URL
853 | SecuritySchemeOpenIdConnect URL
@@ -1229,8 +1237,19 @@ instance ToJSON OAuth2Flows where
1229 toEncoding = sopSwaggerGenericToEncoding
1237 toEncoding = sopSwaggerGenericToEncoding
1230
1238
1231instance ToJSON SecuritySchemeType where
1239instance ToJSON SecuritySchemeType where
1232− toJSON SecuritySchemeHttp
1240+ toJSON (SecuritySchemeHttp ty) = case ty of
1241+ HttpSchemeBearer mFmt ->
1242+ object $ [ "type" .= ("http" :: Text)
1243+ , "scheme" .= ("bearer" :: Text)
1244+ ] <> maybe [] (\t -> ["bearerFormat" .= t]) mFmt
1245+ HttpSchemeBasic ->
1246+ object [ "type" .= ("http" :: Text)
1247+ , "scheme" .= ("basic" :: Text)
1248+ ]
1249+ HttpSchemeCustom t ->
1233− = object [ "type" .= ("http" :: Text) ]
1250+ object [ "type" .= ("http" :: Text)
1251+ , "scheme" .= t
1252+ ]
1234 toJSON (SecuritySchemeApiKey params)
1253 toJSON (SecuritySchemeApiKey params)
1235 = toJSON params
1254 = toJSON params
1236 <+> object [ "type" .= ("apiKey" :: Text) ]
1255 <+> object [ "type" .= ("apiKey" :: Text) ]
@@ -1379,7 +1398,12 @@ instance FromJSON SecuritySchemeType where
1379 parseJSON js@(Object o) = do
1398 parseJSON js@(Object o) = do
1380 (t :: Text) <- o .: "type"
1399 (t :: Text) <- o .: "type"
1381 case t of
1400 case t of
1401+ "http" -> do
1402+ scheme <- o .: "scheme"
1382− "http" -> pure SecuritySchemeHttp
1403+ SecuritySchemeHttp <$> case scheme of
1404+ "bearer" -> HttpSchemeBearer <$> (o .:! "bearerFormat")
1405+ "basic" -> pure HttpSchemeBasic
1406+ t -> pure $ HttpSchemeCustom t
1383 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
1407 "apiKey" -> SecuritySchemeApiKey <$> parseJSON js
1384 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
1408 "oauth2" -> SecuritySchemeOAuth2 <$> (o .: "flows")
1385 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")
1409 "openIdConnect" -> SecuritySchemeOpenIdConnect <$> (o .: "openIdConnectUrl")