git.iko.soy/typeable/openapi3
on master help sign in
Add support for unit types (e.g. ())
3e75720Nickolay Kudasov
src/Data/Swagger/Schema/Internal.hs+9
@@ -94,6 +94,7 @@ instance ToSchema Float where
94instance ToSchema a => ToSchema (Maybe a) where
94instance ToSchema a => ToSchema (Maybe a) where
95 toNamedSchema _ = unnamed $ toSchema (Proxy :: Proxy a)
95 toNamedSchema _ = unnamed $ toSchema (Proxy :: Proxy a)
96
96
97+instance ToSchema ()
97instance (ToSchema a, ToSchema b) => ToSchema (a, b)
98instance (ToSchema a, ToSchema b) => ToSchema (a, b)
98instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
99instance (ToSchema a, ToSchema b, ToSchema c) => ToSchema (a, b, c)
99instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
100instance (ToSchema a, ToSchema b, ToSchema c, ToSchema d) => ToSchema (a, b, c, d)
@@ -188,6 +189,14 @@ gdatatypeSchemaName opts _ = case name of
188 where
189 where
189 name = datatypeNameModifier opts (datatypeName (Proxy3 :: Proxy3 d f a))
190 name = datatypeNameModifier opts (datatypeName (Proxy3 :: Proxy3 d f a))
190
191
192+nullarySchema :: Schema
193+nullarySchema = mempty
194+ & schemaType .~ SchemaArray
195+ & schemaEnum ?~ [ toJSON () ]
196+
197+instance GToSchema U1 where
198+ gtoNamedSchema _ _ _ = unnamed nullarySchema
199+
191instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
200instance (GToSchema f, GToSchema g) => GToSchema (f :*: g) where
192 gtoNamedSchema opts _ = unnamed . gtoSchema opts (Proxy :: Proxy f) . gtoSchema opts (Proxy :: Proxy g)
201 gtoNamedSchema opts _ = unnamed . gtoSchema opts (Proxy :: Proxy f) . gtoSchema opts (Proxy :: Proxy g)
193
202
test/Data/Swagger/SchemaSpec.hs+15
@@ -29,6 +29,7 @@ checkSchemaName name proxy =
29spec :: Spec
29spec :: Spec
30spec = do
30spec = do
31 describe "Generic ToSchema" $ do
31 describe "Generic ToSchema" $ do
32+ context "Unit" $ checkToSchema (Proxy :: Proxy Unit) unitSchemaJSON
32 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
33 context "Person" $ checkToSchema (Proxy :: Proxy Person) personSchemaJSON
33 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
34 context "ISPair" $ checkToSchema (Proxy :: Proxy ISPair) ispairSchemaJSON
34 context "Point (fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
35 context "Point (fieldLabelModifier)" $ checkToSchema (Proxy :: Proxy Point) pointSchemaJSON
@@ -324,3 +325,17 @@ statusSchemaJSON = [aesonQQ|
324}
325}
325|]
326|]
326
327
328+-- ========================================================================
329+-- Unit type
330+-- ========================================================================
331+
332+data Unit = Unit deriving (Generic, ToSchema)
333+
334+unitSchemaJSON :: Value
335+unitSchemaJSON = [aesonQQ|
336+{
337+ "type": "array",
338+ "enum": [[]]
339+}
340+|]
341+