@@ -117,7 +117,7 @@ data Swagger = Swagger
117117 , _swaggerResponses :: Definitions Response
118118
119119 -- | Security scheme definitions that can be used across the specification.
120− , _swaggerSecurityDefinitions :: SecurityDefinitions
120+ , _swaggerSecurityDefinitions :: Definitions SecurityScheme
121121
122122 -- | A declaration of which security schemes are applied for the API as a whole.
123123 -- The list of values describes alternative security schemes that can be used
@@ -755,22 +755,6 @@ data SecurityScheme = SecurityScheme
755755 , _securitySchemeDescription :: Maybe Text
756756 } deriving (Eq, Show, Generic, Data, Typeable)
757757
758−
759−-- | merge scopes of two OAuth2 security schemes when their flows are identical.
760−-- In other case returns first security scheme
761−mergeSecurityScheme :: SecurityScheme -> SecurityScheme -> SecurityScheme
762−mergeSecurityScheme s1@(SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow1 scopes1)) desc)
763− s2@(SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow2 scopes2)) _)
764− = if flow1 == flow2 then
765− SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow1 (scopes1 <> scopes2))) desc
766− else
767− s1
768−mergeSecurityScheme s1 _ = s1
769−
770−newtype SecurityDefinitions
771− = SecurityDefinitions (Definitions SecurityScheme)
772− deriving (Eq, Show, Generic, Data, Typeable)
773−
774758-- | Lists the required security schemes to execute this operation.
775759-- The object can have multiple security schemes declared in it which are all required
776760-- (that is, there is a logical AND between the schemes).
@@ -920,17 +904,6 @@ instance Monoid Example where
920904 mempty = genericMempty
921905 mappend = (<>)
922906
923−instance Semigroup SecurityScheme where
924− (<>) = mergeSecurityScheme
925−
926−instance Semigroup SecurityDefinitions where
927− (SecurityDefinitions sd1) <> (SecurityDefinitions sd2) =
928− SecurityDefinitions $ InsOrdHashMap.unionWith (<>) sd1 sd2
929−
930−instance Monoid SecurityDefinitions where
931− mempty = SecurityDefinitions $ InsOrdHashMap.empty
932− mappend = (<>)
933−
934907-- =======================================================================
935908-- SwaggerMonoid helper instances
936909-- =======================================================================
@@ -945,7 +918,6 @@ instance SwaggerMonoid Responses
945918instance SwaggerMonoid Response
946919instance SwaggerMonoid ExternalDocs
947920instance SwaggerMonoid Operation
948−instance SwaggerMonoid SecurityDefinitions
949921instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
950922
951923instance SwaggerMonoid MimeList
@@ -963,6 +935,18 @@ instance OVERLAPPING_ SwaggerMonoid (InsOrdHashMap FilePath PathItem) where
963935 swaggerMempty = InsOrdHashMap.empty
964936 swaggerMappend = InsOrdHashMap.unionWith mappend
965937
938+instance OVERLAPPING_ SwaggerMonoid (InsOrdHashMap Text SecurityScheme) where
939+ swaggerMempty = InsOrdHashMap.empty
940+ swaggerMappend = InsOrdHashMap.unionWith mergeFun
941+ where
942+ mergeFun s1@(SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow1 scopes1)) desc)
943+ s2@(SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow2 scopes2)) _)
944+ = if flow1 == flow2 then
945+ SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow1 (scopes1 <> scopes2))) desc
946+ else
947+ s2
948+ mergeFun _ ss = ss
949+
966950instance Monoid a => SwaggerMonoid (Referenced a) where
967951 swaggerMempty = Inline mempty
968952 swaggerMappend (Inline x) (Inline y) = Inline (mappend x y)
@@ -1146,9 +1130,6 @@ instance ToJSON PathItem where
11461130instance ToJSON Example where
11471131 toJSON = toJSON . Map.mapKeys show . getExample
11481132
1149−instance ToJSON SecurityDefinitions where
1150− toJSON (SecurityDefinitions sd) = toJSON sd
1151−
11521133instance ToJSON Reference where
11531134 toJSON (Reference ref) = object [ "$ref" .= ref ]
11541135
@@ -1310,9 +1291,6 @@ instance FromJSON Operation where
13101291instance FromJSON PathItem where
13111292 parseJSON = sopSwaggerGenericParseJSON
13121293
1313−instance FromJSON SecurityDefinitions where
1314− parseJSON js = SecurityDefinitions <$> parseJSON js
1315−
13161294instance FromJSON Reference where
13171295 parseJSON (Object o) = Reference <$> o .: "$ref"
13181296 parseJSON _ = empty
@@ -1424,4 +1402,3 @@ instance AesonDefaultValue (SwaggerType a)
14241402instance AesonDefaultValue MimeList where defaultValue = Just mempty
14251403instance AesonDefaultValue Info
14261404instance AesonDefaultValue ParamLocation
1427−instance AesonDefaultValue SecurityDefinitions where defaultValue = Just $ SecurityDefinitions mempty