git.iko.soy/typeable/swagger2
on master help sign in
Merge pull request #192 from phadej/tags-insord-set

Fix #165: Use InsOrdHashSet

commitc367e0677ed93b0a6195b9b4271230ad189ca6af authorOleg Grenrus <oleg.grenrus@iki.fi> dateTue 28 May 2019, 23:46 (7 years ago) parent5232015ac10503
8 files changed+33−10
CHANGELOG.md+11 cabal.project+2 src/Data/Swagger/Internal.hs+10−4 src/Data/Swagger/Internal/AesonUtils.hs+2 src/Data/Swagger/Operation.hs+3−2 stack.yaml+1 swagger2.cabal+1−1 test/Data/SwaggerSpec.hs+3−3
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+
1122.3.1.1
213-------
314- 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
2929import Data.Aeson
3030import qualified Data.Aeson.Types as JSON
3131import Data.Data (Data(..), Typeable, mkConstr, mkDataType, Fixity(..), Constr, DataType, constrIndex)
32+import Data.Hashable (Hashable)
3233import qualified Data.HashMap.Strict as HashMap
34+import Data.HashSet.InsOrd (InsOrdHashSet)
3335import Data.Map (Map)
3436import qualified Data.Map as Map
3537import Data.Monoid (Monoid (..))
3638import Data.Semigroup.Compat (Semigroup (..))
3739import Data.Scientific (Scientific)
38−import Data.Set (Set)
3940import Data.String (IsString(..))
4041import Data.Text (Text)
4142import qualified Data.Text as Text
@@ -129,7 +130,7 @@ data Swagger = Swagger
129130 -- Not all tags that are used by the Operation Object must be declared.
130131 -- The tags that are not declared may be organized randomly or based on the tools' logic.
131132 -- Each tag name in the list MUST be unique.
132− , _swaggerTags :: Set Tag
133+ , _swaggerTags :: InsOrdHashSet Tag
133134
134135 -- | Additional external documentation.
135136 , _swaggerExternalDocs :: Maybe ExternalDocs
@@ -251,7 +252,7 @@ data PathItem = PathItem
251252data Operation = Operation
252253 { -- | A list of tags for API documentation control.
253254 -- Tags can be used for logical grouping of operations by resources or any other qualifier.
254− _operationTags :: Set TagName
255+ _operationTags :: InsOrdHashSet TagName
255256
256257 -- | A short summary of what the operation does.
257258 -- For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
@@ -778,6 +779,8 @@ data Tag = Tag
778779 , _tagExternalDocs :: Maybe ExternalDocs
779780 } deriving (Eq, Ord, Show, Generic, Data, Typeable)
780781
782+instance Hashable Tag
783+
781784instance IsString Tag where
782785 fromString s = Tag (fromString s) Nothing Nothing
783786
@@ -791,6 +794,8 @@ data ExternalDocs = ExternalDocs
791794 , _externalDocsUrl :: URL
792795 } deriving (Eq, Ord, Show, Generic, Data, Typeable)
793796
797+instance Hashable ExternalDocs
798+
794799-- | A simple object to allow referencing other definitions in the specification.
795800-- It can be used to reference parameters and responses that are defined at the top level for reuse.
796801newtype Reference = Reference { getReference :: Text }
@@ -804,7 +809,7 @@ data Referenced a
804809instance IsString a => IsString (Referenced a) where
805810 fromString = Inline . fromString
806811
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)
808813
809814data AdditionalProperties
810815 = AdditionalPropertiesAllowed Bool
@@ -913,6 +918,7 @@ instance SwaggerMonoid Responses
913918instance SwaggerMonoid Response
914919instance SwaggerMonoid ExternalDocs
915920instance SwaggerMonoid Operation
921+instance (Eq a, Hashable a) => SwaggerMonoid (InsOrdHashSet a)
916922
917923instance SwaggerMonoid MimeList
918924deriving instance SwaggerMonoid URL
src/Data/Swagger/Internal/AesonUtils.hs+2
@@ -44,6 +44,7 @@ import qualified Data.Text as T
4444import qualified Data.HashMap.Strict as HM
4545import qualified Data.Set as Set
4646import qualified Data.HashMap.Strict.InsOrd as InsOrd
47+import qualified Data.HashSet.InsOrd as InsOrdHS
4748
4849#if MIN_VERSION_aeson(0,10,0)
4950import Data.Aeson (Encoding, pairs, (.=), Series)
@@ -85,6 +86,7 @@ instance AesonDefaultValue Text where defaultValue = Nothing
8586instance AesonDefaultValue (Maybe a) where defaultValue = Just Nothing
8687instance AesonDefaultValue [a] where defaultValue = Just []
8788instance AesonDefaultValue (Set.Set a) where defaultValue = Just Set.empty
89+instance AesonDefaultValue (InsOrdHS.InsOrdHashSet k) where defaultValue = Just InsOrdHS.empty
8890instance AesonDefaultValue (InsOrd.InsOrdHashMap k v) where defaultValue = Just InsOrd.empty
8991
9092-------------------------------------------------------------------------------
src/Data/Swagger/Operation.hs+3−2
@@ -46,6 +46,7 @@ import Data.Swagger.Lens
4646import Data.Swagger.Schema
4747
4848import qualified Data.HashMap.Strict.InsOrd as InsOrdHashMap
49+import qualified Data.HashSet.InsOrd as InsOrdHS
4950
5051-- $setup
5152-- >>> import Data.Aeson
@@ -111,8 +112,8 @@ applyTags = applyTagsFor allOperations
111112-- list of tags.
112113applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
113114applyTagsFor ops ts swag = swag
114− & ops . tags %~ (<> Set.fromList (map _tagName ts))
115− & tags %~ (<> Set.fromList ts)
115+ & ops . tags %~ (<> InsOrdHS.fromList (map _tagName ts))
116+ & tags %~ (<> InsOrdHS.fromList ts)
116117
117118-- | Construct a response with @'Schema'@ while declaring all
118119-- necessary schema definitions.
stack.yaml+1
@@ -5,3 +5,4 @@ extra-deps:
55- aeson-1.4.2.0
66- base-compat-batteries-0.10.4
77- contravariant-1.5
8+- insert-ordered-containers-0.2.2
swagger2.cabal+1−1
@@ -81,7 +81,7 @@ library
8181 , generics-sop >=0.3.2.0 && <0.6
8282 , hashable >=1.2.7.0 && <1.4
8383 , 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
8585 , lens >=4.16.1 && <4.18
8686 , network >=2.6.3.5 && <3.2
8787 , scientific >=0.3.6.2 && <0.4
test/Data/SwaggerSpec.hs+3−3
@@ -12,7 +12,7 @@ import Control.Lens
1212import Data.Aeson
1313import Data.Aeson.QQ.Simple
1414import Data.HashMap.Strict (HashMap)
15−import qualified Data.Set as Set
15+import qualified Data.HashSet.InsOrd as InsOrdHS
1616import Data.Text (Text)
1717
1818import Data.Swagger
@@ -127,7 +127,7 @@ licenseExampleJSON = [aesonQQ|
127127
128128operationExample :: Operation
129129operationExample = mempty
130− & tags .~ Set.fromList ["pet"]
130+ & tags .~ InsOrdHS.fromList ["pet"]
131131 & summary ?~ "Updates a pet in the store with form data"
132132 & description ?~ ""
133133 & operationId ?~ "updatePetWithForm"
@@ -531,7 +531,7 @@ swaggerExample = mempty
531531 & schema .~ ParamOther (mempty
532532 & in_ .~ ParamPath
533533 & type_ ?~ SwaggerString ) ]
534− & tags .~ Set.fromList [ "todo" ] ))
534+ & tags .~ InsOrdHS.fromList [ "todo" ] ))
535535
536536swaggerExampleJSON :: Value
537537swaggerExampleJSON = [aesonQQ|