git.iko.soy/typeable/openapi3
on master help sign in
Add generic ToParamSchema instance for unit data types
4af4329Nickolay Kudasov
src/Data/Swagger/Internal/ParamSchema.hs+3
@@ -206,6 +206,9 @@ class GToParamSchema (f :: * -> *) where
206instance GToParamSchema f => GToParamSchema (D1 d f) where
206instance GToParamSchema f => GToParamSchema (D1 d f) where
207 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
207 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
208
208
209+instance Constructor c => GToParamSchema (C1 c U1) where
210+ gtoParamSchema = genumParamSchema
211+
209instance GToParamSchema f => GToParamSchema (C1 c (S1 s f)) where
212instance GToParamSchema f => GToParamSchema (C1 c (S1 s f)) where
210 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
213 gtoParamSchema opts _ = gtoParamSchema opts (Proxy :: Proxy f)
211
214
test/Data/Swagger/ParamSchemaSpec.hs+15
@@ -23,6 +23,7 @@ checkToParamSchema proxy js = (toParamSchema proxy :: ParamSchema Param) <=> js
23spec :: Spec
23spec :: Spec
24spec = do
24spec = do
25 describe "Generic ToParamSchema" $ do
25 describe "Generic ToParamSchema" $ do
26+ context "Unit" $ checkToParamSchema (Proxy :: Proxy Unit) unitSchemaJSON
26 context "Color (bounded enum)" $ checkToParamSchema (Proxy :: Proxy Color) colorSchemaJSON
27 context "Color (bounded enum)" $ checkToParamSchema (Proxy :: Proxy Color) colorSchemaJSON
27 context "Status (constructorTagModifier)" $ checkToParamSchema (Proxy :: Proxy Status) statusSchemaJSON
28 context "Status (constructorTagModifier)" $ checkToParamSchema (Proxy :: Proxy Status) statusSchemaJSON
28 context "Unary records" $ do
29 context "Unary records" $ do
@@ -32,6 +33,20 @@ spec = do
32main :: IO ()
33main :: IO ()
33main = hspec spec
34main = hspec spec
34
35
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+
35-- ========================================================================
50-- ========================================================================
36-- Color (enum)
51-- Color (enum)
37-- ========================================================================
52-- ========================================================================