git.iko.soy/typeable/openapi3
on master help sign in
Change tags to be a Set
72b9b98Nickolay Kudasov
src/Data/Swagger/Internal.hs+6−5
@@ -29,6 +29,7 @@ import Data.Map (Map)
29import qualified Data.Map as Map
29import qualified Data.Map as Map
30import Data.Monoid
30import Data.Monoid
31import Data.Scientific (Scientific)
31import Data.Scientific (Scientific)
32+import Data.Set (Set)
32import Data.String (IsString(..))
33import Data.String (IsString(..))
33import Data.Text (Text)
34import Data.Text (Text)
34import qualified Data.Text as Text
35import qualified Data.Text as Text
@@ -99,7 +100,7 @@ data Swagger = Swagger
99 -- Not all tags that are used by the Operation Object must be declared.
100 -- Not all tags that are used by the Operation Object must be declared.
100 -- The tags that are not declared may be organized randomly or based on the tools' logic.
101 -- The tags that are not declared may be organized randomly or based on the tools' logic.
101 -- Each tag name in the list MUST be unique.
102 -- Each tag name in the list MUST be unique.
102− , _swaggerTags :: [Tag]
103+ , _swaggerTags :: Set Tag
103
104
104 -- | Additional external documentation.
105 -- | Additional external documentation.
105 , _swaggerExternalDocs :: Maybe ExternalDocs
106 , _swaggerExternalDocs :: Maybe ExternalDocs
@@ -221,7 +222,7 @@ data PathItem = PathItem
221data Operation = Operation
222data Operation = Operation
222 { -- | A list of tags for API documentation control.
223 { -- | A list of tags for API documentation control.
223 -- Tags can be used for logical grouping of operations by resources or any other qualifier.
224 -- Tags can be used for logical grouping of operations by resources or any other qualifier.
224− _operationTags :: [TagName]
225+ _operationTags :: Set TagName
225
226
226 -- | A short summary of what the operation does.
227 -- | A short summary of what the operation does.
227 -- For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
228 -- For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
@@ -697,7 +698,7 @@ data Tag = Tag
697
698
698 -- | Additional external documentation for this tag.
699 -- | Additional external documentation for this tag.
699 , _tagExternalDocs :: Maybe ExternalDocs
700 , _tagExternalDocs :: Maybe ExternalDocs
700− } deriving (Eq, Show, Generic, Data, Typeable)
701+ } deriving (Eq, Ord, Show, Generic, Data, Typeable)
701
702
702instance IsString Tag where
703instance IsString Tag where
703 fromString s = Tag (fromString s) Nothing Nothing
704 fromString s = Tag (fromString s) Nothing Nothing
@@ -710,7 +711,7 @@ data ExternalDocs = ExternalDocs
710
711
711 -- | The URL for the target documentation.
712 -- | The URL for the target documentation.
712 , _externalDocsUrl :: URL
713 , _externalDocsUrl :: URL
713− } deriving (Eq, Show, Generic, Data, Typeable)
714+ } deriving (Eq, Ord, Show, Generic, Data, Typeable)
714
715
715-- | A simple object to allow referencing other definitions in the specification.
716-- | A simple object to allow referencing other definitions in the specification.
716-- It can be used to reference parameters and responses that are defined at the top level for reuse.
717-- 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
725instance IsString a => IsString (Referenced a) where
726instance IsString a => IsString (Referenced a) where
726 fromString = Inline . fromString
727 fromString = Inline . fromString
727
728
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)
729
730
730-- =======================================================================
731-- =======================================================================
731-- Monoid instances
732-- Monoid instances
src/Data/Swagger/Internal/Utils.hs+2
@@ -22,6 +22,7 @@ import Data.HashMap.Strict (HashMap)
22import qualified Data.HashMap.Strict as HashMap
22import qualified Data.HashMap.Strict as HashMap
23import Data.Map (Map)
23import Data.Map (Map)
24import Data.Monoid
24import Data.Monoid
25+import Data.Set (Set)
25import Data.Text (Text)
26import Data.Text (Text)
26import GHC.Generics
27import GHC.Generics
27import Language.Haskell.TH (mkName)
28import Language.Haskell.TH (mkName)
@@ -152,6 +153,7 @@ class SwaggerMonoid m where
152 swaggerMappend = mappend
153 swaggerMappend = mappend
153
154
154instance SwaggerMonoid [a]
155instance SwaggerMonoid [a]
156+instance Ord a => SwaggerMonoid (Set a)
155instance Ord k => SwaggerMonoid (Map k v)
157instance Ord k => SwaggerMonoid (Map k v)
156
158
157instance (Eq k, Hashable k) => SwaggerMonoid (HashMap k v) where
159instance (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
40import Data.List
40import Data.List
41import Data.Maybe (mapMaybe)
41import Data.Maybe (mapMaybe)
42import Data.Monoid
42import Data.Monoid
43+import qualified Data.Set as Set
43import Data.Traversable
44import Data.Traversable
44
45
45import Data.Swagger.Declare
46import Data.Swagger.Declare
@@ -113,8 +114,8 @@ applyTags = applyTagsFor allOperations
113-- list of tags.
114-- list of tags.
114applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
115applyTagsFor :: Traversal' Swagger Operation -> [Tag] -> Swagger -> Swagger
115applyTagsFor ops ts swag = swag
116applyTagsFor ops ts swag = swag
116− & ops . tags %~ (map _tagName ts ++)
117+ & ops . tags %~ (<> Set.fromList (map _tagName ts))
117− & tags %~ (ts ++)
118+ & tags %~ (<> Set.fromList ts)
118
119
119-- | Construct a response with @'Schema'@ while declaring all
120-- | Construct a response with @'Schema'@ while declaring all
120-- necessary schema definitions.
121-- necessary schema definitions.