git.iko.soy/typeable/swagger2
on master help sign in
Add TypeError for ByteString ToSchema instances (closes #77)
commitda4c8d8d15fc66619751298802fd31866c98dce4 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateSun 4 Sep 2016, 11:57 (10 years ago) parent218f427
2 files changed+21
src/Data/Swagger/Internal/Schema.hs+20 swagger2.cabal+1
src/Data/Swagger/Internal/Schema.hs+20
@@ -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.
swagger2.cabal+1
@@ -42,6 +42,7 @@ library
4242 build-depends: base >=4.7 && <4.10
4343 , base-compat >=0.9.1 && <0.10
4444 , aeson >=0.11.2.1
45+ , bytestring
4546 , containers
4647 , hashable
4748 , generics-sop >=0.2 && <0.3