@@ -8,8 +8,12 @@ module Data.Swagger.SchemaSpec where
88import Data.Aeson
99import Data.Aeson.QQ
1010import Data.Char
11+import qualified Data.HashMap.Strict as HashMap
1112import Data.Proxy
1213import Data.Set (Set)
14+import qualified Data.Set as Set
15+import Data.Text (Text)
16+import qualified Data.Text as Text
1317import GHC.Generics
1418
1519import Data.Swagger
@@ -25,6 +29,13 @@ checkSchemaName sname proxy =
2529 it ("schema name is " ++ show sname) $
2630 schemaName proxy `shouldBe` sname
2731
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+
2839spec :: Spec
2940spec = do
3041 describe "Generic ToSchema" $ do
@@ -51,6 +62,12 @@ spec = do
5162 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
5263 context "Person" $ checkSchemaName (Just "Person") (Proxy :: Proxy Person)
5364 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"]
5471
5572main :: IO ()
5673main = hspec spec