git.iko.soy/typeable/swagger2
on master help sign in
Merge pull request #33 from GetShopTV/release-v1.1
5f050d6Nickolay Kudasov
CHANGELOG.md+14
@@ -1,3 +1,17 @@
1+1.1
2+---
3+* Major changes:
4+ * Put `CollectionFormat` in one place (see [`3cc860d`](https://github.com/GetShopTV/swagger2/commit/3cc860dd3f002ab984f4d0e4ce1d1799f985832e)).
5+
6+* Minor changes:
7+ * Use Swagger formats for `Int32`, `Int64`, `Float`, `Double`, `Day` and `ZonedTime` (see [#32](https://github.com/GetShopTV/swagger2/pull/32));
8+ * Export `HeaderName`, `TagName`, `HttpStatusCode` type synonyms;
9+ * Add `ToParamSchema` instances for `[a]`, `Set a` and `HashSet a`;
10+ * Add `Monoid` instances for `Header` and `Example`.
11+
12+* Fixes:
13+ * Use overwrite strategy for `HashMap` `SwaggerMonoid` instances by default.
14+
11.0
151.0
2---
16---
3* Major changes:
17* Major changes:
src/Data/Swagger.hs+4−2
@@ -38,8 +38,9 @@ module Data.Swagger (
38 PathItem(..),
38 PathItem(..),
39
39
40 -- ** Operations
40 -- ** Operations
41− Tag(..),
42 Operation(..),
41 Operation(..),
42+ Tag(..),
43+ TagName,
43
44
44 -- ** Types and formats
45 -- ** Types and formats
45 SwaggerType(..),
46 SwaggerType(..),
@@ -52,8 +53,8 @@ module Data.Swagger (
52 ParamOtherSchema(..),
53 ParamOtherSchema(..),
53 ParamLocation(..),
54 ParamLocation(..),
54 ParamName,
55 ParamName,
55− Items(..),
56 Header(..),
56 Header(..),
57+ HeaderName,
57 Example(..),
58 Example(..),
58
59
59 -- ** Schemas
60 -- ** Schemas
@@ -65,6 +66,7 @@ module Data.Swagger (
65 -- ** Responses
66 -- ** Responses
66 Responses(..),
67 Responses(..),
67 Response(..),
68 Response(..),
69+ HttpStatusCode,
68
70
69 -- ** Security
71 -- ** Security
70 SecurityScheme(..),
72 SecurityScheme(..),
src/Data/Swagger/Internal.hs+43−67
@@ -211,7 +211,7 @@ data PathItem = PathItem
211data Operation = Operation
211data Operation = Operation
212 { -- | A list of tags for API documentation control.
212 { -- | A list of tags for API documentation control.
213 -- Tags can be used for logical grouping of operations by resources or any other qualifier.
213 -- Tags can be used for logical grouping of operations by resources or any other qualifier.
214− _operationTags :: [Text]
214+ _operationTags :: [TagName]
215
215
216 -- | A short summary of what the operation does.
216 -- | A short summary of what the operation does.
217 -- For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
217 -- For maximum readability in the swagger-ui, this field SHOULD be less than 120 characters.
@@ -319,15 +319,21 @@ data ParamOtherSchema = ParamOtherSchema
319 -- Default value is @False@.
319 -- Default value is @False@.
320 , _paramOtherSchemaAllowEmptyValue :: Maybe Bool
320 , _paramOtherSchemaAllowEmptyValue :: Maybe Bool
321
321
322− -- | Determines the format of the array if @'ParamArray'@ is used.
323− -- Default value is csv.
324− , _paramOtherSchemaCollectionFormat :: Maybe (CollectionFormat Param)
325−
326 , _paramOtherSchemaParamSchema :: ParamSchema ParamOtherSchema
322 , _paramOtherSchemaParamSchema :: ParamSchema ParamOtherSchema
327 } deriving (Eq, Show, Generic, Data, Typeable)
323 } deriving (Eq, Show, Generic, Data, Typeable)
328
324
325+-- | Items for @'SwaggerArray'@ schemas.
326+--
327+-- @'SwaggerItemsPrimitive'@ should be used only for query params, headers and path pieces.
328+-- The @'CollectionFormat' t@ parameter specifies how elements of an array should be displayed.
329+-- Note that @fmt@ in @'SwaggerItemsPrimitive' fmt schema@ specifies format for elements of type @schema@.
330+-- This is different from the original Swagger's <http://swagger.io/specification/#itemsObject Items Object>.
331+--
332+-- @'SwaggerItemsObject'@ should be used to specify homogenous array @'Schema'@s.
333+--
334+-- @'SwaggerItemsArray'@ should be used to specify tuple @'Schema'@s.
329data SwaggerItems t where
335data SwaggerItems t where
330− SwaggerItemsPrimitive :: Items -> SwaggerItems t
336+ SwaggerItemsPrimitive :: Maybe (CollectionFormat t) -> ParamSchema t -> SwaggerItems t
331 SwaggerItemsObject :: Referenced Schema -> SwaggerItems Schema
337 SwaggerItemsObject :: Referenced Schema -> SwaggerItems Schema
332 SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems Schema
338 SwaggerItemsArray :: [Referenced Schema] -> SwaggerItems Schema
333
339
@@ -341,9 +347,9 @@ swaggerItemsPrimitiveConstr = mkConstr swaggerItemsDataType "SwaggerItemsPrimiti
341swaggerItemsDataType :: DataType
347swaggerItemsDataType :: DataType
342swaggerItemsDataType = mkDataType "Data.Swagger.SwaggerItems" [swaggerItemsPrimitiveConstr]
348swaggerItemsDataType = mkDataType "Data.Swagger.SwaggerItems" [swaggerItemsPrimitiveConstr]
343
349
344−instance {-# OVERLAPPABLE #-} Typeable t => Data (SwaggerItems t) where
350+instance {-# OVERLAPPABLE #-} Data t => Data (SwaggerItems t) where
345 gunfold k z c = case constrIndex c of
351 gunfold k z c = case constrIndex c of
346− 1 -> k (z SwaggerItemsPrimitive)
352+ 1 -> k (k (z SwaggerItemsPrimitive))
347 _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type (SwaggerItems t)."
353 _ -> error $ "Data.Data.gunfold: Constructor " ++ show c ++ " is not of type (SwaggerItems t)."
348 toConstr _ = swaggerItemsPrimitiveConstr
354 toConstr _ = swaggerItemsPrimitiveConstr
349 dataTypeOf _ = swaggerItemsDataType
355 dataTypeOf _ = swaggerItemsDataType
@@ -508,7 +514,7 @@ deriving instance (Data t, Data (SwaggerType t), Data (SwaggerItems t)) => Data
508
514
509data Xml = Xml
515data Xml = Xml
510 { -- | Replaces the name of the element/attribute used for the described schema property.
516 { -- | Replaces the name of the element/attribute used for the described schema property.
511− -- When defined within the @'Items'@ (items), it will affect the name of the individual XML elements within the list.
517+ -- When defined within the @'SwaggerItems'@ (items), it will affect the name of the individual XML elements within the list.
512 -- When defined alongside type being array (outside the items),
518 -- When defined alongside type being array (outside the items),
513 -- it will affect the wrapping element and only if wrapped is true.
519 -- it will affect the wrapping element and only if wrapped is true.
514 -- If wrapped is false, it will be ignored.
520 -- If wrapped is false, it will be ignored.
@@ -534,14 +540,6 @@ data Xml = Xml
534 , _xmlWrapped :: Maybe Bool
540 , _xmlWrapped :: Maybe Bool
535 } deriving (Eq, Show, Generic, Data, Typeable)
541 } deriving (Eq, Show, Generic, Data, Typeable)
536
542
537−data Items = Items
538− { -- | Determines the format of the array if type array is used.
539− -- Default value is @'ItemsCollectionCSV'@.
540− _itemsCollectionFormat :: Maybe (CollectionFormat Items)
541−
542− , _itemsParamSchema :: ParamSchema Items
543− } deriving (Eq, Show, Generic, Data, Typeable)
544−
545-- | A container for the expected responses of an operation.
543-- | A container for the expected responses of an operation.
546-- The container maps a HTTP response code to the expected response.
544-- The container maps a HTTP response code to the expected response.
547-- It is not expected from the documentation to necessarily cover all possible HTTP response codes,
545-- It is not expected from the documentation to necessarily cover all possible HTTP response codes,
@@ -585,10 +583,6 @@ data Header = Header
585 { -- | A short description of the header.
583 { -- | A short description of the header.
586 _headerDescription :: Maybe Text
584 _headerDescription :: Maybe Text
587
585
588− -- | Determines the format of the array if type array is used.
589− -- Default value is @'ItemsCollectionCSV'@.
590− , _headerCollectionFormat :: Maybe (CollectionFormat Items)
591−
592 , _headerParamSchema :: ParamSchema Header
586 , _headerParamSchema :: ParamSchema Header
593 } deriving (Eq, Show, Generic, Data, Typeable)
587 } deriving (Eq, Show, Generic, Data, Typeable)
594
588
@@ -664,11 +658,14 @@ newtype SecurityRequirement = SecurityRequirement
664 { getSecurityRequirement :: HashMap Text [Text]
658 { getSecurityRequirement :: HashMap Text [Text]
665 } deriving (Eq, Read, Show, Monoid, ToJSON, FromJSON, Data, Typeable)
659 } deriving (Eq, Read, Show, Monoid, ToJSON, FromJSON, Data, Typeable)
666
660
661+-- | Tag name.
662+type TagName = Text
663+
667-- | Allows adding meta data to a single tag that is used by @Operation@.
664-- | Allows adding meta data to a single tag that is used by @Operation@.
668-- It is not mandatory to have a @Tag@ per tag used there.
665-- It is not mandatory to have a @Tag@ per tag used there.
669data Tag = Tag
666data Tag = Tag
670 { -- | The name of the tag.
667 { -- | The name of the tag.
671− _tagName :: Text
668+ _tagName :: TagName
672
669
673 -- | A short description for the tag.
670 -- | A short description for the tag.
674 -- GFM syntax can be used for rich text representation.
671 -- GFM syntax can be used for rich text representation.
@@ -736,6 +733,10 @@ instance Monoid ParamOtherSchema where
736 mempty = genericMempty
733 mempty = genericMempty
737 mappend = genericMappend
734 mappend = genericMappend
738
735
736+instance Monoid Header where
737+ mempty = genericMempty
738+ mappend = genericMappend
739+
739instance Monoid Responses where
740instance Monoid Responses where
740 mempty = genericMempty
741 mempty = genericMempty
741 mappend = genericMappend
742 mappend = genericMappend
@@ -752,6 +753,10 @@ instance Monoid Operation where
752 mempty = genericMempty
753 mempty = genericMempty
753 mappend = genericMappend
754 mappend = genericMappend
754
755
756+instance Monoid Example where
757+ mempty = genericMempty
758+ mappend = genericMappend
759+
755-- =======================================================================
760-- =======================================================================
756-- SwaggerMonoid helper instances
761-- SwaggerMonoid helper instances
757-- =======================================================================
762-- =======================================================================
@@ -779,43 +784,15 @@ instance SwaggerMonoid ParamLocation where
779 swaggerMempty = ParamQuery
784 swaggerMempty = ParamQuery
780 swaggerMappend _ y = y
785 swaggerMappend _ y = y
781
786
782−instance SwaggerMonoid (HashMap Text Schema) where
787+instance SwaggerMonoid (HashMap FilePath PathItem) where
783 swaggerMempty = HashMap.empty
788 swaggerMempty = HashMap.empty
784 swaggerMappend = HashMap.unionWith mappend
789 swaggerMappend = HashMap.unionWith mappend
785
790
786−instance SwaggerMonoid (HashMap Text (Referenced Schema)) where
787− swaggerMempty = HashMap.empty
788− swaggerMappend = HashMap.unionWith swaggerMappend
789−
790instance Monoid a => SwaggerMonoid (Referenced a) where
791instance Monoid a => SwaggerMonoid (Referenced a) where
791 swaggerMempty = Inline mempty
792 swaggerMempty = Inline mempty
792 swaggerMappend (Inline x) (Inline y) = Inline (x <> y)
793 swaggerMappend (Inline x) (Inline y) = Inline (x <> y)
793 swaggerMappend _ y = y
794 swaggerMappend _ y = y
794
795
795−instance SwaggerMonoid (HashMap Text Param) where
796− swaggerMempty = HashMap.empty
797− swaggerMappend = HashMap.unionWith mappend
798−
799−instance SwaggerMonoid (HashMap Text Response) where
800− swaggerMempty = HashMap.empty
801− swaggerMappend = flip HashMap.union
802−
803−instance SwaggerMonoid (HashMap Text SecurityScheme) where
804− swaggerMempty = HashMap.empty
805− swaggerMappend = flip HashMap.union
806−
807−instance SwaggerMonoid (HashMap FilePath PathItem) where
808− swaggerMempty = HashMap.empty
809− swaggerMappend = HashMap.unionWith mappend
810−
811−instance SwaggerMonoid (HashMap HeaderName Header) where
812− swaggerMempty = HashMap.empty
813− swaggerMappend = flip HashMap.union
814−
815−instance SwaggerMonoid (HashMap HttpStatusCode (Referenced Response)) where
816− swaggerMempty = HashMap.empty
817− swaggerMappend = flip HashMap.union
818−
819instance SwaggerMonoid ParamAnySchema where
796instance SwaggerMonoid ParamAnySchema where
820 swaggerMempty = ParamOther swaggerMempty
797 swaggerMempty = ParamOther swaggerMempty
821 swaggerMappend (ParamBody x) (ParamBody y) = ParamBody (swaggerMappend x y)
798 swaggerMappend (ParamBody x) (ParamBody y) = ParamBody (swaggerMappend x y)
@@ -934,13 +911,12 @@ instance ToJSON Schema where
934instance ToJSON Header where
911instance ToJSON Header where
935 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "header")
912 toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "header")
936
913
937−instance ToJSON Items where
938− toJSON = genericToJSONWithSub "paramSchema" (jsonPrefix "items")
939−
940instance ToJSON (SwaggerItems t) where
914instance ToJSON (SwaggerItems t) where
941− toJSON (SwaggerItemsPrimitive x) = toJSON x
915+ toJSON (SwaggerItemsPrimitive fmt schema) = object
916+ [ "collectionFormat" .= fmt
917+ , "items" .= schema ]
942− toJSON (SwaggerItemsObject x) = toJSON x
918+ toJSON (SwaggerItemsObject x) = object [ "items" .= x ]
943− toJSON (SwaggerItemsArray x) = toJSON x
919+ toJSON (SwaggerItemsArray x) = object [ "items" .= x ]
944
920
945instance ToJSON Host where
921instance ToJSON Host where
946 toJSON (Host host mport) = toJSON $
922 toJSON (Host host mport) = toJSON $
@@ -1009,7 +985,7 @@ instance ToJSON (CollectionFormat t) where
1009 toJSON CollectionMulti = "multi"
985 toJSON CollectionMulti = "multi"
1010
986
1011instance ToJSON (ParamSchema t) where
987instance ToJSON (ParamSchema t) where
1012− toJSON = genericToJSON (jsonPrefix "paramSchema")
988+ toJSON = omitEmpties . genericToJSONWithSub "items" (jsonPrefix "paramSchema")
1013
989
1014-- =======================================================================
990-- =======================================================================
1015-- Manual FromJSON instances
991-- Manual FromJSON instances
@@ -1068,11 +1044,10 @@ instance FromJSON Schema where
1068instance FromJSON Header where
1044instance FromJSON Header where
1069 parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "header")
1045 parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "header")
1070
1046
1071−instance FromJSON Items where
1072− parseJSON = genericParseJSONWithSub "paramSchema" (jsonPrefix "items")
1073−
1074−instance {-# OVERLAPPABLE #-} FromJSON (SwaggerItems t) where
1047+instance {-# OVERLAPPABLE #-} (FromJSON (CollectionFormat t), FromJSON (ParamSchema t)) => FromJSON (SwaggerItems t) where
1075− parseJSON js = SwaggerItemsPrimitive <$> parseJSON js
1048+ parseJSON (Object o) = SwaggerItemsPrimitive
1049+ <$> o .:? "collectionFormat"
1050+ <*> (o .: "items" >>= parseJSON)
1076
1051
1077instance {-# OVERLAPPING #-} FromJSON (SwaggerItems Schema) where
1052instance {-# OVERLAPPING #-} FromJSON (SwaggerItems Schema) where
1078 parseJSON js@(Object _) = SwaggerItemsObject <$> parseJSON js
1053 parseJSON js@(Object _) = SwaggerItemsObject <$> parseJSON js
@@ -1166,16 +1141,17 @@ instance FromJSON (SwaggerType ParamOtherSchema) where
1166instance {-# OVERLAPPABLE #-} FromJSON (SwaggerType t) where
1141instance {-# OVERLAPPABLE #-} FromJSON (SwaggerType t) where
1167 parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray]
1142 parseJSON = parseOneOf [SwaggerString, SwaggerInteger, SwaggerNumber, SwaggerBoolean, SwaggerArray]
1168
1143
1144+instance {-# OVERLAPPABLE #-} FromJSON (CollectionFormat t) where
1145+ parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
1146+
1169instance FromJSON (CollectionFormat Param) where
1147instance FromJSON (CollectionFormat Param) where
1170 parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes, CollectionMulti]
1148 parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes, CollectionMulti]
1171
1149
1172−instance FromJSON (CollectionFormat Items) where
1173− parseJSON = parseOneOf [CollectionCSV, CollectionSSV, CollectionTSV, CollectionPipes]
1174−
1175-- NOTE: The constraints @FromJSON (SwaggerType t)@ and
1150-- NOTE: The constraints @FromJSON (SwaggerType t)@ and
1176-- @FromJSON (SwaggerItems t)@ are necessary here!
1151-- @FromJSON (SwaggerItems t)@ are necessary here!
1177-- Without the constraint the general instance will be used
1152-- Without the constraint the general instance will be used
1178-- that only accepts common types (i.e. NOT object, null or file)
1153-- that only accepts common types (i.e. NOT object, null or file)
1179-- and primitive array items.
1154-- and primitive array items.
1180instance (FromJSON (SwaggerType t), FromJSON (SwaggerItems t)) => FromJSON (ParamSchema t) where
1155instance (FromJSON (SwaggerType t), FromJSON (SwaggerItems t)) => FromJSON (ParamSchema t) where
1181− parseJSON = genericParseJSON (jsonPrefix "ParamSchema")
1156+ parseJSON = genericParseJSONWithSub "items" (jsonPrefix "ParamSchema")
1157+
src/Data/Swagger/Internal/ParamSchema.hs+15
@@ -3,6 +3,7 @@
3{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE FlexibleInstances #-}
4{-# LANGUAGE KindSignatures #-}
4{-# LANGUAGE KindSignatures #-}
5{-# LANGUAGE OverloadedStrings #-}
5{-# LANGUAGE OverloadedStrings #-}
6+{-# LANGUAGE PackageImports #-}
6{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE PolyKinds #-}
7{-# LANGUAGE ScopedTypeVariables #-}
8{-# LANGUAGE ScopedTypeVariables #-}
8{-# LANGUAGE TypeOperators #-}
9{-# LANGUAGE TypeOperators #-}
@@ -15,7 +16,9 @@ import Data.Proxy
15import GHC.Generics
16import GHC.Generics
16
17
17import Data.Int
18import Data.Int
19+import "unordered-containers" Data.HashSet (HashSet)
18import Data.Monoid
20import Data.Monoid
21+import Data.Set (Set)
19import Data.Scientific
22import Data.Scientific
20import qualified Data.Text as T
23import qualified Data.Text as T
21import qualified Data.Text.Lazy as TL
24import qualified Data.Text.Lazy as TL
@@ -168,6 +171,18 @@ instance ToParamSchema a => ToParamSchema (First a) where toParamSchema _ = to
168instance ToParamSchema a => ToParamSchema (Last a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
171instance ToParamSchema a => ToParamSchema (Last a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
169instance ToParamSchema a => ToParamSchema (Dual a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
172instance ToParamSchema a => ToParamSchema (Dual a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
170
173
174+instance ToParamSchema a => ToParamSchema [a] where
175+ toParamSchema _ = mempty
176+ & schemaType .~ SwaggerArray
177+ & schemaItems ?~ SwaggerItemsPrimitive Nothing (toParamSchema (Proxy :: Proxy a))
178+
179+instance ToParamSchema a => ToParamSchema (Set a) where
180+ toParamSchema _ = toParamSchema (Proxy :: Proxy [a])
181+ & schemaUniqueItems ?~ True
182+
183+instance ToParamSchema a => ToParamSchema (HashSet a) where
184+ toParamSchema _ = toParamSchema (Proxy :: Proxy (Set a))
185+
171-- |
186-- |
172-- >>> encode $ toParamSchema (Proxy :: Proxy ())
187-- >>> encode $ toParamSchema (Proxy :: Proxy ())
173-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
188-- "{\"type\":\"string\",\"enum\":[\"_\"]}"
src/Data/Swagger/Internal/Utils.hs+14−4
@@ -1,5 +1,6 @@
1{-# LANGUAGE DefaultSignatures #-}
1{-# LANGUAGE DefaultSignatures #-}
2{-# LANGUAGE FlexibleContexts #-}
2{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleInstances #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE RankNTypes #-}
5{-# LANGUAGE RankNTypes #-}
5{-# LANGUAGE TypeOperators #-}
6{-# LANGUAGE TypeOperators #-}
@@ -14,6 +15,7 @@ import Data.Data
14import Data.Hashable (Hashable)
15import Data.Hashable (Hashable)
15import Data.HashMap.Strict (HashMap)
16import Data.HashMap.Strict (HashMap)
16import qualified Data.HashMap.Strict as HashMap
17import qualified Data.HashMap.Strict as HashMap
18+import Data.Map (Map)
17import Data.Monoid
19import Data.Monoid
18import Data.Text (Text)
20import Data.Text (Text)
19import GHC.Generics
21import GHC.Generics
@@ -66,14 +68,17 @@ genericToJSONWithSub :: (Generic a, GToJSON (Rep a)) => Text -> Options -> a ->
66genericToJSONWithSub sub opts x =
68genericToJSONWithSub sub opts x =
67 case genericToJSON opts x of
69 case genericToJSON opts x of
68 Object o ->
70 Object o ->
69− let so = HashMap.lookupDefault (error "impossible") sub o
71+ case HashMap.lookup sub o of
70− in Object (HashMap.delete sub o) <+> so
72+ Just so -> Object (HashMap.delete sub o) <+> so
73+ Nothing -> Object o -- no subjson, leaving object as is
71 _ -> error "genericToJSONWithSub: subjson is not an object"
74 _ -> error "genericToJSONWithSub: subjson is not an object"
72
75
73genericParseJSONWithSub :: (Generic a, GFromJSON (Rep a)) => Text -> Options -> Value -> Parser a
76genericParseJSONWithSub :: (Generic a, GFromJSON (Rep a)) => Text -> Options -> Value -> Parser a
74−genericParseJSONWithSub sub opts (Object o) = genericParseJSON opts js
77+genericParseJSONWithSub sub opts js@(Object o)
78+ = genericParseJSON opts js -- try without subjson
79+ <|> genericParseJSON opts js' -- try with subjson
75 where
80 where
76− js = Object (HashMap.insert sub (Object o) o)
81+ js' = Object (HashMap.insert sub (Object o) o)
77genericParseJSONWithSub _ _ _ = error "genericParseJSONWithSub: given json is not an object"
82genericParseJSONWithSub _ _ _ = error "genericParseJSONWithSub: given json is not an object"
78
83
79(<+>) :: Value -> Value -> Value
84(<+>) :: Value -> Value -> Value
@@ -119,6 +124,11 @@ class SwaggerMonoid m where
119 swaggerMappend = mappend
124 swaggerMappend = mappend
120
125
121instance SwaggerMonoid [a]
126instance SwaggerMonoid [a]
127+instance Ord k => SwaggerMonoid (Map k v)
128+
129+instance {-# OVERLAPPABLE #-} (Eq k, Hashable k) => SwaggerMonoid (HashMap k v) where
130+ swaggerMempty = mempty
131+ swaggerMappend = HashMap.unionWith (\_old new -> new)
122
132
123instance SwaggerMonoid Text where
133instance SwaggerMonoid Text where
124 swaggerMempty = mempty
134 swaggerMempty = mempty
src/Data/Swagger/Lens.hs−3
@@ -38,8 +38,6 @@ makeLenses ''Param
38makePrisms ''ParamAnySchema
38makePrisms ''ParamAnySchema
39-- ** 'ParamOtherSchema' lenses
39-- ** 'ParamOtherSchema' lenses
40makeLenses ''ParamOtherSchema
40makeLenses ''ParamOtherSchema
41−-- ** 'Items' lenses
42−makeLenses ''Items
43-- ** 'Header' lenses
41-- ** 'Header' lenses
44makeLenses ''Header
42makeLenses ''Header
45-- ** 'Schema' lenses
43-- ** 'Schema' lenses
@@ -86,7 +84,6 @@ class HasParamSchema s t | s -> t where
86
84
87instance HasParamSchema Schema Schema where parameterSchema = schemaParamSchema
85instance HasParamSchema Schema Schema where parameterSchema = schemaParamSchema
88instance HasParamSchema ParamOtherSchema ParamOtherSchema where parameterSchema = paramOtherSchemaParamSchema
86instance HasParamSchema ParamOtherSchema ParamOtherSchema where parameterSchema = paramOtherSchemaParamSchema
89−instance HasParamSchema Items Items where parameterSchema = itemsParamSchema
90instance HasParamSchema Header Header where parameterSchema = headerParamSchema
87instance HasParamSchema Header Header where parameterSchema = headerParamSchema
91instance HasParamSchema (ParamSchema t) t where parameterSchema = id
88instance HasParamSchema (ParamSchema t) t where parameterSchema = id
92
89
swagger2.cabal+1−1
@@ -1,5 +1,5 @@
1name: swagger2
1name: swagger2
2−version: 1.0
2+version: 1.1
3synopsis: Swagger 2.0 data model
3synopsis: Swagger 2.0 data model
4description: Please see README.md
4description: Please see README.md
5homepage: https://github.com/GetShopTV/swagger2
5homepage: https://github.com/GetShopTV/swagger2