git.iko.soy/typeable/swagger2
on master help sign in
Add test with custom fieldLabelModifier
commit0703c199116ce71b8766caca9137f62deefc92ab authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateMon 23 Nov 2015, 18:51 (11 years ago) parent7e27641
1 file changed+26
test/Data/Swagger/SchemaSpec.hs+26
test/Data/Swagger/SchemaSpec.hs+26
@@ -6,10 +6,13 @@ module Data.Swagger.SchemaSpec where
66
77import Data.Aeson
88import Data.Aeson.QQ
9+import Data.Char
910import Data.Proxy
1011import GHC.Generics
1112
1213import Data.Swagger
14+import Data.Swagger.Schema
15+
1316import SpecCommon
1417import Test.Hspec
1518
@@ -21,6 +24,7 @@ spec = do
2124 describe "Generic ToSchema" $ do
2225 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
2326 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
27+ context "Point (custom fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
2428
2529main :: IO ()
2630main = hspec spec
@@ -60,3 +64,25 @@ ispairSchemaJSON = [aesonQQ|
6064}
6165|]
6266
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+