git.iko.soy/typeable/swagger2
on ea57696 help sign in
CHANGELOG.md−13
since splitsnapshots
unifiedsplit
@@ -1,16 +1,3 @@
1−2.5
2−---
3−
4−Highlights:
5−- Add instance for `TimeOfDay` (see [#196]( https://github.com/GetShopTV/swagger2/pull/196 ));
6−- Add support for [`optics`](https://hackage.haskell.org/package/optics) (see [#200]( https://github.com/GetShopTV/swagger2/pull/200 ));
7−- Slightly better validation errors (see [#195]( https://github.com/GetShopTV/swagger2/pull/195 ));
8−
9−Fixes and minor changes:
10−- Minor cleanup (see [#194]( https://github.com/GetShopTV/swagger2/pull/194 ));
11−- Allow base-4.13 and other GHC-8.8 related stuff (see [#198]( https://github.com/GetShopTV/swagger2/pull/198 ));
12−- Fix `stack.yaml` (see [#201]( https://github.com/GetShopTV/swagger2/pull/201 ));
13−
142.4
12.4
15---
2---
16
3
src/Data/Swagger.hs+1−2
@@ -89,7 +89,6 @@ module Data.Swagger (
89 SecurityScheme(..),
89 SecurityScheme(..),
90 SecuritySchemeType(..),
90 SecuritySchemeType(..),
91 SecurityRequirement(..),
91 SecurityRequirement(..),
92− SecurityDefinitions(..),
93
92
94 -- *** API key
93 -- *** API key
95 ApiKeyParams(..),
94 ApiKeyParams(..),
@@ -280,7 +279,7 @@ import Data.Swagger.Internal
280-- >>> encode $ toSchema (Proxy :: Proxy Person)
279-- >>> encode $ toSchema (Proxy :: Proxy Person)
281-- "{\"required\":[\"name\",\"age\"],\"properties\":{\"name\":{\"type\":\"string\"},\"age\":{\"type\":\"integer\"}},\"type\":\"object\"}"
280-- "{\"required\":[\"name\",\"age\"],\"properties\":{\"name\":{\"type\":\"string\"},\"age\":{\"type\":\"integer\"}},\"type\":\"object\"}"
282--
281--
283−-- Please note that not all valid Haskell data types will have a proper swagger schema. For example while we can derive a
282+-- Please note that not all valid Haskell data types will have a proper swagger schema. For example while we can derive a
284-- schema for basic enums like
283-- schema for basic enums like
285--
284--
286-- >>> data SampleEnum = ChoiceOne | ChoiceTwo deriving Generic
285-- >>> data SampleEnum = ChoiceOne | ChoiceTwo deriving Generic
src/Data/Swagger/Internal.hs+1−36
@@ -117,7 +117,7 @@ data Swagger = Swagger
117 , _swaggerResponses :: Definitions Response
117 , _swaggerResponses :: Definitions Response
118
118
119 -- | Security scheme definitions that can be used across the specification.
119 -- | Security scheme definitions that can be used across the specification.
120− , _swaggerSecurityDefinitions :: SecurityDefinitions
120+ , _swaggerSecurityDefinitions :: Definitions SecurityScheme
121
121
122 -- | A declaration of which security schemes are applied for the API as a whole.
122 -- | A declaration of which security schemes are applied for the API as a whole.
123 -- The list of values describes alternative security schemes that can be used
123 -- The list of values describes alternative security schemes that can be used
@@ -755,22 +755,6 @@ data SecurityScheme = SecurityScheme
755 , _securitySchemeDescription :: Maybe Text
755 , _securitySchemeDescription :: Maybe Text
756 } deriving (Eq, Show, Generic, Data, Typeable)
756 } deriving (Eq, Show, Generic, Data, Typeable)
757
757
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−
774-- | Lists the required security schemes to execute this operation.
758-- | Lists the required security schemes to execute this operation.
775-- The object can have multiple security schemes declared in it which are all required
759-- The object can have multiple security schemes declared in it which are all required
776-- (that is, there is a logical AND between the schemes).
760-- (that is, there is a logical AND between the schemes).
@@ -920,17 +904,6 @@ instance Monoid Example where
920 mempty = genericMempty
904 mempty = genericMempty
921 mappend = (<>)
905 mappend = (<>)
922
906
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−
934-- =======================================================================
907-- =======================================================================
935-- SwaggerMonoid helper instances
908-- SwaggerMonoid helper instances
936-- =======================================================================
909-- =======================================================================
@@ -945,7 +918,6 @@ instance SwaggerMonoid Responses
945instance SwaggerMonoid Response
918instance SwaggerMonoid Response
946instance SwaggerMonoid ExternalDocs
919instance SwaggerMonoid ExternalDocs
947instance SwaggerMonoid Operation
920instance SwaggerMonoid Operation
948−instance SwaggerMonoid SecurityDefinitions
949instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
921instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
950
922
951instance SwaggerMonoid MimeList
923instance SwaggerMonoid MimeList
@@ -1146,9 +1118,6 @@ instance ToJSON PathItem where
1146instance ToJSON Example where
1118instance ToJSON Example where
1147 toJSON = toJSON . Map.mapKeys show . getExample
1119 toJSON = toJSON . Map.mapKeys show . getExample
1148
1120
1149−instance ToJSON SecurityDefinitions where
1150− toJSON (SecurityDefinitions sd) = toJSON sd
1151−
1152instance ToJSON Reference where
1121instance ToJSON Reference where
1153 toJSON (Reference ref) = object [ "$ref" .= ref ]
1122 toJSON (Reference ref) = object [ "$ref" .= ref ]
1154
1123
@@ -1310,9 +1279,6 @@ instance FromJSON Operation where
1310instance FromJSON PathItem where
1279instance FromJSON PathItem where
1311 parseJSON = sopSwaggerGenericParseJSON
1280 parseJSON = sopSwaggerGenericParseJSON
1312
1281
1313−instance FromJSON SecurityDefinitions where
1314− parseJSON js = SecurityDefinitions <$> parseJSON js
1315−
1316instance FromJSON Reference where
1282instance FromJSON Reference where
1317 parseJSON (Object o) = Reference <$> o .: "$ref"
1283 parseJSON (Object o) = Reference <$> o .: "$ref"
1318 parseJSON _ = empty
1284 parseJSON _ = empty
@@ -1424,4 +1390,3 @@ instance AesonDefaultValue (SwaggerType a)
1424instance AesonDefaultValue MimeList where defaultValue = Just mempty
1390instance AesonDefaultValue MimeList where defaultValue = Just mempty
1425instance AesonDefaultValue Info
1391instance AesonDefaultValue Info
1426instance AesonDefaultValue ParamLocation
1392instance AesonDefaultValue ParamLocation
1427−instance AesonDefaultValue SecurityDefinitions where defaultValue = Just $ SecurityDefinitions mempty
src/Data/Swagger/Lens.hs−6
@@ -96,12 +96,6 @@ instance At Responses where at n = responses . at n
96instance Ixed Operation where ix n = responses . ix n
96instance Ixed Operation where ix n = responses . ix n
97instance At Operation where at n = responses . at n
97instance At Operation where at n = responses . at n
98
98
99−type instance Index SecurityDefinitions = Text
100−type instance IxValue SecurityDefinitions = SecurityScheme
101−
102−instance Ixed SecurityDefinitions where ix n = (coerced :: Lens' SecurityDefinitions (Definitions SecurityScheme)). ix n
103−instance At SecurityDefinitions where at n = (coerced :: Lens' SecurityDefinitions (Definitions SecurityScheme)). at n
104−
105instance HasParamSchema NamedSchema (ParamSchema 'SwaggerKindSchema) where paramSchema = schema.paramSchema
99instance HasParamSchema NamedSchema (ParamSchema 'SwaggerKindSchema) where paramSchema = schema.paramSchema
106
100
107-- HasType instances
101-- HasType instances
swagger2.cabal+2−1
@@ -1,6 +1,7 @@
1cabal-version: >=1.10
1cabal-version: >=1.10
2name: swagger2
2name: swagger2
3−version: 2.5
3+version: 2.4
4+x-revision: 1
4
5
5synopsis: Swagger 2.0 data model
6synopsis: Swagger 2.0 data model
6category: Web, Swagger
7category: Web, Swagger
test/Data/SwaggerSpec.hs+2−43
@@ -43,7 +43,6 @@ spec = do
43 describe "Parameters Definition Object" $ paramsDefinitionExample <=> paramsDefinitionExampleJSON
43 describe "Parameters Definition Object" $ paramsDefinitionExample <=> paramsDefinitionExampleJSON
44 describe "Responses Definition Object" $ responsesDefinitionExample <=> responsesDefinitionExampleJSON
44 describe "Responses Definition Object" $ responsesDefinitionExample <=> responsesDefinitionExampleJSON
45 describe "Security Definitions Object" $ securityDefinitionsExample <=> securityDefinitionsExampleJSON
45 describe "Security Definitions Object" $ securityDefinitionsExample <=> securityDefinitionsExampleJSON
46− describe "OAuth2 Security Definitions with merged Scope" $ oAuth2SecurityDefinitionsExample <=> oAuth2SecurityDefinitionsExampleJSON
47 describe "Composition Schema Example" $ compositionSchemaExample <=> compositionSchemaExampleJSON
46 describe "Composition Schema Example" $ compositionSchemaExample <=> compositionSchemaExampleJSON
48 describe "Swagger Object" $ do
47 describe "Swagger Object" $ do
49 context "Todo Example" $ swaggerExample <=> swaggerExampleJSON
48 context "Todo Example" $ swaggerExample <=> swaggerExampleJSON
@@ -460,8 +459,8 @@ responsesDefinitionExampleJSON = [aesonQQ|
460-- Responses Definition object
459-- Responses Definition object
461-- =======================================================================
460-- =======================================================================
462
461
463−securityDefinitionsExample :: SecurityDefinitions
462+securityDefinitionsExample :: HashMap Text SecurityScheme
464−securityDefinitionsExample = SecurityDefinitions
463+securityDefinitionsExample =
465 [ ("api_key", SecurityScheme
464 [ ("api_key", SecurityScheme
466 { _securitySchemeType = SecuritySchemeApiKey (ApiKeyParams "api_key" ApiKeyHeader)
465 { _securitySchemeType = SecuritySchemeApiKey (ApiKeyParams "api_key" ApiKeyHeader)
467 , _securitySchemeDescription = Nothing })
466 , _securitySchemeDescription = Nothing })
@@ -493,46 +492,6 @@ securityDefinitionsExampleJSON = [aesonQQ|
493}
492}
494|]
493|]
495
494
496−oAuth2SecurityDefinitionsReadExample :: SecurityDefinitions
497−oAuth2SecurityDefinitionsReadExample = SecurityDefinitions
498− [ ("petstore_auth", SecurityScheme
499− { _securitySchemeType = SecuritySchemeOAuth2 (OAuth2Params
500− { _oauth2Flow = OAuth2Implicit "http://swagger.io/api/oauth/dialog"
501− , _oauth2Scopes =
502− [ ("read:pets", "read your pets") ] } )
503− , _securitySchemeDescription = Nothing })
504− ]
505−
506−oAuth2SecurityDefinitionsWriteExample :: SecurityDefinitions
507−oAuth2SecurityDefinitionsWriteExample = SecurityDefinitions
508− [ ("petstore_auth", SecurityScheme
509− { _securitySchemeType = SecuritySchemeOAuth2 (OAuth2Params
510− { _oauth2Flow = OAuth2Implicit "http://swagger.io/api/oauth/dialog"
511− , _oauth2Scopes =
512− [ ("write:pets", "modify pets in your account") ] } )
513− , _securitySchemeDescription = Nothing })
514− ]
515−
516−oAuth2SecurityDefinitionsExample :: SecurityDefinitions
517−oAuth2SecurityDefinitionsExample =
518− oAuth2SecurityDefinitionsWriteExample <>
519− oAuth2SecurityDefinitionsReadExample
520−
521−oAuth2SecurityDefinitionsExampleJSON :: Value
522−oAuth2SecurityDefinitionsExampleJSON = [aesonQQ|
523−{
524− "petstore_auth": {
525− "type": "oauth2",
526− "authorizationUrl": "http://swagger.io/api/oauth/dialog",
527− "flow": "implicit",
528− "scopes": {
529− "write:pets": "modify pets in your account",
530− "read:pets": "read your pets"
531− }
532− }
533−}
534−|]
535−
536-- =======================================================================
495-- =======================================================================
537-- Swagger object
496-- Swagger object
538-- =======================================================================
497-- =======================================================================