git.iko.soy/typeable/swagger2
on master help sign in
Change tags to be a Set
commit72b9b98c7674f8e004611ff0d4280279b26c8c0c authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateTue 2 Feb 2016, 14:03 (11 years ago) parent51c7f31
3 files changed+11−7
src/Data/Swagger/Internal.hs+6−5 src/Data/Swagger/Internal/Utils.hs+2 src/Data/Swagger/Operation.hs+3−2
src/Data/Swagger/Internal.hs+6−5
@@ -29,6 +29,7 @@ import Data.Map (Map)
2929import qualified Data.Map as Map
3030import Data.Monoid
3131import Data.Scientific (Scientific)
32+import Data.Set (Set)
3233import Data.String (IsString(..))
3334import Data.Text (Text)
3435import qualified Data.Text as Text
@@ -99,7 +100,7 @@ data Swagger = Swagger
99100 -- Not all tags that are used by the Operation Object must be declared.
100101 -- The tags that are not declared may be organized randomly or based on the tools' logic.
101102 -- Each tag name in the list MUST be unique.
102− , _swaggerTags :: [Tag]
103+ , _swaggerTags :: Set Tag
103104
104105 -- | Additional external documentation.
105106 , _swaggerExternalDocs :: Maybe ExternalDocs
@@ -221,7 +222,7 @@ data PathItem = PathItem
221222data Operation = Operation
222223 { -- | A list of tags for API documentation control.
223224 -- Tags can be used for logical grouping of operations by resources or any other qualifier.
224− _operationTags :: [TagName]
225+ _operationTags :: Set TagName
225226
226227 -- | A short summary of what the operation does.
227228 -- For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
@@ -697,7 +698,7 @@ data Tag = Tag
697698
698699 -- | Additional external documentation for this tag.
699700 , _tagExternalDocs :: Maybe ExternalDocs
700− } deriving (Eq, Show, Generic, Data, Typeable)
701+ } deriving (Eq, Ord, Show, Generic, Data, Typeable)
701702
702703instance IsString Tag where
703704 fromString s = Tag (fromString s) Nothing Nothing
@@ -710,7 +711,7 @@ data ExternalDocs = ExternalDocs
710711
711712 -- | The URL for the target documentation.
712713 , _externalDocsUrl :: URL
713− } deriving (Eq, Show, Generic, Data, Typeable)
714+ } deriving (Eq, Ord, Show, Generic, Data, Typeable)
714715
715716-- | A simple object to allow referencing other definitions in the specification.
716717-- It can be used to reference parameters and responses that are defined at the top level for reuse.
@@ -725,7 +726,7 @@ data Referenced a
725726instance IsString a => IsString (Referenced a) where
726727 fromString = Inline . fromString
727728
728−newtype URL = URL { getUrl :: Text } deriving (Eq, Show, ToJSON, FromJSON, Data, Typeable)
729+newtype URL = URL { getUrl :: Text } deriving (Eq, Ord, Show, ToJSON, FromJSON, Data, Typeable)
729730
730731-- =======================================================================
731732-- Monoid instances
src/Data/Swagger/Internal/Utils.hs+2
@@ -22,6 +22,7 @@ import Data.HashMap.Strict (HashMap)
2222import qualified Data.HashMap.Strict as HashMap
2323import Data.Map (Map)
2424import Data.Monoid
25+import Data.Set (Set)
2526import Data.Text (Text)
2627import GHC.Generics
2728import Language.Haskell.TH (mkName)
@@ -152,6 +153,7 @@ class SwaggerMonoid m where
152153 swaggerMappend = mappend
153154
154155instance SwaggerMonoid [a]
156+instance Ord a => SwaggerMonoid (Set a)
155157instance Ord k => SwaggerMonoid (Map k v)
156158
157159instance (Eq k, Hashable k) => SwaggerMonoid (HashMap k v) where
src/Data/Swagger/Operation.hs+3−2
@@ -40,6 +40,7 @@ import qualified Data.HashMap.Strict as HashMap
4040import Data.List
4141import Data.Maybe (mapMaybe)
4242import Data.Monoid
43+import qualified Data.Set as Set
4344import Data.Traversable
4445
4546import Data.Swagger.Declare
@@ -113,8 +114,8 @@ applyTags = applyTagsFor allOperations
113114-- list of tags.
114115applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
115116applyTagsFor ops ts swag = swag
116− & ops . tags %~ (map _tagName ts ++)
117− & tags %~ (ts ++)
117+ & ops . tags %~ (<> Set.fromList (map _tagName ts))
118+ & tags %~ (<> Set.fromList ts)
118119
119120-- | Construct a response with @'Schema'@ while declaring all
120121-- necessary schema definitions.