git.iko.soy/typeable/openapi3
on master help sign in
Fix builds for older GHC versions
50038e7Nickolay Kudasov
src/Data/Swagger.hs+17
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1-- |
2-- |
2-- Module: Data.Swagger
3-- Module: Data.Swagger
3-- Maintainer: Nickolay Kudasov <nickolay@getshoptv.com>
4-- Maintainer: Nickolay Kudasov <nickolay@getshoptv.com>
@@ -288,6 +289,21 @@ import Data.Swagger.Internal
288--
289--
289-- we can not derive a valid schema for a mix of the above. The following will result in a type error
290-- we can not derive a valid schema for a mix of the above. The following will result in a type error
290--
291--
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
291-- >>> data BadMixedType = ChoiceBool Bool | JustTag deriving Generic
307-- >>> data BadMixedType = ChoiceBool Bool | JustTag deriving Generic
292-- >>> instance ToSchema BadMixedType
308-- >>> instance ToSchema BadMixedType
293-- ...
309-- ...
@@ -304,6 +320,7 @@ import Data.Swagger.Internal
304-- ... declareNamedSchema
320-- ... declareNamedSchema
305-- ... = Data.Swagger.Internal.Schema.$dmdeclareNamedSchema @BadMixedType
321-- ... = Data.Swagger.Internal.Schema.$dmdeclareNamedSchema @BadMixedType
306-- ... In the instance declaration for ‘ToSchema BadMixedType’
322-- ... In the instance declaration for ‘ToSchema BadMixedType’
323+#endif
307--
324--
308-- We can use 'genericDeclareNamedSchemaUnrestricted' to try our best to represent this type as a Swagger Schema and match 'ToJSON':
325-- We can use 'genericDeclareNamedSchemaUnrestricted' to try our best to represent this type as a Swagger Schema and match 'ToJSON':
309--
326--
src/Data/Swagger/Internal/TypeShape.hs+7
@@ -1,3 +1,4 @@
1+{-# LANGUAGE CPP #-}
1{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE ConstraintKinds #-}
2{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE DataKinds #-}
3{-# LANGUAGE KindSignatures #-}
4{-# LANGUAGE KindSignatures #-}
@@ -36,6 +37,11 @@ type family TypeHasSimpleShape t (f :: Symbol) :: Constraint where
36type family GenericHasSimpleShape t (f :: Symbol) (s :: TypeShape) :: Constraint where
37type family GenericHasSimpleShape t (f :: Symbol) (s :: TypeShape) :: Constraint where
37 GenericHasSimpleShape t f Enumeration = ()
38 GenericHasSimpleShape t f Enumeration = ()
38 GenericHasSimpleShape t f SumOfProducts = ()
39 GenericHasSimpleShape t f SumOfProducts = ()
40+#if __GLASGOW_HASKELL__ < 800
41+ GenericHasSimpleShape t f Mixed = CannotDeriveSchemaForMixedSumType t
42+
43+class CannotDeriveSchemaForMixedSumType t where
44+#else
39 GenericHasSimpleShape t f Mixed =
45 GenericHasSimpleShape t f Mixed =
40 TypeError
46 TypeError
41 ( Text "Cannot derive Generic-based Swagger Schema for " :<>: ShowType t
47 ( Text "Cannot derive Generic-based Swagger Schema for " :<>: ShowType t
@@ -45,6 +51,7 @@ type family GenericHasSimpleShape t (f :: Symbol) (s :: TypeShape) :: Constraint
45 :$$: Text "that matches aeson's Generic-based toJSON,"
51 :$$: Text "that matches aeson's Generic-based toJSON,"
46 :$$: Text "but that's not supported by some Swagger tools."
52 :$$: Text "but that's not supported by some Swagger tools."
47 )
53 )
54+#endif
48
55
49-- | Infer a 'TypeShape' for a generic representation of a type.
56-- | Infer a 'TypeShape' for a generic representation of a type.
50type family GenericShape (g :: * -> *) :: TypeShape
57type family GenericShape (g :: * -> *) :: TypeShape