git.iko.soy/typeable/openapi3
on master help sign in
Add a few tests on generic ToSchema Definitions
11c6271Nickolay Kudasov
test/Data/Swagger/SchemaSpec.hs+17
@@ -8,8 +8,12 @@ module Data.Swagger.SchemaSpec where
8import Data.Aeson
8import Data.Aeson
9import Data.Aeson.QQ
9import Data.Aeson.QQ
10import Data.Char
10import Data.Char
11+import qualified Data.HashMap.Strict as HashMap
11import Data.Proxy
12import Data.Proxy
12import Data.Set (Set)
13import Data.Set (Set)
14+import qualified Data.Set as Set
15+import Data.Text (Text)
16+import qualified Data.Text as Text
13import GHC.Generics
17import GHC.Generics
14
18
15import Data.Swagger
19import Data.Swagger
@@ -25,6 +29,13 @@ checkSchemaName sname proxy =
25 it ("schema name is " ++ show sname) $
29 it ("schema name is " ++ show sname) $
26 schemaName proxy `shouldBe` sname
30 schemaName proxy `shouldBe` sname
27
31
32+checkDefs :: ToSchema a => Proxy a -> [String] -> Spec
33+checkDefs proxy names =
34+ it ("uses these definitions " ++ show names) $
35+ Set.fromList (HashMap.keys defs) `shouldBe` Set.fromList (map Text.pack names)
36+ where
37+ defs = fst (toSchemaDefinitions proxy)
38+
28spec :: Spec
39spec :: Spec
29spec = do
40spec = do
30 describe "Generic ToSchema" $ do
41 describe "Generic ToSchema" $ do
@@ -51,6 +62,12 @@ spec = do
51 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
62 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
52 context "Person" $ checkSchemaName (Just "Person") (Proxy :: Proxy Person)
63 context "Person" $ checkSchemaName (Just "Person") (Proxy :: Proxy Person)
53 context "Shade" $ checkSchemaName (Just "Shade") (Proxy :: Proxy Shade)
64 context "Shade" $ checkSchemaName (Just "Shade") (Proxy :: Proxy Shade)
65+ describe "Generic Definitions" $ do
66+ context "Unit" $ checkDefs (Proxy :: Proxy Unit) ["Unit"]
67+ context "Paint" $ checkDefs (Proxy :: Proxy Paint) ["Paint", "Color"]
68+ context "Light" $ checkDefs (Proxy :: Proxy Light) ["Light", "Color"]
69+ context "Character" $ checkDefs (Proxy :: Proxy Character) ["Character", "Player", "Point"]
70+ context "MyRoseTree" $ checkDefs (Proxy :: Proxy MyRoseTree) ["RoseTree"]
54
71
55main :: IO ()
72main :: IO ()
56main = hspec spec
73main = hspec spec