git.iko.soy/typeable/swagger2
on master help sign in
Add test with custom fieldLabelModifier
0703c19Nickolay Kudasov
test/Data/Swagger/SchemaSpec.hs+26
@@ -6,10 +6,13 @@ module Data.Swagger.SchemaSpec where
6
6
7import Data.Aeson
7import Data.Aeson
8import Data.Aeson.QQ
8import Data.Aeson.QQ
9+import Data.Char
9import Data.Proxy
10import Data.Proxy
10import GHC.Generics
11import GHC.Generics
11
12
12import Data.Swagger
13import Data.Swagger
14+import Data.Swagger.Schema
15+
13import SpecCommon
16import SpecCommon
14import Test.Hspec
17import Test.Hspec
15
18
@@ -21,6 +24,7 @@ spec = do
21 describe "Generic ToSchema" $ do
24 describe "Generic ToSchema" $ do
22 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
25 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
23 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
26 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
27+ context "Point (custom fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
24
28
25main :: IO ()
29main :: IO ()
26main = hspec spec
30main = hspec spec
@@ -60,3 +64,25 @@ ispairSchemaJSON = [aesonQQ|
60}
64}
61|]
65|]
62
66
67+data Point = Point
68+ { pointX :: Double
69+ , pointY :: Double
70+ } deriving (Generic)
71+
72+instance ToSchema Point where
73+ toSchema = genericToSchema defaultSchemaOptions
74+ { fieldLabelModifier = map toLower . drop (length "point") }
75+
76+pointSchemaJSON :: Value
77+pointSchemaJSON = [aesonQQ|
78+{
79+ "type": "object",
80+ "properties":
81+ {
82+ "x": { "type": "number" },
83+ "y": { "type": "number" }
84+ },
85+ "required": ["x", "y"]
86+}
87+|]
88+