git.iko.soy/typeable/swagger2
on master help sign in
Merge branch 'master' into bytestring-type-errors
d256763Nickolay Kudasov
.travis.yml+10
@@ -22,10 +22,20 @@ matrix:
22 - env: CABALVER=1.24 GHCVER=8.0.1
22 - env: CABALVER=1.24 GHCVER=8.0.1
23 compiler: ": #GHC 8.0.1"
23 compiler: ": #GHC 8.0.1"
24 addons: {apt: {packages: [cabal-install-1.24,ghc-8.0.1,happy-1.19.5], sources: [hvr-ghc]}}
24 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]}}
25
34
26before_install:
35before_install:
27 - unset CC
36 - unset CC
28 - export PATH=/opt/ghc/$GHCVER/bin:/opt/cabal/$CABALVER/bin:/opt/happy/1.19.5/bin:$PATH
37 - 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
29
39
30install:
40install:
31 - cabal --version
41 - 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+
12.1.2
112.1.2
2---
12---
3
13
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
33import qualified Data.Vector.Storable as VS
33import qualified Data.Vector.Storable as VS
34import qualified Data.Vector.Unboxed as VU
34import qualified Data.Vector.Unboxed as VU
35import Data.Word
35import Data.Word
36+import Data.UUID.Types (UUID)
36
37
37import Data.Swagger.Internal
38import Data.Swagger.Internal
38import Data.Swagger.Lens
39import Data.Swagger.Lens
@@ -243,6 +244,11 @@ instance ToParamSchema () where
243 & type_ .~ SwaggerString
244 & type_ .~ SwaggerString
244 & enum_ ?~ ["_"]
245 & enum_ ?~ ["_"]
245
246
247+instance ToParamSchema UUID where
248+ toParamSchema _ = mempty
249+ & type_ .~ SwaggerString
250+ & format ?~ "uuid"
251+
246-- | A configurable generic @'ParamSchema'@ creator.
252-- | A configurable generic @'ParamSchema'@ creator.
247--
253--
248-- >>> :set -XDeriveGeneric
254-- >>> :set -XDeriveGeneric
src/Data/Swagger/Internal/Schema.hs+21−16
@@ -54,6 +54,7 @@ import qualified Data.Vector.Storable as VS
54import qualified Data.Vector.Unboxed as VU
54import qualified Data.Vector.Unboxed as VU
55import Data.Word
55import Data.Word
56import GHC.Generics
56import GHC.Generics
57+import qualified Data.UUID.Types as UUID
57
58
58import Data.Swagger.Declare
59import Data.Swagger.Declare
59import Data.Swagger.Internal
60import Data.Swagger.Internal
@@ -441,6 +442,11 @@ instance (ToSchema a, ToSchema b) => ToSchema (Either a b)
441instance ToSchema () where
442instance ToSchema () where
442 declareNamedSchema _ = pure (NamedSchema Nothing nullarySchema)
443 declareNamedSchema _ = pure (NamedSchema Nothing nullarySchema)
443
444
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+
444instance (ToSchema a, ToSchema b) => ToSchema (a, b)
450instance (ToSchema a, ToSchema b) => ToSchema (a, b)
445instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
451instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
446instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
452instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
@@ -502,6 +508,21 @@ instance ToSchema a => ToSchema (IntMap a) where
502 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
508 declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [(Int, a)])
503
509
504#if MIN_VERSION_aeson(1,0,0)
510#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
505
526
506instance ToSchema a => ToSchema (Map String a) where
527instance ToSchema a => ToSchema (Map String a) where
507 declareNamedSchema _ = do
528 declareNamedSchema _ = do
@@ -517,22 +538,6 @@ instance ToSchema a => ToSchema (HashMap String a) where declareNamedSchema _ =
517instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
538instance ToSchema a => ToSchema (HashMap T.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
518instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
539instance ToSchema a => ToSchema (HashMap TL.Text a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Map String a))
519
540
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−
536#endif
541#endif
537
542
538instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
543instance ToSchema a => ToSchema (V.Vector a) where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy [a])
swagger2.cabal+2−1
@@ -1,5 +1,5 @@
1name: swagger2
1name: swagger2
2−version: 2.1.2
2+version: 2.1.3
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
@@ -58,6 +58,7 @@ library
58 , transformers
58 , transformers
59 , unordered-containers
59 , unordered-containers
60 , vector
60 , vector
61+ , uuid-types >=1.0.2 && <1.1
61 default-language: Haskell2010
62 default-language: Haskell2010
62
63
63test-suite spec
64test-suite spec