@@ -13,6 +13,7 @@
1313{-# LANGUAGE TypeFamilies #-}
1414{-# LANGUAGE TypeOperators #-}
1515{-# LANGUAGE TypeSynonymInstances #-}
16+{-# LANGUAGE UndecidableInstances #-}
1617#if __GLASGOW_HASKELL__ >= 800
1718-- Few generics related redundant constraints
1819{-# OPTIONS_GHC -Wno-redundant-constraints #-}
@@ -66,6 +67,13 @@ import Data.Swagger.SchemaOptions
6667import Data.Swagger.Lens (name, schema)
6768#endif
6869
70+#if __GLASGOW_HASKELL__ < 800
71+#else
72+import qualified Data.ByteString as BS
73+import qualified Data.ByteString.Lazy as BSL
74+import GHC.TypeLits (TypeError, ErrorMessage(..))
75+#endif
76+
6977unnamed :: Schema -> NamedSchema
7078unnamed schema = NamedSchema Nothing schema
7179
@@ -481,6 +489,18 @@ instance ToSchema UTCTime where
481489instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
482490instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
483491
492+#if __GLASGOW_HASKELL__ < 800
493+#else
494+type family ToSchemaByteStringError bs where
495+ ToSchemaByteStringError bs = TypeError
496+ ( Text "Impossible to have an instance " :<>: ShowType (ToSchema bs) :<>: Text "."
497+ :$$: Text "Please, use a newtype wrapper around " :<>: ShowType bs :<>: Text " instead."
498+ :$$: Text "Consider using byteSchema or binarySchema templates." )
499+
500+instance ToSchemaByteStringError BS.ByteString => ToSchema BS.ByteString where declareNamedSchema = error "impossible"
501+instance ToSchemaByteStringError BSL.ByteString => ToSchema BSL.ByteString where declareNamedSchema = error "impossible"
502+#endif
503+
484504instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
485505
486506-- | NOTE: This schema does not account for the uniqueness of keys.