git.iko.soy/typeable/swagger2
on master help sign in
Add test for datatypeNameModifier (with recursive data type)
commitc83192339c8dfd57906dae8aafb20cc482b449ff authorNickolay Kudasov <nickolay.kudasov@gmail.com> dateTue 24 Nov 2015, 14:59 (11 years ago) parent0c4a852
1 file changed+34
test/Data/Swagger/SchemaSpec.hs+34
test/Data/Swagger/SchemaSpec.hs+34
@@ -36,6 +36,7 @@ spec = do
3636 context "UserId (non-record newtype)" $ checkToSchema (Proxy :: Proxy UserId) userIdSchemaJSON
3737 context "Player (unary record)" $ checkToSchema (Proxy :: Proxy Player) playerSchemaJSON
3838 context "Players (inlining schema)" $ checkToSchema (Proxy :: Proxy Players) playersSchemaJSON
39+ context "MyRoseTree (datatypeNameModifier)" $ checkToSchema (Proxy :: Proxy MyRoseTree) myRoseTreeSchemaJSON
3940 context "Schema name" $ do
4041 context "String" $ checkSchemaName Nothing (Proxy :: Proxy String)
4142 context "(Int, Float)" $ checkSchemaName Nothing (Proxy :: Proxy (Int, Float))
@@ -188,6 +189,39 @@ playerSchemaJSON = [aesonQQ|
188189}
189190|]
190191
192+-- ========================================================================
193+-- MyRoseTree (custom datatypeNameModifier)
194+-- ========================================================================
195+
196+data MyRoseTree = MyRoseTree
197+ { root :: String
198+ , trees :: [MyRoseTree]
199+ } deriving (Generic)
200+
201+instance ToSchema MyRoseTree where
202+ toNamedSchema = genericToNamedSchema defaultSchemaOptions
203+ { datatypeNameModifier = drop (length "My") }
204+
205+myRoseTreeSchemaJSON :: Value
206+myRoseTreeSchemaJSON = [aesonQQ|
207+{
208+ "type": "object",
209+ "properties":
210+ {
211+ "root": { "type": "string" },
212+ "trees":
213+ {
214+ "type": "array",
215+ "items":
216+ {
217+ "$ref": "#/definitions/RoseTree"
218+ }
219+ }
220+ },
221+ "required": ["root", "trees"]
222+}
223+|]
224+
191225-- ========================================================================
192226-- Inlined (newtype for inlining schemas)
193227-- ========================================================================