git.iko.soy/typeable/openapi3
on master help sign in
Add generic ToParamSchema instance for unit data types
commit4af4329bc5798245f651156d475b6d686cdd1cab authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateFri 15 Jan 2016, 23:39 (11 years ago) parent41a2619
2 files changed+18
src/Data/Swagger/Internal/ParamSchema.hs+3 test/Data/Swagger/ParamSchemaSpec.hs+15
src/Data/Swagger/Internal/ParamSchema.hs+3
@@ -206,6 +206,9 @@ class GToParamSchema (f :: * -> *) where
206206instance GToParamSchema f => GToParamSchema (D1 d f) where
207207 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
208208
209+instance Constructor c => GToParamSchema (C1 c U1) where
210+ gtoParamSchema = genumParamSchema
211+
209212instance GToParamSchema f => GToParamSchema (C1 c (S1 s f)) where
210213 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
211214
test/Data/Swagger/ParamSchemaSpec.hs+15
@@ -23,6 +23,7 @@ checkToParamSchema proxy js = (toParamSchema proxy :: ParamSchema Param) <=> js
2323spec :: Spec
2424spec = do
2525 describe "Generic ToParamSchema" $ do
26+ context "Unit" $ checkToParamSchema (Proxy :: Proxy Unit) unitSchemaJSON
2627 context "Color (bounded enum)" $ checkToParamSchema (Proxy :: Proxy Color) colorSchemaJSON
2728 context "Status (constructorTagModifier)" $ checkToParamSchema (Proxy :: Proxy Status) statusSchemaJSON
2829 context "Unary records" $ do
@@ -32,6 +33,20 @@ spec = do
3233main :: IO ()
3334main = hspec spec
3435
36+-- ========================================================================
37+-- Unit type
38+-- ========================================================================
39+
40+data Unit = Unit deriving (Generic, ToParamSchema)
41+
42+unitSchemaJSON :: Value
43+unitSchemaJSON = [aesonQQ|
44+{
45+ "type": "string",
46+ "enum": ["Unit"]
47+}
48+|]
49+
3550-- ========================================================================
3651-- Color (enum)
3752-- ========================================================================