git.iko.soy/typeable/openapi3
on master help sign in
Fix #165: Use InsOrdHashSet
ac10503Oleg Grenrus
CHANGELOG.md+11
@@ -1,3 +1,14 @@
1+2.4
2+---
3+
4+- Allow hashable-1.3, semigroups-0.19, network-3.1, time-1.9, generics-sop-0.5
5+- Tags aren't sorted
6+ (see [#165](https://github.com/GetShopTV/swagger2/issues/165))
7+- Schema type is optional
8+ (see [#138](https://github.com/GetShopTV/swagger2/issues/138), [#164](https://github.com/GetShopTV/swagger2/pull/164))
9+- Take concrete 'Proxy' as argument
10+ (see [#180](https://github.com/GetShopTV/swagger2/pull/180))
11+
12.3.1.1
122.3.1.1
2-------
13-------
3- Allow `network-3.0`
14- Allow `network-3.0`
cabal.projectnew file+2
@@ -0,0 +1,2 @@
1+packages: .
2+tests: true
src/Data/Swagger/Internal.hs+10−4
@@ -29,13 +29,14 @@ import Control.Applicative
29import Data.Aeson
29import Data.Aeson
30import qualified Data.Aeson.Types as JSON
30import qualified Data.Aeson.Types as JSON
31import Data.Data (Data(..), Typeable, mkConstr, mkDataType, Fixity(..), Constr, DataType, constrIndex)
31import Data.Data (Data(..), Typeable, mkConstr, mkDataType, Fixity(..), Constr, DataType, constrIndex)
32+import Data.Hashable (Hashable)
32import qualified Data.HashMap.Strict as HashMap
33import qualified Data.HashMap.Strict as HashMap
34+import Data.HashSet.InsOrd (InsOrdHashSet)
33import Data.Map (Map)
35import Data.Map (Map)
34import qualified Data.Map as Map
36import qualified Data.Map as Map
35import Data.Monoid (Monoid (..))
37import Data.Monoid (Monoid (..))
36import Data.Semigroup.Compat (Semigroup (..))
38import Data.Semigroup.Compat (Semigroup (..))
37import Data.Scientific (Scientific)
39import Data.Scientific (Scientific)
38−import Data.Set (Set)
39import Data.String (IsString(..))
40import Data.String (IsString(..))
40import Data.Text (Text)
41import Data.Text (Text)
41import qualified Data.Text as Text
42import qualified Data.Text as Text
@@ -129,7 +130,7 @@ data Swagger = Swagger
129 -- Not all tags that are used by the Operation Object must be declared.
130 -- Not all tags that are used by the Operation Object must be declared.
130 -- The tags that are not declared may be organized randomly or based on the tools' logic.
131 -- The tags that are not declared may be organized randomly or based on the tools' logic.
131 -- Each tag name in the list MUST be unique.
132 -- Each tag name in the list MUST be unique.
132− , _swaggerTags :: Set Tag
133+ , _swaggerTags :: InsOrdHashSet Tag
133
134
134 -- | Additional external documentation.
135 -- | Additional external documentation.
135 , _swaggerExternalDocs :: Maybe ExternalDocs
136 , _swaggerExternalDocs :: Maybe ExternalDocs
@@ -251,7 +252,7 @@ data PathItem = PathItem
251data Operation = Operation
252data Operation = Operation
252 { -- | A list of tags for API documentation control.
253 { -- | A list of tags for API documentation control.
253 -- Tags can be used for logical grouping of operations by resources or any other qualifier.
254 -- Tags can be used for logical grouping of operations by resources or any other qualifier.
254− _operationTags :: Set TagName
255+ _operationTags :: InsOrdHashSet TagName
255
256
256 -- | A short summary of what the operation does.
257 -- | A short summary of what the operation does.
257 -- For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
258 -- For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
@@ -778,6 +779,8 @@ data Tag = Tag
778 , _tagExternalDocs :: Maybe ExternalDocs
779 , _tagExternalDocs :: Maybe ExternalDocs
779 } deriving (Eq, Ord, Show, Generic, Data, Typeable)
780 } deriving (Eq, Ord, Show, Generic, Data, Typeable)
780
781
782+instance Hashable Tag
783+
781instance IsString Tag where
784instance IsString Tag where
782 fromString s = Tag (fromString s) Nothing Nothing
785 fromString s = Tag (fromString s) Nothing Nothing
783
786
@@ -791,6 +794,8 @@ data ExternalDocs = ExternalDocs
791 , _externalDocsUrl :: URL
794 , _externalDocsUrl :: URL
792 } deriving (Eq, Ord, Show, Generic, Data, Typeable)
795 } deriving (Eq, Ord, Show, Generic, Data, Typeable)
793
796
797+instance Hashable ExternalDocs
798+
794-- | A simple object to allow referencing other definitions in the specification.
799-- | A simple object to allow referencing other definitions in the specification.
795-- It can be used to reference parameters and responses that are defined at the top level for reuse.
800-- It can be used to reference parameters and responses that are defined at the top level for reuse.
796newtype Reference = Reference { getReference :: Text }
801newtype Reference = Reference { getReference :: Text }
@@ -804,7 +809,7 @@ data Referenced a
804instance IsString a => IsString (Referenced a) where
809instance IsString a => IsString (Referenced a) where
805 fromString = Inline . fromString
810 fromString = Inline . fromString
806
811
807−newtype URL = URL { getUrl :: Text } deriving (Eq, Ord, Show, ToJSON, FromJSON, Data, Typeable)
812+newtype URL = URL { getUrl :: Text } deriving (Eq, Ord, Show, Hashable, ToJSON, FromJSON, Data, Typeable)
808
813
809data AdditionalProperties
814data AdditionalProperties
810 = AdditionalPropertiesAllowed Bool
815 = AdditionalPropertiesAllowed Bool
@@ -913,6 +918,7 @@ instance SwaggerMonoid Responses
913instance SwaggerMonoid Response
918instance SwaggerMonoid Response
914instance SwaggerMonoid ExternalDocs
919instance SwaggerMonoid ExternalDocs
915instance SwaggerMonoid Operation
920instance SwaggerMonoid Operation
921+instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
916
922
917instance SwaggerMonoid MimeList
923instance SwaggerMonoid MimeList
918deriving instance SwaggerMonoid URL
924deriving instance SwaggerMonoid URL
src/Data/Swagger/Internal/AesonUtils.hs+2
@@ -44,6 +44,7 @@ import qualified Data.Text as T
44import qualified Data.HashMap.Strict as HM
44import qualified Data.HashMap.Strict as HM
45import qualified Data.Set as Set
45import qualified Data.Set as Set
46import qualified Data.HashMap.Strict.InsOrd as InsOrd
46import qualified Data.HashMap.Strict.InsOrd as InsOrd
47+import qualified Data.HashSet.InsOrd as InsOrdHS
47
48
48#if MIN_VERSION_aeson(0,10,0)
49#if MIN_VERSION_aeson(0,10,0)
49import Data.Aeson (Encoding, pairs, (.=), Series)
50import Data.Aeson (Encoding, pairs, (.=), Series)
@@ -85,6 +86,7 @@ instance AesonDefaultValue Text where defaultValue = Nothing
85instance AesonDefaultValue (Maybe a) where defaultValue = Just Nothing
86instance AesonDefaultValue (Maybe a) where defaultValue = Just Nothing
86instance AesonDefaultValue [a] where defaultValue = Just []
87instance AesonDefaultValue [a] where defaultValue = Just []
87instance AesonDefaultValue (Set.Set a) where defaultValue = Just Set.empty
88instance AesonDefaultValue (Set.Set a) where defaultValue = Just Set.empty
89+instance AesonDefaultValue (InsOrdHS.InsOrdHashSet k) where defaultValue = Just InsOrdHS.empty
88instance AesonDefaultValue (InsOrd.InsOrdHashMap k v) where defaultValue = Just InsOrd.empty
90instance AesonDefaultValue (InsOrd.InsOrdHashMap k v) where defaultValue = Just InsOrd.empty
89
91
90-------------------------------------------------------------------------------
92-------------------------------------------------------------------------------
src/Data/Swagger/Operation.hs+3−2
@@ -46,6 +46,7 @@ import Data.Swagger.Lens
46import Data.Swagger.Schema
46import Data.Swagger.Schema
47
47
48import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
48import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
49+import qualified Data.HashSet.InsOrd as InsOrdHS
49
50
50-- $setup
51-- $setup
51-- >>> import Data.Aeson
52-- >>> import Data.Aeson
@@ -111,8 +112,8 @@ applyTags = applyTagsFor allOperations
111-- list of tags.
112-- list of tags.
112applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
113applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
113applyTagsFor ops ts swag = swag
114applyTagsFor ops ts swag = swag
114− & ops . tags %~ (<> Set.fromList (map _tagName ts))
115+ & ops . tags %~ (<> InsOrdHS.fromList (map _tagName ts))
115− & tags %~ (<> Set.fromList ts)
116+ & tags %~ (<> InsOrdHS.fromList ts)
116
117
117-- | Construct a response with @'Schema'@ while declaring all
118-- | Construct a response with @'Schema'@ while declaring all
118-- necessary schema definitions.
119-- necessary schema definitions.
stack.yaml+1
@@ -5,3 +5,4 @@ extra-deps:
5- aeson-1.4.2.0
5- aeson-1.4.2.0
6- base-compat-batteries-0.10.4
6- base-compat-batteries-0.10.4
7- contravariant-1.5
7- contravariant-1.5
8+- insert-ordered-containers-0.2.2
swagger2.cabal+1−1
@@ -81,7 +81,7 @@ library
81 , generics-sop >=0.3.2.0 && <0.6
81 , generics-sop >=0.3.2.0 && <0.6
82 , hashable >=1.2.7.0 && <1.4
82 , hashable >=1.2.7.0 && <1.4
83 , http-media >=0.7.1.2 && <0.9
83 , http-media >=0.7.1.2 && <0.9
84− , insert-ordered-containers >=0.2.1.0 && <0.3
84+ , insert-ordered-containers >=0.2.2 && <0.3
85 , lens >=4.16.1 && <4.18
85 , lens >=4.16.1 && <4.18
86 , network >=2.6.3.5 && <3.2
86 , network >=2.6.3.5 && <3.2
87 , scientific >=0.3.6.2 && <0.4
87 , scientific >=0.3.6.2 && <0.4
test/Data/SwaggerSpec.hs+3−3
@@ -12,7 +12,7 @@ import Control.Lens
12import Data.Aeson
12import Data.Aeson
13import Data.Aeson.QQ.Simple
13import Data.Aeson.QQ.Simple
14import Data.HashMap.Strict (HashMap)
14import Data.HashMap.Strict (HashMap)
15−import qualified Data.Set as Set
15+import qualified Data.HashSet.InsOrd as InsOrdHS
16import Data.Text (Text)
16import Data.Text (Text)
17
17
18import Data.Swagger
18import Data.Swagger
@@ -127,7 +127,7 @@ licenseExampleJSON = [aesonQQ|
127
127
128operationExample :: Operation
128operationExample :: Operation
129operationExample = mempty
129operationExample = mempty
130− & tags .~ Set.fromList ["pet"]
130+ & tags .~ InsOrdHS.fromList ["pet"]
131 & summary ?~ "Updates a pet in the store with form data"
131 & summary ?~ "Updates a pet in the store with form data"
132 & description ?~ ""
132 & description ?~ ""
133 & operationId ?~ "updatePetWithForm"
133 & operationId ?~ "updatePetWithForm"
@@ -531,7 +531,7 @@ swaggerExample = mempty
531 & schema .~ ParamOther (mempty
531 & schema .~ ParamOther (mempty
532 & in_ .~ ParamPath
532 & in_ .~ ParamPath
533 & type_ ?~ SwaggerString ) ]
533 & type_ ?~ SwaggerString ) ]
534− & tags .~ Set.fromList [ "todo" ] ))
534+ & tags .~ InsOrdHS.fromList [ "todo" ] ))
535
535
536swaggerExampleJSON :: Value
536swaggerExampleJSON :: Value
537swaggerExampleJSON = [aesonQQ|
537swaggerExampleJSON = [aesonQQ|