git.iko.soy/typeable/swagger2
on master help sign in
Add test for sum type with unary ref and record in an alternative
commita3f3747bb1460f95d6f92710b299db10cbbe94f2 authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateWed 25 Nov 2015, 14:45 (11 years ago) parent51d69d3
1 file changed+34−1
test/Data/Swagger/SchemaSpec.hs+34−1
test/Data/Swagger/SchemaSpec.hs+34−1
@@ -3,7 +3,7 @@
33{-# LANGUAGE ScopedTypeVariables #-}
44{-# LANGUAGE TemplateHaskell #-}
55{-# LANGUAGE QuasiQuotes #-}
6−module Data.Swagger.SchemaSpec where
6+module Data.Swagger.SchemaSpec (main, spec) where
77
88import Data.Aeson
99import Data.Aeson.QQ
@@ -44,6 +44,7 @@ spec = do
4444 context "MyRoseTree (datatypeNameModifier)" $ checkToSchema (Proxy :: Proxy MyRoseTree) myRoseTreeSchemaJSON
4545 context "Sum types" $ do
4646 context "Status (sum of unary constructors)" $ checkToSchema (Proxy :: Proxy Status) statusSchemaJSON
47+ context "Character (ref and record sum)" $ checkToSchema (Proxy :: Proxy Character) characterSchemaJSON
4748 context "Schema name" $ do
4849 context "String" $ checkSchemaName Nothing (Proxy :: Proxy String)
4950 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
@@ -334,3 +335,35 @@ unitSchemaJSON = [aesonQQ|
334335}
335336|]
336337
338+
339+-- ========================================================================
340+-- Character (sum type with ref and record in alternative)
341+-- ========================================================================
342+
343+data Character
344+ = PC Player
345+ | NPC { npcName :: String, npcPosition :: Point }
346+ deriving (Generic, ToSchema)
347+
348+characterSchemaJSON :: Value
349+characterSchemaJSON = [aesonQQ|
350+{
351+ "type": "object",
352+ "properties":
353+ {
354+ "PC": { "$ref": "#/definitions/Player" },
355+ "NPC":
356+ {
357+ "type": "object",
358+ "properties":
359+ {
360+ "npcName": { "type": "string" },
361+ "npcPosition": { "$ref": "#/definitions/Point" }
362+ },
363+ "required": ["npcName", "npcPosition"]
364+ }
365+ },
366+ "maxProperties": 1,
367+ "minProperties": 1
368+}
369+|]