Skip to content

Commit a24b14b

Browse files
committed
polymorphism java tests
1 parent 305249e commit a24b14b

File tree

9 files changed

+874
-0
lines changed

9 files changed

+874
-0
lines changed

modules/swagger-codegen/src/test/java/io/swagger/codegen/v3/service/GeneratorServiceTest.java

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,206 @@ public void testGeneratorServiceTypescriptAngular3() {
832832
Assert.assertFalse(files.isEmpty());
833833
}
834834

835+
/*
836+
* testIssue605 testIssue612_CC27814 testIssue613_CC27916 testIssue613_CC27916
837+
*
838+
* to obtain a runnable server via jetty:run, in generated server code, replace the following files
839+
* with the ones in src/test/resources/3_0_0/issue-605/sertemplate
840+
*
841+
* pom.xml
842+
* web.xml
843+
* RestApplication.java
844+
* InventoryApi.java
845+
*
846+
*
847+
*/
848+
@Test
849+
public void testIssue605() throws IOException {
850+
String path = getTmpFolder().getAbsolutePath() + "/client";
851+
path = new File("/dati/dev/progetti/swagger/issue-206/client").getAbsolutePath();
852+
GenerationRequest request = new GenerationRequest();
853+
request
854+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
855+
.type(GenerationRequest.Type.CLIENT)
856+
.lang("java")
857+
.spec(loadSpecAsNode("3_0_0/issue-605/swagger.yaml", true, false))
858+
.options(
859+
new Options()
860+
.outputDir(path)
861+
.library("resteasy")
862+
.addAdditionalProperty("dateLibray", "time4j")
863+
864+
);
865+
List<File> files = new GeneratorService().generationRequest(request).generate();
866+
Assert.assertFalse(files.isEmpty());
867+
System.out.println("Generated client in:\n" + path);
868+
path = getTmpFolder().getAbsolutePath() + "/server";
869+
path = new File("/dati/dev/progetti/swagger/issue-206/server").getAbsolutePath();
870+
request = new GenerationRequest();
871+
request
872+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
873+
.type(GenerationRequest.Type.SERVER)
874+
.lang("jaxrs-resteasy")
875+
.spec(loadSpecAsNode("3_0_0/issue-605/swagger.yaml", true, false))
876+
.options(
877+
new Options()
878+
.outputDir(path)
879+
880+
);
881+
files = new GeneratorService().generationRequest(request).generate();
882+
Assert.assertFalse(files.isEmpty());
883+
System.out.println("Generated server in:\n" + path);
884+
}
885+
886+
@Test
887+
public void testIssue612_CC27814() throws IOException {
888+
889+
String path = getTmpFolder().getAbsolutePath() + "/server";
890+
path = new File("/dati/dev/progetti/swagger/CC-27814/server").getAbsolutePath();
891+
GenerationRequest request = new GenerationRequest();
892+
request
893+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
894+
.type(GenerationRequest.Type.SERVER)
895+
.lang("jaxrs-resteasy")
896+
.spec(loadSpecAsNode("3_0_0/issue-612/cc-27814.yaml", true, false))
897+
.options(
898+
new Options()
899+
.outputDir(path)
900+
);
901+
List<File> files = new GeneratorService().generationRequest(request).generate();
902+
Assert.assertFalse(files.isEmpty());
903+
System.out.println("Generated server in:\n" + path);
904+
905+
path = getTmpFolder().getAbsolutePath() + "/client";
906+
path = new File("/dati/dev/progetti/swagger/CC-27814/client").getAbsolutePath();
907+
request = new GenerationRequest();
908+
request
909+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
910+
.type(GenerationRequest.Type.CLIENT)
911+
.lang("java")
912+
.spec(loadSpecAsNode("3_0_0/issue-612/cc-27814.yaml", true, false))
913+
.options(
914+
new Options()
915+
.outputDir(path)
916+
.library("resteasy")
917+
.addAdditionalProperty("dateLibray", "time4j")
918+
919+
);
920+
files = new GeneratorService().generationRequest(request).generate();
921+
Assert.assertFalse(files.isEmpty());
922+
System.out.println("Generated client in:\n" + path);
923+
}
924+
925+
@Test
926+
public void testIssue613_CC27916() throws IOException {
927+
928+
String path = getTmpFolder().getAbsolutePath() + "/client";
929+
path = new File("/dati/dev/progetti/swagger/CC-27986/client").getAbsolutePath();
930+
GenerationRequest request = new GenerationRequest();
931+
request
932+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
933+
.type(GenerationRequest.Type.CLIENT)
934+
.lang("java")
935+
.spec(loadSpecAsNode("3_0_0/issue-613/cc-27916.yaml", true, false))
936+
.options(
937+
new Options()
938+
.outputDir(path)
939+
);
940+
List<File> files = new GeneratorService().generationRequest(request).generate();
941+
Assert.assertFalse(files.isEmpty());
942+
System.out.println("Generated client in:\n" + path);
943+
944+
path = getTmpFolder().getAbsolutePath() + "/server";
945+
path = new File("/dati/dev/progetti/swagger/CC-27986/server").getAbsolutePath();
946+
request = new GenerationRequest();
947+
request
948+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
949+
.type(GenerationRequest.Type.SERVER)
950+
.lang("jaxrs-resteasy")
951+
.spec(loadSpecAsNode("3_0_0/issue-613/cc-27916.yaml", true, false))
952+
.options(
953+
new Options()
954+
.outputDir(path)
955+
956+
);
957+
files = new GeneratorService().generationRequest(request).generate();
958+
Assert.assertFalse(files.isEmpty());
959+
System.out.println("Generated server in:\n" + path);
960+
}
961+
962+
@Test
963+
public void testIssue613_605_612() throws IOException {
964+
965+
String path = getTmpFolder().getAbsolutePath() + "/client";
966+
path = new File("/dati/dev/progetti/swagger/polycodegen/client").getAbsolutePath();
967+
GenerationRequest request = new GenerationRequest();
968+
request
969+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
970+
.type(GenerationRequest.Type.CLIENT)
971+
.lang("java")
972+
.spec(loadSpecAsNode("3_0_0/issue-605-612-613/swagger.yaml", true, false))
973+
.options(
974+
new Options()
975+
.outputDir(path)
976+
);
977+
List<File> files = new GeneratorService().generationRequest(request).generate();
978+
Assert.assertFalse(files.isEmpty());
979+
System.out.println("Generated client in:\n" + path);
980+
981+
path = getTmpFolder().getAbsolutePath() + "/server";
982+
path = new File("/dati/dev/progetti/swagger/polycodegen/server").getAbsolutePath();
983+
request = new GenerationRequest();
984+
request
985+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
986+
.type(GenerationRequest.Type.SERVER)
987+
.lang("jaxrs-resteasy")
988+
.spec(loadSpecAsNode("3_0_0/issue-605-612-613/swagger.yaml", true, false))
989+
.options(
990+
new Options()
991+
.outputDir(path)
992+
993+
);
994+
files = new GeneratorService().generationRequest(request).generate();
995+
Assert.assertFalse(files.isEmpty());
996+
System.out.println("Generated server in:\n" + path);
997+
}
998+
999+
@Test
1000+
public void testIssue613_605_612_non_resteasy() throws IOException {
1001+
1002+
String path = getTmpFolder().getAbsolutePath() + "/clientdefault";
1003+
path = new File("/dati/dev/progetti/swagger/polycodegendefault/client").getAbsolutePath();
1004+
GenerationRequest request = new GenerationRequest();
1005+
request
1006+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
1007+
.type(GenerationRequest.Type.CLIENT)
1008+
.lang("java")
1009+
.spec(loadSpecAsNode("3_0_0/issue-605-612-613/swagger.yaml", true, false))
1010+
.options(
1011+
new Options()
1012+
.outputDir(path)
1013+
);
1014+
List<File> files = new GeneratorService().generationRequest(request).generate();
1015+
Assert.assertFalse(files.isEmpty());
1016+
System.out.println("Generated client in:\n" + path);
1017+
1018+
path = getTmpFolder().getAbsolutePath() + "/server";
1019+
path = new File("/dati/dev/progetti/swagger/polycodegendefault/serverdefault").getAbsolutePath();
1020+
request = new GenerationRequest();
1021+
request
1022+
.codegenVersion(GenerationRequest.CodegenVersion.V3)
1023+
.type(GenerationRequest.Type.SERVER)
1024+
.lang("jaxrs-jersey")
1025+
.spec(loadSpecAsNode("3_0_0/issue-605-612-613/swagger.yaml", true, false))
1026+
.options(
1027+
new Options()
1028+
.outputDir(path)
1029+
1030+
);
1031+
files = new GeneratorService().generationRequest(request).generate();
1032+
Assert.assertFalse(files.isEmpty());
1033+
System.out.println("Generated server in:\n" + path);
1034+
}
8351035
protected static File getTmpFolder() {
8361036
try {
8371037
File outputFolder = Files.createTempFile("codegentest-", "-tmp").toFile();
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
openapi: 3.0.1
2+
info:
3+
title: OpenAPI definition
4+
version: v0
5+
servers:
6+
- url: http://localhost:8080
7+
description: Generated server url
8+
paths:
9+
/list:
10+
get:
11+
tags:
12+
- demo-controller
13+
operationId: epList
14+
responses:
15+
'200':
16+
description: OK
17+
content:
18+
'*/*':
19+
schema:
20+
type: array
21+
items:
22+
oneOf:
23+
- $ref: '#/components/schemas/ClassA'
24+
- $ref: '#/components/schemas/ClassB'
25+
/c:
26+
get:
27+
tags:
28+
- demo-controller
29+
operationId: epC
30+
responses:
31+
'200':
32+
description: OK
33+
content:
34+
'*/*':
35+
schema:
36+
oneOf:
37+
- $ref: '#/components/schemas/ClassA'
38+
- $ref: '#/components/schemas/ClassB'
39+
/d:
40+
get:
41+
tags:
42+
- demo-controller
43+
operationId: epD
44+
requestBody:
45+
description: Inventory item to add
46+
content:
47+
application/json:
48+
schema:
49+
$ref: '#/components/schemas/ClassAorB'
50+
responses:
51+
'200':
52+
description: OK
53+
content:
54+
'*/*':
55+
schema:
56+
oneOf:
57+
- $ref: '#/components/schemas/ClassA'
58+
- $ref: '#/components/schemas/ClassB'
59+
'202':
60+
description: OK
61+
content:
62+
'*/*':
63+
schema:
64+
$ref: '#/components/schemas/ClassAorB'
65+
/b:
66+
get:
67+
tags:
68+
- demo-controller
69+
operationId: epB
70+
responses:
71+
'200':
72+
description: OK
73+
content:
74+
'*/*':
75+
schema:
76+
$ref: '#/components/schemas/ClassB'
77+
/a:
78+
get:
79+
tags:
80+
- demo-controller
81+
operationId: epA
82+
responses:
83+
'200':
84+
description: OK
85+
content:
86+
'*/*':
87+
schema:
88+
$ref: '#/components/schemas/ClassA'
89+
components:
90+
schemas:
91+
ClassA:
92+
required:
93+
- bId
94+
- type
95+
type: object
96+
allOf:
97+
- $ref: '#/components/schemas/InterfaceC'
98+
- type: object
99+
properties:
100+
onlyInA:
101+
type: string
102+
ClassB:
103+
required:
104+
- bId
105+
- type
106+
type: object
107+
allOf:
108+
- $ref: '#/components/schemas/InterfaceC'
109+
InterfaceC:
110+
type: object
111+
properties:
112+
currentTime:
113+
type: string
114+
type:
115+
type: string
116+
discriminator:
117+
propertyName: type
118+
ClassAorB:
119+
discriminator:
120+
propertyName: type
121+
oneOf:
122+
- $ref: '#/components/schemas/ClassA'
123+
- $ref: '#/components/schemas/ClassB'

0 commit comments

Comments
 (0)