git.iko.soy/typeable/swagger2
on d256763 help sign in
src/Data/Swagger/Internal/ParamSchema.hs+22
since splitsnapshots
unifiedsplit
@@ -1,4 +1,5 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2+{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DefaultSignatures #-}
3{-# LANGUAGE DefaultSignatures #-}
3{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleContexts #-}
4{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE FlexibleInstances #-}
@@ -7,8 +8,10 @@
7{-# LANGUAGE PackageImports #-}
8{-# LANGUAGE PackageImports #-}
8{-# LANGUAGE PolyKinds #-}
9{-# LANGUAGE PolyKinds #-}
9{-# LANGUAGE ScopedTypeVariables #-}
10{-# LANGUAGE ScopedTypeVariables #-}
11+{-# LANGUAGE TypeFamilies #-}
10{-# LANGUAGE TypeOperators #-}
12{-# LANGUAGE TypeOperators #-}
11{-# LANGUAGE TypeSynonymInstances #-}
13{-# LANGUAGE TypeSynonymInstances #-}
14+{-# LANGUAGE UndecidableInstances #-}
12#include "overlapping-compat.h"
15#include "overlapping-compat.h"
13module Data.Swagger.Internal.ParamSchema where
16module Data.Swagger.Internal.ParamSchema where
14
17
@@ -36,6 +39,13 @@ import Data.Swagger.Internal
36import Data.Swagger.Lens
39import Data.Swagger.Lens
37import Data.Swagger.SchemaOptions
40import Data.Swagger.SchemaOptions
38
41
42+#if __GLASGOW_HASKELL__ < 800
43+#else
44+import qualified Data.ByteString as BS
45+import qualified Data.ByteString.Lazy as BSL
46+import GHC.TypeLits (TypeError, ErrorMessage(..))
47+#endif
48+
39-- | Default schema for binary data (any sequence of octets).
49-- | Default schema for binary data (any sequence of octets).
40binaryParamSchema :: ParamSchema t
50binaryParamSchema :: ParamSchema t
41binaryParamSchema = mempty
51binaryParamSchema = mempty
@@ -189,6 +199,18 @@ instance ToParamSchema T.Text where
189instance ToParamSchema TL.Text where
199instance ToParamSchema TL.Text where
190 toParamSchema _ = toParamSchema (Proxy :: Proxy String)
200 toParamSchema _ = toParamSchema (Proxy :: Proxy String)
191
201
202+#if __GLASGOW_HASKELL__ < 800
203+#else
204+type family ToParamSchemaByteStringError bs where
205+ ToParamSchemaByteStringError bs = TypeError
206+ ( Text "Impossible to have an instance " :<>: ShowType (ToParamSchema bs) :<>: Text "."
207+ :$$: Text "Please, use a newtype wrapper around " :<>: ShowType bs :<>: Text " instead."
208+ :$$: Text "Consider using byteParamSchema or binaryParamSchema templates." )
209+
210+instance ToParamSchemaByteStringError BS.ByteString => ToParamSchema BS.ByteString where toParamSchema = error "impossible"
211+instance ToParamSchemaByteStringError BSL.ByteString => ToParamSchema BSL.ByteString where toParamSchema = error "impossible"
212+#endif
213+
192instance ToParamSchema All where toParamSchema _ = toParamSchema (Proxy :: Proxy Bool)
214instance ToParamSchema All where toParamSchema _ = toParamSchema (Proxy :: Proxy Bool)
193instance ToParamSchema Any where toParamSchema _ = toParamSchema (Proxy :: Proxy Bool)
215instance ToParamSchema Any where toParamSchema _ = toParamSchema (Proxy :: Proxy Bool)
194instance ToParamSchema a => ToParamSchema (Sum a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
216instance ToParamSchema a => ToParamSchema (Sum a) where toParamSchema _ = toParamSchema (Proxy :: Proxy a)
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
@@ -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.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