@@ -0,0 +1,78 @@
1+{-# LANGUAGE DeriveGeneric #-}
2+{-# LANGUAGE DeriveAnyClass #-}
3+{-# LANGUAGE ScopedTypeVariables #-}
4+{-# LANGUAGE TemplateHaskell #-}
5+{-# LANGUAGE QuasiQuotes #-}
6+module Data.Swagger.ParamSchemaSpec where
20+checkToParamSchema :: ToParamSchema a => Proxy a -> Value -> Spec
21+checkToParamSchema proxy js = (toParamSchema proxy :: ParamSchema Param Items) <=> js
25+ describe "Generic ToParamSchema" $ do
26+ context "Color (bounded enum)" $ checkToParamSchema (Proxy :: Proxy Color) colorSchemaJSON
27+ context "Unary records" $ do
28+ context "Email (unary record)" $ checkToParamSchema (Proxy :: Proxy Email) emailSchemaJSON
29+ context "UserId (non-record newtype)" $ checkToParamSchema (Proxy :: Proxy UserId) userIdSchemaJSON
34+-- ========================================================================
36+-- ========================================================================
41+ deriving (Generic, ToParamSchema)
43+colorSchemaJSON :: Value
44+colorSchemaJSON = [aesonQQ|
47+ "enum": ["Red", "Green", "Blue"]
51+-- ========================================================================
52+-- Email (newtype with unwrapUnaryRecords set to True)
53+-- ========================================================================
55+newtype Email = Email { getEmail :: String }
56+ deriving (Generic, ToParamSchema)
58+emailSchemaJSON :: Value
59+emailSchemaJSON = [aesonQQ|
65+-- ========================================================================
66+-- UserId (non-record newtype)
67+-- ========================================================================
69+newtype UserId = UserId Integer
70+ deriving (Generic, ToParamSchema)
72+userIdSchemaJSON :: Value
73+userIdSchemaJSON = [aesonQQ|