git.iko.soy/typeable/swagger2
on master help sign in
Merge branch 'master' into bytestring-type-errors
commitd2567635ddbf7f7c7b4f9220ac326bc39b9c99da authorNickolay Kudasov <fizruk@users.noreply.github.com> dateTue 27 Sep 2016, 19:44 (10 years ago) parent9fa029e2c26881
6 files changed+50−17
.travis.yml+10 CHANGELOG.md+10 aeson-0.11.cabal.config+1 src/Data/Swagger/Internal/ParamSchema.hs+6 src/Data/Swagger/Internal/Schema.hs+21−16 swagger2.cabal+2−1
.travis.yml+10
@@ -22,10 +22,20 @@ matrix:
2222 - env: CABALVER=1.24 GHCVER=8.0.1
2323 compiler: ": #GHC 8.0.1"
2424 addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1,happy-1.19.5], sources: [hvr-ghc]}}
25+ - env: CABALVER=1.18 GHCVER=7.8.4 CABALCONFIG=aeson-0.11.cabal.config
26+ compiler: ": #GHC 7.8.4 aeson-0.11"
27+ addons: {apt: {packages: [cabal-install-1.18,ghc-7.8.4,happy-1.19.5], sources: [hvr-ghc]}}
28+ - env: CABALVER=1.22 GHCVER=7.10.3 CABALCONFIG=aeson-0.11.cabal.config
29+ compiler: ": #GHC 7.10.3 aeson-0.11"
30+ addons: {apt: {packages: [cabal-install-1.22,ghc-7.10.3,happy-1.19.5], sources: [hvr-ghc]}}
31+ - env: CABALVER=1.24 GHCVER=8.0.1 CABALCONFIG=aeson-0.11.cabal.config
32+ compiler: ": #GHC 8.0.1 aeson-0.11"
33+ addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1,happy-1.19.5], sources: [hvr-ghc]}}
2534
2635before_install:
2736 - unset CC
2837 - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:/opt/happy/1.19.5/bin:$PATH
38+ - if [ -f "$CABALCONFIG" ]; then cp $CABALCONFIG cabal.config; fi
2939
3040install:
3141 - cabal --version
CHANGELOG.md+10
@@ -1,3 +1,13 @@
1+2.1.3
2+-----
3+
4+* Add UUID instances (see [#81](https://github.com/GetShopTV/swagger2/pull/81)).
5+
6+2.1.2.1
7+-------
8+
9+* Bug fix previous release
10+
1112.1.2
212---
313
aeson-0.11.cabal.confignew file+1
@@ -0,0 +1 @@
1+constraints: aeson ==0.11.*
src/Data/Swagger/Internal/ParamSchema.hs+6
@@ -33,6 +33,7 @@ import qualified Data.Vector.Primitive as VP
3333import qualified Data.Vector.Storable as VS
3434import qualified Data.Vector.Unboxed as VU
3535import Data.Word
36+import Data.UUID.Types (UUID)
3637
3738import Data.Swagger.Internal
3839import Data.Swagger.Lens
@@ -243,6 +244,11 @@ instance ToParamSchema () where
243244 & type_ .~ SwaggerString
244245 & enum_ ?~ ["_"]
245246
247+instance ToParamSchema UUID where
248+ toParamSchema _ = mempty
249+ & type_ .~ SwaggerString
250+ & format ?~ "uuid"
251+
246252-- | A configurable generic @'ParamSchema'@ creator.
247253--
248254-- >>> :set -XDeriveGeneric
src/Data/Swagger/Internal/Schema.hs+21−16
@@ -54,6 +54,7 @@ import qualified Data.Vector.Storable as VS
5454import qualified Data.Vector.Unboxed as VU
5555import Data.Word
5656import GHC.Generics
57+import qualified Data.UUID.Types as UUID
5758
5859import Data.Swagger.Declare
5960import Data.Swagger.Internal
@@ -441,6 +442,11 @@ instance (ToSchema a, ToSchema b) => ToSchema (Either a b)
441442instance ToSchema () where
442443 declareNamedSchema _ = pure (NamedSchema Nothing nullarySchema)
443444
445+-- | For 'ToJSON' instance, see <http://hackage.haskell.org/package/uuid-aeson uuid-aeson> package.
446+instance ToSchema UUID.UUID where
447+ declareNamedSchema p = pure $ named "UUID" $ paramSchemaToSchema p
448+ & example ?~ toJSON (UUID.toText UUID.nil)
449+
444450instance (ToSchema a, ToSchema b) => ToSchema (a, b)
445451instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
446452instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
@@ -502,6 +508,21 @@ instance ToSchema a => ToSchema (IntMap a) where
502508 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
503509
504510#if MIN_VERSION_aeson(1,0,0)
511+instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
512+ declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction k of
513+ ToJSONKeyText _ _ -> declareObjectMapSchema
514+ ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, v)])
515+ where
516+ declareObjectMapSchema = do
517+ schema <- declareSchemaRef (Proxy :: Proxy v)
518+ return $ unnamed $ mempty
519+ & type_ .~ SwaggerObject
520+ & additionalProperties ?~ schema
521+
522+instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
523+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
524+
525+#else
505526
506527instance ToSchema a => ToSchema (Map String a) where
507528 declareNamedSchema _ = do
@@ -517,22 +538,6 @@ instance ToSchema a => ToSchema (HashMap String a) where declareNamedSchema _ =
517538instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
518539instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
519540
520−#else
521−
522−instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (Map k v) where
523− declareNamedSchema _ = case toJSONKey :: ToJSONKeyFunction v of
524− ToJSONKeyText _ _ -> declareObjectMapSchema
525− ToJSONKeyValue _ _ -> declareNamedSchema (Proxy :: Proxy [(k, v)])
526− where
527− declareObjectMapSchema = do
528− schema <- declareSchemaRef (Proxy :: Proxy v)
529− return $ unnamed $ mempty
530− & type_ .~ SwaggerObject
531− & additionalProperties ?~ schema
532−
533−instance (ToJSONKey k, ToSchema k, ToSchema v) => ToSchema (HashMap k v) where
534− declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map k v))
535−
536541#endif
537542
538543instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
swagger2.cabal+2−1
@@ -1,5 +1,5 @@
11name: swagger2
2−version: 2.1.2
2+version: 2.1.3
33synopsis: Swagger 2.0 data model
44description: Please see README.md
55homepage: https://github.com/GetShopTV/swagger2
@@ -58,6 +58,7 @@ library
5858 , transformers
5959 , unordered-containers
6060 , vector
61+ , uuid-types >=1.0.2 && <1.1
6162 default-language: Haskell2010
6263
6364test-suite spec