git.iko.soy/typeable/openapi3
on master help sign in
Add tests for different SumEncoding flavors
55662c8Maxim Koltsov
test/Data/Swagger/Schema/ValidationSpec.hs+30
@@ -91,6 +91,8 @@ spec = do
91 prop "Paint" $ shouldValidate (Proxy :: Proxy Paint)
91 prop "Paint" $ shouldValidate (Proxy :: Proxy Paint)
92 prop "MyRoseTree" $ shouldValidate (Proxy :: Proxy MyRoseTree)
92 prop "MyRoseTree" $ shouldValidate (Proxy :: Proxy MyRoseTree)
93 prop "Light" $ shouldValidate (Proxy :: Proxy Light)
93 prop "Light" $ shouldValidate (Proxy :: Proxy Light)
94+ prop "Light TaggedObject" $ shouldValidate (Proxy :: Proxy LightTaggedObject)
95+ prop "Light UntaggedValue" $ shouldValidate (Proxy :: Proxy LightUntaggedValue)
94 prop "ButtonImages" $ shouldValidate (Proxy :: Proxy ButtonImages)
96 prop "ButtonImages" $ shouldValidate (Proxy :: Proxy ButtonImages)
95 prop "Version" $ shouldValidate (Proxy :: Proxy Version)
97 prop "Version" $ shouldValidate (Proxy :: Proxy Version)
96 prop "FreeForm" $ shouldValidate (Proxy :: Proxy FreeForm)
98 prop "FreeForm" $ shouldValidate (Proxy :: Proxy FreeForm)
@@ -203,6 +205,34 @@ instance Arbitrary Light where
203invalidLightToJSON :: Light -> Value
205invalidLightToJSON :: Light -> Value
204invalidLightToJSON = genericToJSON defaultOptions
206invalidLightToJSON = genericToJSON defaultOptions
205
207
208+-- Check all SumEncoding flavors.
209+
210+newtype LightTaggedObject = LightTaggedObject Light
211+ deriving (Show)
212+
213+instance ToJSON LightTaggedObject where
214+ toJSON (LightTaggedObject light) = genericToJSON defaultOptions { Data.Aeson.Types.sumEncoding = defaultTaggedObject } light
215+
216+instance ToSchema LightTaggedObject where
217+ declareNamedSchema _ =
218+ genericDeclareNamedSchema defaultSchemaOptions { Data.Swagger.sumEncoding = defaultTaggedObject } (Proxy :: Proxy Light)
219+
220+instance Arbitrary LightTaggedObject where
221+ arbitrary = LightTaggedObject <$> arbitrary
222+
223+newtype LightUntaggedValue = LightUntaggedValue Light
224+ deriving (Show)
225+
226+instance ToJSON LightUntaggedValue where
227+ toJSON (LightUntaggedValue light) = genericToJSON defaultOptions { Data.Aeson.Types.sumEncoding = UntaggedValue } light
228+
229+instance ToSchema LightUntaggedValue where
230+ declareNamedSchema _ =
231+ genericDeclareNamedSchema defaultSchemaOptions { Data.Swagger.sumEncoding = UntaggedValue } (Proxy :: Proxy Light)
232+
233+instance Arbitrary LightUntaggedValue where
234+ arbitrary = LightUntaggedValue <$> arbitrary
235+
206-- ========================================================================
236-- ========================================================================
207-- ButtonImages (bounded enum key mapping)
237-- ButtonImages (bounded enum key mapping)
208-- ========================================================================
238-- ========================================================================