Skip to content

Commit

Permalink
Monoid instance for merging OAuth2 scopes
Browse files Browse the repository at this point in the history
Only merge scopes when OAuth2Flow are same
  • Loading branch information
taojang committed Apr 23, 2018
1 parent c8ccdd7 commit 4f9d4e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ cabal.sandbox.config
*.prof
*.aux
*.hp
.stack-work/
.stack-work/
12 changes: 12 additions & 0 deletions src/Data/Swagger/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,18 @@ instance OVERLAPPING_ SwaggerMonoid (InsOrdHashMap FilePath PathItem) where
swaggerMempty = InsOrdHashMap.empty
swaggerMappend = InsOrdHashMap.unionWith mappend

instance OVERLAPPING_ SwaggerMonoid (InsOrdHashMap Text SecurityScheme) where
swaggerMempty = InsOrdHashMap.empty
swaggerMappend = InsOrdHashMap.unionWith mergeFun
where
mergeFun s1@(SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow1 scopes1)) desc)
s2@(SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow2 scopes2)) _)
= if flow1 == flow2 then
SecurityScheme (SecuritySchemeOAuth2 (OAuth2Params flow1 (scopes1 <> scopes2))) desc
else
s2
mergeFun _ ss = ss

instance Monoid a => SwaggerMonoid (Referenced a) where
swaggerMempty = Inline mempty
swaggerMappend (Inline x) (Inline y) = Inline (mappend x y)
Expand Down

0 comments on commit 4f9d4e9

Please sign in to comment.