14
14
15
15
public class CodegenTest {
16
16
17
+ @ Test (description = "handle simple composition" )
18
+ public void propertiesInComposedModelTest () {
19
+ final Swagger swagger = parseAndPrepareSwagger ("src/test/resources/2_0/allOfProperties.yaml" );
20
+ final DefaultCodegen codegen = new DefaultCodegen ();
21
+ codegen .supportsInheritance = true ;
22
+ final Model model = swagger .getDefinitions ().get ("RedisResource" );
23
+ CodegenModel composed = codegen .fromModel ("RedisResource" , model , swagger .getDefinitions ());
24
+
25
+ Assert .assertEquals (composed .vars .size (), 3 );
26
+ Assert .assertEquals (composed .vars .get (0 ).baseName , "properties" );
27
+ Assert .assertEquals (composed .vars .get (1 ).baseName , "zones" );
28
+ Assert .assertEquals (composed .vars .get (2 ).baseName , "modelOneProp" );
29
+ Assert .assertNull (composed .parent );
30
+ }
31
+
17
32
@ Test (description = "test sanitizeTag" )
18
33
public void sanitizeTagTest () {
19
34
final DefaultCodegen codegen = new DefaultCodegen ();
@@ -284,9 +299,9 @@ public void simpleInheritanceTest() {
284
299
final Model model = swagger .getDefinitions ().get ("ChildOfSimpleParent" );
285
300
CodegenModel child = codegen .fromModel ("ChildOfSimpleParent" , model , swagger .getDefinitions ());
286
301
287
- Assert .assertEquals (child .vars .size (), 2 );
302
+ Assert .assertEquals (child .vars .size (), 4 );
288
303
Assert .assertEquals (child .vars .get (0 ).baseName , "modelOneProp" );
289
- Assert .assertEquals (child .vars .get (1 ).baseName , "childOfSimpleParentProp" );
304
+ Assert .assertEquals (child .vars .get (3 ).baseName , "childOfSimpleParentProp" );
290
305
Assert .assertEquals (child .parent , "SimpleParent" );
291
306
}
292
307
@@ -298,8 +313,8 @@ public void multiInheritanceTest() {
298
313
final Model model = swagger .getDefinitions ().get ("ChildOfChildOfSimpleParent" );
299
314
CodegenModel child = codegen .fromModel ("ChildOfChildOfSimpleParent" , model , swagger .getDefinitions ());
300
315
301
- Assert .assertEquals (child .vars .size (), 1 );
302
- Assert .assertEquals (child .vars .get (0 ).baseName , "childOfChildOfSimpleParentProp" );
316
+ Assert .assertEquals (child .vars .size (), 5 );
317
+ Assert .assertEquals (child .vars .get (4 ).baseName , "childOfChildOfSimpleParentProp" );
303
318
Assert .assertEquals (child .parent , "ChildOfSimpleParent" );
304
319
}
305
320
@@ -328,8 +343,8 @@ public void supportsMixinsTest() {
328
343
final Model model = swagger .getDefinitions ().get ("ChildOfChildOfSimpleParent" );
329
344
CodegenModel child = codegen .fromModel ("ChildOfChildOfSimpleParent" , model , swagger .getDefinitions ());
330
345
331
- Assert .assertEquals (child .vars .size (), 1 );
332
- Assert .assertEquals (child .vars .get (0 ).baseName , "childOfChildOfSimpleParentProp" );
346
+ Assert .assertEquals (child .vars .size (), 5 );
347
+ Assert .assertEquals (child .vars .get (4 ).baseName , "childOfChildOfSimpleParentProp" );
333
348
Assert .assertEquals (child .allVars .size (), 5 );
334
349
Assert .assertEquals (child .allVars .get (0 ).baseName , "modelOneProp" );
335
350
Assert .assertEquals (child .allVars .get (1 ).baseName , "disc" );
@@ -348,8 +363,8 @@ public void inheritanceOfComposedModelTest() {
348
363
final Model model = swagger .getDefinitions ().get ("ChildOfComposedParent" );
349
364
CodegenModel child = codegen .fromModel ("ChildOfComposedParent" , model , swagger .getDefinitions ());
350
365
351
- Assert .assertEquals (child .vars .size (), 1 );
352
- Assert .assertEquals (child .vars .get (0 ).baseName , "childOfComposedParentProp" );
366
+ Assert .assertEquals (child .vars .size (), 5 );
367
+ Assert .assertEquals (child .vars .get (4 ).baseName , "childOfComposedParentProp" );
353
368
Assert .assertEquals (child .parent , "ComposedParent" );
354
369
}
355
370
@@ -361,8 +376,8 @@ public void multiInheritanceOfComposedModelTest() {
361
376
final Model model = swagger .getDefinitions ().get ("ChildOfChildOfComposedParent" );
362
377
CodegenModel child = codegen .fromModel ("ChildOfChildOfComposedParent" , model , swagger .getDefinitions ());
363
378
364
- Assert .assertEquals (child .vars .size (), 1 );
365
- Assert .assertEquals (child .vars .get (0 ).baseName , "childOfChildOfComposedParentProp" );
379
+ Assert .assertEquals (child .vars .size (), 6 );
380
+ Assert .assertEquals (child .vars .get (5 ).baseName , "childOfChildOfComposedParentProp" );
366
381
Assert .assertEquals (child .parent , "ChildOfComposedParent" );
367
382
}
368
383
0 commit comments