|
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, "modelOneProp"); |
| 27 | + Assert.assertEquals(composed.vars.get(1).baseName, "properties"); |
| 28 | + Assert.assertEquals(composed.vars.get(2).baseName, "zones"); |
| 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();
|
@@ -47,7 +62,7 @@ public void camelizeNamesTest() {
|
47 | 62 | Assert.assertEquals(codegen.camelize(".foo.bar"), "FooBar");
|
48 | 63 | Assert.assertEquals(codegen.camelize("foo$bar"), "Foo$bar");
|
49 | 64 | Assert.assertEquals(codegen.camelize("foo_$bar"), "Foo$bar");
|
50 |
| - |
| 65 | + |
51 | 66 | Assert.assertEquals(codegen.camelize("foo_bar"), "FooBar");
|
52 | 67 | Assert.assertEquals(codegen.camelize("foo_bar_baz"), "FooBarBaz");
|
53 | 68 | Assert.assertEquals(codegen.camelize("foo/bar.baz"), "FooBarBaz");
|
@@ -232,7 +247,7 @@ public void fileResponeseTest() {
|
232 | 247 | Assert.assertTrue(op.responses.get(0).isFile);
|
233 | 248 | Assert.assertTrue(op.isResponseFile);
|
234 | 249 | }
|
235 |
| - |
| 250 | + |
236 | 251 | @Test(description = "discriminator is present")
|
237 | 252 | public void discriminatorTest() {
|
238 | 253 | final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/discriminatorTest.json");
|
@@ -410,47 +425,47 @@ public void relativeDefinitionsMapInResponseTest() {
|
410 | 425 | Assert.assertTrue(op.imports.contains("PhotoThumbnailsRequest"));
|
411 | 426 |
|
412 | 427 | }
|
413 |
| - |
| 428 | + |
414 | 429 | @Test(description = "use operation consumes and produces")
|
415 | 430 | public void localConsumesAndProducesTest() {
|
416 | 431 | final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/globalConsumesAndProduces.json");
|
417 | 432 | final DefaultCodegen codegen = new DefaultCodegen();
|
418 | 433 | final String path = "/tests/localConsumesAndProduces";
|
419 | 434 | final Operation p = model.getPaths().get(path).getGet();
|
420 | 435 | CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model);
|
421 |
| - |
| 436 | + |
422 | 437 | Assert.assertTrue(op.hasConsumes);
|
423 | 438 | Assert.assertEquals(op.consumes.size(), 1);
|
424 | 439 | Assert.assertEquals(op.consumes.get(0).get("mediaType"), "application/json");
|
425 | 440 | Assert.assertTrue(op.hasProduces);
|
426 | 441 | Assert.assertEquals(op.produces.size(), 1);
|
427 | 442 | Assert.assertEquals(op.produces.get(0).get("mediaType"), "application/json");
|
428 | 443 | }
|
429 |
| - |
| 444 | + |
430 | 445 | @Test(description = "use spec consumes and produces")
|
431 | 446 | public void globalConsumesAndProducesTest() {
|
432 | 447 | final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/globalConsumesAndProduces.json");
|
433 | 448 | final DefaultCodegen codegen = new DefaultCodegen();
|
434 | 449 | final String path = "/tests/globalConsumesAndProduces";
|
435 | 450 | final Operation p = model.getPaths().get(path).getGet();
|
436 | 451 | CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model);
|
437 |
| - |
| 452 | + |
438 | 453 | Assert.assertTrue(op.hasConsumes);
|
439 | 454 | Assert.assertEquals(op.consumes.size(), 1);
|
440 | 455 | Assert.assertEquals(op.consumes.get(0).get("mediaType"), "application/global_consumes");
|
441 | 456 | Assert.assertTrue(op.hasProduces);
|
442 | 457 | Assert.assertEquals(op.produces.size(), 1);
|
443 | 458 | Assert.assertEquals(op.produces.get(0).get("mediaType"), "application/global_produces");
|
444 | 459 | }
|
445 |
| - |
| 460 | + |
446 | 461 | @Test(description = "use operation consumes and produces (reset in operation with empty array)")
|
447 | 462 | public void localResetConsumesAndProducesTest() {
|
448 | 463 | final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/globalConsumesAndProduces.json");
|
449 | 464 | final DefaultCodegen codegen = new DefaultCodegen();
|
450 | 465 | final String path = "/tests/localResetConsumesAndProduces";
|
451 | 466 | final Operation p = model.getPaths().get(path).getGet();
|
452 | 467 | CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions(), model);
|
453 |
| - |
| 468 | + |
454 | 469 | Assert.assertNotNull(op);
|
455 | 470 | Assert.assertFalse(op.hasConsumes);
|
456 | 471 | Assert.assertNull(op.consumes);
|
|
0 commit comments