git.iko.soy/typeable/email-validate-extra
on master help sign in
add flag schema
7032ea1odr
email-validate-extra.cabal+8
unifiedsplit
@@ -16,6 +16,11 @@ Flag aeson
16 Default: True
16 Default: True
17 Manual: False
17 Manual: False
18
18
19+Flag schema
20+ Description: Add openapi3 instances to EmailAddress
21+ Default: False
22+ Manual: False
23+
19Flag arbitrary
24Flag arbitrary
20 Description: Add Arbitrary instances to EmailAddress
25 Description: Add Arbitrary instances to EmailAddress
21 Default: True
26 Default: True
@@ -41,6 +46,9 @@ library
41 if flag(aeson)
46 if flag(aeson)
42 build-depends: aeson
47 build-depends: aeson
43 cpp-options: -DAESON
48 cpp-options: -DAESON
49+ if flag(schema)
50+ build-depends: openapi3
51+ cpp-options: -DSCHEMA
44
52
45 exposed-modules: Text.Email.Extra
53 exposed-modules: Text.Email.Extra
46
54
src/Text/Email/Extra.hs+13
@@ -1,5 +1,6 @@
1{-# OPTIONS_GHC -Wno-orphans #-}
1{-# OPTIONS_GHC -Wno-orphans #-}
2{-# LANGUAGE CPP #-}
2{-# LANGUAGE CPP #-}
3+
3module Text.Email.Extra
4module Text.Email.Extra
4 ( validateEmail
5 ( validateEmail
5 , emailToText
6 , emailToText
@@ -24,6 +25,10 @@ import Database.PostgreSQL.Simple.ToField as PG
24import Control.Monad
25import Control.Monad
25import Data.Aeson
26import Data.Aeson
26#endif
27#endif
28+#ifdef SCHEMA
29+import Data.OpenApi
30+import Data.Proxy
31+#endif
27
32
28-- | Validate that the domain part in this email address is
33-- | Validate that the domain part in this email address is
29-- in fact a domain name.
34-- in fact a domain name.
@@ -105,3 +110,11 @@ instance ToJSON EmailAddress where
105instance FromJSON EmailAddress where
110instance FromJSON EmailAddress where
106 parseJSON = parseJSON >=> either fail pure . validateEmail . Text.encodeUtf8
111 parseJSON = parseJSON >=> either fail pure . validateEmail . Text.encodeUtf8
107#endif
112#endif
113+
114+#ifdef SCHEMA
115+instance ToSchema EmailAddress where
116+ declareNamedSchema _ = declareNamedSchema (Proxy :: Proxy Text)
117+
118+instance ToParamSchema EmailAddress where
119+ toParamSchema _ = toParamSchema (Proxy :: Proxy Text)
120+#endif