git.iko.soy/typeable/email-validate-extra
on master help sign in
add flag schema
commit7032ea115325f8290fceead054d36d6eb7d340bb authorodr <dima@typeable.io> dateWed 14 May 2025, 15:30 (1 year ago) parent3dda01c
2 files changed+21
unifiedsplit
email-validate-extra.cabal+8 src/Text/Email/Extra.hs+13
email-validate-extra.cabal+8
@@ -16,6 +16,11 @@ Flag aeson
1616 Default: True
1717 Manual: False
1818
19+Flag schema
20+ Description: Add openapi3 instances to EmailAddress
21+ Default: False
22+ Manual: False
23+
1924Flag arbitrary
2025 Description: Add Arbitrary instances to EmailAddress
2126 Default: True
@@ -41,6 +46,9 @@ library
4146 if flag(aeson)
4247 build-depends: aeson
4348 cpp-options: -DAESON
49+ if flag(schema)
50+ build-depends: openapi3
51+ cpp-options: -DSCHEMA
4452
4553 exposed-modules: Text.Email.Extra
4654
src/Text/Email/Extra.hs+13
@@ -1,5 +1,6 @@
11{-# OPTIONS_GHC -Wno-orphans #-}
22{-# LANGUAGE CPP #-}
3+
34module Text.Email.Extra
45 ( validateEmail
56 , emailToText
@@ -24,6 +25,10 @@ import Database.PostgreSQL.Simple.ToField as PG
2425import Control.Monad
2526import Data.Aeson
2627#endif
28+#ifdef SCHEMA
29+import Data.OpenApi
30+import Data.Proxy
31+#endif
2732
2833-- | Validate that the domain part in this email address is
2934-- in fact a domain name.
@@ -105,3 +110,11 @@ instance ToJSON EmailAddress where
105110instance FromJSON EmailAddress where
106111 parseJSON = parseJSON >=> either fail pure . validateEmail . Text.encodeUtf8
107112#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