@@ -92,6 +92,7 @@ spec = do
92
92
prop " (Int, String, Double)" $ shouldValidate (Proxy :: Proxy (Int , String , Double ))
93
93
prop " (Int, String, Double, [Int])" $ shouldValidate (Proxy :: Proxy (Int , String , Double , [Int ]))
94
94
prop " (Int, String, Double, [Int], Int)" $ shouldValidate (Proxy :: Proxy (Int , String , Double , [Int ], Int ))
95
+ prop " (String, Paint)" $ shouldValidate (Proxy :: Proxy (String , Paint ))
95
96
prop " Person" $ shouldValidate (Proxy :: Proxy Person )
96
97
prop " Color" $ shouldValidate (Proxy :: Proxy Color )
97
98
prop " Paint" $ shouldValidate (Proxy :: Proxy Paint )
@@ -109,6 +110,8 @@ spec = do
109
110
prop " invalidPaintToJSON" $ shouldNotValidate invalidPaintToJSON
110
111
prop " invalidLightToJSON" $ shouldNotValidate invalidLightToJSON
111
112
prop " invalidButtonImagesToJSON" $ shouldNotValidate invalidButtonImagesToJSON
113
+ prop " invalidStringPersonToJSON" $ shouldNotValidate $ \ (s :: String , p ) ->
114
+ toJSON (s, toInvalidPersonJSON p)
112
115
113
116
main :: IO ()
114
117
main = hspec spec
@@ -128,12 +131,23 @@ instance ToSchema Person
128
131
instance Arbitrary Person where
129
132
arbitrary = Person <$> arbitrary <*> arbitrary <*> arbitrary
130
133
134
+ data InvalidPersonJSON = InvalidPersonJSON
135
+ { invalidName :: String
136
+ , invalidPhone :: Integer
137
+ , invalidEmail :: Maybe String
138
+ } deriving (Show , Generic )
139
+
140
+ instance ToJSON InvalidPersonJSON
141
+
142
+ toInvalidPersonJSON :: Person -> InvalidPersonJSON
143
+ toInvalidPersonJSON Person {.. } = InvalidPersonJSON
144
+ { invalidName = name
145
+ , invalidPhone = phone
146
+ , invalidEmail = email
147
+ }
148
+
131
149
invalidPersonToJSON :: Person -> Value
132
- invalidPersonToJSON Person {.. } = object
133
- [ stringToKey " personName" .= toJSON name
134
- , stringToKey " personPhone" .= toJSON phone
135
- , stringToKey " personEmail" .= toJSON email
136
- ]
150
+ invalidPersonToJSON = toJSON . toInvalidPersonJSON
137
151
138
152
-- ========================================================================
139
153
-- Color (enum)
0 commit comments