@@ -13,6 +13,7 @@
1313{-# LANGUAGE TypeFamilies #-}
1414{-# LANGUAGE TypeOperators #-}
1515{-# LANGUAGE TypeSynonymInstances #-}
16+{-# LANGUAGE UndecidableInstances #-}
1617#include "overlapping-compat.h"
1718module Data.Swagger.Internal.Schema where
1819
@@ -65,6 +66,13 @@ import Data.Swagger.SchemaOptions
6566import Data.Swagger.Lens (name, schema)
6667#endif
6768
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+
6876unnamed :: Schema -> NamedSchema
6977unnamed schema = NamedSchema Nothing schema
7078
@@ -475,6 +483,18 @@ instance ToSchema UTCTime where
475483instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
476484instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
477485
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+
478498instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
479499
480500-- | NOTE: This schema does not account for the uniqueness of keys.