git.iko.soy/typeable/openapi3
on master help sign in
Add TypeError for ByteString ToSchema instances (closes #77)
da4c8d8Nickolay 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#if __GLASGOW_HASKELL__ >= 800
17#if __GLASGOW_HASKELL__ >= 800
17-- Few generics related redundant constraints
18-- Few generics related redundant constraints
18{-# OPTIONS_GHC -Wno-redundant-constraints #-}
19{-# OPTIONS_GHC -Wno-redundant-constraints #-}
@@ -66,6 +67,13 @@ import Data.Swagger.SchemaOptions
66import Data.Swagger.Lens (name, schema)
67import Data.Swagger.Lens (name, schema)
67#endif
68#endif
68
69
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+
69unnamed :: Schema -> NamedSchema
77unnamed :: Schema -> NamedSchema
70unnamed schema = NamedSchema Nothing schema
78unnamed schema = NamedSchema Nothing schema
71
79
@@ -481,6 +489,18 @@ instance ToSchema UTCTime where
481instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
489instance ToSchema T.Text where declareNamedSchema = plain . paramSchemaToSchema
482instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
490instance ToSchema TL.Text where declareNamedSchema = plain . paramSchemaToSchema
483
491
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+
484instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
504instance ToSchema IntSet where declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy (Set Int))
485
505
486-- | NOTE: This schema does not account for the uniqueness of keys.
506-- | 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.9.1 && <0.10
43 , base-compat >=0.9.1 && <0.10
44 , aeson >=0.11.2.1
44 , aeson >=0.11.2.1
45+ , bytestring
45 , containers
46 , containers
46 , hashable
47 , hashable
47 , generics-sop >=0.2 && <0.3
48 , generics-sop >=0.2 && <0.3