git.iko.soy/typeable/swagger2
on master help sign in
Fix builds for older GHC versions
commit50038e769e3c214cca3e0099dcaece46c44fba51 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateThu 7 Sep 2017, 05:07 (9 years ago) parentda1fc8b
2 files changed+24
src/Data/Swagger.hs+17 src/Data/Swagger/Internal/TypeShape.hs+7
src/Data/Swagger.hs+17
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12-- |
23-- Module: Data.Swagger
34-- Maintainer: Nickolay Kudasov <nickolay@getshoptv.com>
@@ -288,6 +289,21 @@ import Data.Swagger.Internal
288289--
289290-- we can not derive a valid schema for a mix of the above. The following will result in a type error
290291--
292+#if __GLASGOW_HASKELL__ < 800
293+-- >>> data BadMixedType = ChoiceBool Bool | JustTag deriving Generic
294+-- >>> instance ToSchema BadMixedType
295+-- ...
296+-- ... error:
297+-- ... • No instance for (Data.Swagger.Internal.TypeShape.CannotDeriveSchemaForMixedSumType
298+-- ... BadMixedType)
299+-- ... arising from a use of ‘Data.Swagger.Internal.Schema.$dmdeclareNamedSchema’
300+-- ... • In the expression:
301+-- ... Data.Swagger.Internal.Schema.$dmdeclareNamedSchema @BadMixedType
302+-- ... In an equation for ‘declareNamedSchema’:
303+-- ... declareNamedSchema
304+-- ... = Data.Swagger.Internal.Schema.$dmdeclareNamedSchema @BadMixedType
305+-- ... In the instance declaration for ‘ToSchema BadMixedType’
306+#else
291307-- >>> data BadMixedType = ChoiceBool Bool | JustTag deriving Generic
292308-- >>> instance ToSchema BadMixedType
293309-- ...
@@ -304,6 +320,7 @@ import Data.Swagger.Internal
304320-- ... declareNamedSchema
305321-- ... = Data.Swagger.Internal.Schema.$dmdeclareNamedSchema @BadMixedType
306322-- ... In the instance declaration for ‘ToSchema BadMixedType’
323+#endif
307324--
308325-- We can use 'genericDeclareNamedSchemaUnrestricted' to try our best to represent this type as a Swagger Schema and match 'ToJSON':
309326--
src/Data/Swagger/Internal/TypeShape.hs+7
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
12{-# LANGUAGE ConstraintKinds #-}
23{-# LANGUAGE DataKinds #-}
34{-# LANGUAGE KindSignatures #-}
@@ -36,6 +37,11 @@ type family TypeHasSimpleShape t (f :: Symbol) :: Constraint where
3637type family GenericHasSimpleShape t (f :: Symbol) (s :: TypeShape) :: Constraint where
3738 GenericHasSimpleShape t f Enumeration = ()
3839 GenericHasSimpleShape t f SumOfProducts = ()
40+#if __GLASGOW_HASKELL__ < 800
41+ GenericHasSimpleShape t f Mixed = CannotDeriveSchemaForMixedSumType t
42+
43+class CannotDeriveSchemaForMixedSumType t where
44+#else
3945 GenericHasSimpleShape t f Mixed =
4046 TypeError
4147 ( Text "Cannot derive Generic-based Swagger Schema for " :<>: ShowType t
@@ -45,6 +51,7 @@ type family GenericHasSimpleShape t (f :: Symbol) (s :: TypeShape) :: Constraint
4551 :$$: Text "that matches aeson's Generic-based toJSON,"
4652 :$$: Text "but that's not supported by some Swagger tools."
4753 )
54+#endif
4855
4956-- | Infer a 'TypeShape' for a generic representation of a type.
5057type family GenericShape (g :: * -> *) :: TypeShape