git.iko.soy/typeable/swagger2
on master help sign in
Add TypeError for ByteString ToSchema instances (closes #77)
91de35cNickolay Kudasov
src/Data/Swagger/Internal/Schema.hs+20
@@ -13,6 +13,7 @@
13{-# LANGUAGE TypeFamilies #-}
13{-# LANGUAGE TypeFamilies #-}
14{-# LANGUAGE TypeOperators #-}
14{-# LANGUAGE TypeOperators #-}
15{-# LANGUAGE TypeSynonymInstances #-}
15{-# LANGUAGE TypeSynonymInstances #-}
16+{-# LANGUAGE UndecidableInstances #-}
16#include "overlapping-compat.h"
17#include "overlapping-compat.h"
17module Data.Swagger.Internal.Schema where
18module Data.Swagger.Internal.Schema where
18
19
@@ -65,6 +66,13 @@ import Data.Swagger.SchemaOptions
65import Data.Swagger.Lens (name, schema)
66import Data.Swagger.Lens (name, schema)
66#endif
67#endif
67
68
69+#if __GLASGOW_HASKELL__ < 800
70+#else
71+import qualified Data.ByteString as BS
72+import qualified Data.ByteString.Lazy as BSL
73+import GHC.TypeLits (TypeError, ErrorMessage(..))
74+#endif
75+
68unnamed :: Schema -> NamedSchema
76unnamed :: Schema -> NamedSchema
69unnamed schema = NamedSchema Nothing schema
77unnamed schema = NamedSchema Nothing schema
70
78
@@ -475,6 +483,18 @@ instance ToSchema UTCTime where
475instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
483instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
476instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
484instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
477
485
486+#if __GLASGOW_HASKELL__ < 800
487+#else
488+type family ToSchemaByteStringError bs where
489+ ToSchemaByteStringError bs = TypeError
490+ ( Text "Impossible to have an instance " :<>: ShowType (ToSchema bs) :<>: Text "."
491+ :$$: Text "Please, use a newtype wrapper around " :<>: ShowType bs :<>: Text " instead."
492+ :$$: Text "Consider using byteSchema or binarySchema templates." )
493+
494+instance ToSchemaByteStringError BS.ByteString => ToSchema BS.ByteString where declareNamedSchema = error "impossible"
495+instance ToSchemaByteStringError BSL.ByteString => ToSchema BSL.ByteString where declareNamedSchema = error "impossible"
496+#endif
497+
478instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
498instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
479
499
480-- | NOTE: This schema does not account for the uniqueness of keys.
500-- | NOTE: This schema does not account for the uniqueness of keys.
swagger2.cabal+1
@@ -42,6 +42,7 @@ library
42 build-depends: base >=4.7 && <4.10
42 build-depends: base >=4.7 && <4.10
43 , base-compat >=0.6.0 && <0.10
43 , base-compat >=0.6.0 && <0.10
44 , aeson
44 , aeson
45+ , bytestring
45 , containers
46 , containers
46 , hashable
47 , hashable
47 , generics-sop >=0.2 && <0.3
48 , generics-sop >=0.2 && <0.3