-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge OAuth2 scopes #151
Merged
Merged
Merge OAuth2 scopes #151
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -117,7 +117,7 @@ data Swagger = Swagger | |||||
, _swaggerResponses :: Definitions Response | ||||||
|
||||||
-- | Security scheme definitions that can be used across the specification. | ||||||
, _swaggerSecurityDefinitions :: Definitions SecurityScheme | ||||||
, _swaggerSecurityDefinitions :: SecurityDefinitions | ||||||
|
||||||
-- | A declaration of which security schemes are applied for the API as a whole. | ||||||
-- The list of values describes alternative security schemes that can be used | ||||||
|
@@ -755,6 +755,22 @@ data SecurityScheme = SecurityScheme | |||||
, _securitySchemeDescription :: Maybe Text | ||||||
} deriving (Eq, Show, Generic, Data, Typeable) | ||||||
|
||||||
|
||||||
-- | merge scopes of two OAuth2 security schemes when their flows are identical. | ||||||
-- In other case returns first security scheme | ||||||
mergeSecurityScheme :: SecurityScheme -> SecurityScheme -> SecurityScheme | ||||||
mergeSecurityScheme 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 | ||||||
s1 | ||||||
mergeSecurityScheme s1 _ = s1 | ||||||
|
||||||
newtype SecurityDefinitions | ||||||
= SecurityDefinitions (Definitions SecurityScheme) | ||||||
deriving (Eq, Show, Generic, Data, Typeable) | ||||||
|
||||||
-- | Lists the required security schemes to execute this operation. | ||||||
-- The object can have multiple security schemes declared in it which are all required | ||||||
-- (that is, there is a logical AND between the schemes). | ||||||
|
@@ -904,6 +920,17 @@ instance Monoid Example where | |||||
mempty = genericMempty | ||||||
mappend = (<>) | ||||||
|
||||||
instance Semigroup SecurityScheme where | ||||||
(<>) = mergeSecurityScheme | ||||||
|
||||||
instance Semigroup SecurityDefinitions where | ||||||
(SecurityDefinitions sd1) <> (SecurityDefinitions sd2) = | ||||||
SecurityDefinitions $ InsOrdHashMap.unionWith (<>) sd1 sd2 | ||||||
|
||||||
instance Monoid SecurityDefinitions where | ||||||
mempty = SecurityDefinitions $ InsOrdHashMap.empty | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
mappend = (<>) | ||||||
|
||||||
-- ======================================================================= | ||||||
-- SwaggerMonoid helper instances | ||||||
-- ======================================================================= | ||||||
|
@@ -918,6 +945,7 @@ instance SwaggerMonoid Responses | |||||
instance SwaggerMonoid Response | ||||||
instance SwaggerMonoid ExternalDocs | ||||||
instance SwaggerMonoid Operation | ||||||
instance SwaggerMonoid SecurityDefinitions | ||||||
instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a) | ||||||
|
||||||
instance SwaggerMonoid MimeList | ||||||
|
@@ -1118,6 +1146,9 @@ instance ToJSON PathItem where | |||||
instance ToJSON Example where | ||||||
toJSON = toJSON . Map.mapKeys show . getExample | ||||||
|
||||||
instance ToJSON SecurityDefinitions where | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can derive these with |
||||||
toJSON (SecurityDefinitions sd) = toJSON sd | ||||||
|
||||||
instance ToJSON Reference where | ||||||
toJSON (Reference ref) = object [ "$ref" .= ref ] | ||||||
|
||||||
|
@@ -1279,6 +1310,9 @@ instance FromJSON Operation where | |||||
instance FromJSON PathItem where | ||||||
parseJSON = sopSwaggerGenericParseJSON | ||||||
|
||||||
instance FromJSON SecurityDefinitions where | ||||||
parseJSON js = SecurityDefinitions <$> parseJSON js | ||||||
|
||||||
instance FromJSON Reference where | ||||||
parseJSON (Object o) = Reference <$> o .: "$ref" | ||||||
parseJSON _ = empty | ||||||
|
@@ -1390,3 +1424,4 @@ instance AesonDefaultValue (SwaggerType a) | |||||
instance AesonDefaultValue MimeList where defaultValue = Just mempty | ||||||
instance AesonDefaultValue Info | ||||||
instance AesonDefaultValue ParamLocation | ||||||
instance AesonDefaultValue SecurityDefinitions where defaultValue = Just $ SecurityDefinitions mempty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Shouldn't there be an
instance Semigroup InsOrdHashMap
? Same forMonoid
?)