git.iko.soy/typeable/swagger2
on master help sign in
Add ToParamSchema test with constructorTagModifier
commit3c39be66dccc6db18a9ea6152445f6eda1696924 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateWed 9 Dec 2015, 15:38 (11 years ago) parenta6adc7e
1 file changed+19
test/Data/Swagger/ParamSchemaSpec.hs+19
test/Data/Swagger/ParamSchemaSpec.hs+19
@@ -24,6 +24,7 @@ spec :: Spec
2424spec = do
2525 describe "Generic ToParamSchema" $ do
2626 context "Color (bounded enum)" $ checkToParamSchema (Proxy :: Proxy Color) colorSchemaJSON
27+ context "Status (constructorTagModifier)" $ checkToParamSchema (Proxy :: Proxy Status) statusSchemaJSON
2728 context "Unary records" $ do
2829 context "Email (unary record)" $ checkToParamSchema (Proxy :: Proxy Email) emailSchemaJSON
2930 context "UserId (non-record newtype)" $ checkToParamSchema (Proxy :: Proxy UserId) userIdSchemaJSON
@@ -48,6 +49,24 @@ colorSchemaJSON = [aesonQQ|
4849}
4950|]
5051
52+-- ========================================================================
53+-- Status (constructorTagModifier)
54+-- ========================================================================
55+
56+data Status = StatusOk | StatusError deriving (Generic)
57+
58+instance ToParamSchema Status where
59+ toParamSchema = genericToParamSchema defaultSchemaOptions
60+ { constructorTagModifier = map toLower . drop (length "Status") }
61+
62+statusSchemaJSON :: Value
63+statusSchemaJSON = [aesonQQ|
64+{
65+ "type": "string",
66+ "enum": ["ok", "error"]
67+}
68+|]
69+
5170-- ========================================================================
5271-- Email (newtype with unwrapUnaryRecords set to True)
5372-- ========================================================================