Skip to content

Commit 86def9a

Browse files
committed
add unit tests
1 parent 1597304 commit 86def9a

1 file changed

Lines changed: 74 additions & 1 deletion

File tree

modules/openapi-generator/src/test/java/org/openapitools/codegen/kotlin/spring/KotlinSpringServerCodegenTest.java

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,40 @@ public void generateSerializableModelWithXimplements() throws Exception {
10401040
);
10411041
}
10421042

1043+
@Test
1044+
public void generateSerializableModelWithXimplementsSkip() throws Exception {
1045+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
1046+
output.deleteOnExit();
1047+
String outputPath = output.getAbsolutePath().replace('\\', '/');
1048+
1049+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
1050+
codegen.setOutputDir(output.getAbsolutePath());
1051+
codegen.additionalProperties().put(CodegenConstants.SERIALIZABLE_MODEL, true);
1052+
codegen.additionalProperties().put(X_KOTLIN_IMPLEMENTS_SKIP, List.of("com.some.pack.Fetchable"));
1053+
codegen.additionalProperties().put(X_KOTLIN_IMPLEMENTS_FIELDS_SKIP, Map.of("Dog", List.of("likesFetch")));
1054+
1055+
ClientOptInput input = new ClientOptInput()
1056+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/petstore-with-x-kotlin-implements.yaml"))
1057+
.config(codegen);
1058+
DefaultGenerator generator = new DefaultGenerator();
1059+
1060+
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
1061+
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
1062+
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
1063+
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false");
1064+
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
1065+
1066+
generator.opts(input).generate();
1067+
1068+
Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Dog.kt");
1069+
assertFileContains(
1070+
path,
1071+
"@get:JsonProperty(\"likesFetch\", required = true) val likesFetch: kotlin.Boolean,",
1072+
") : Pet, java.io.Serializable {",
1073+
"private const val serialVersionUID: kotlin.Long = 1"
1074+
);
1075+
}
1076+
10431077
@Test
10441078
public void generateSerializableModelWithSchemaImplements() throws Exception {
10451079
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
@@ -1093,7 +1127,7 @@ public void generateSerializableModelWithSchemaImplements() throws Exception {
10931127
Path pet = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Pet.kt");
10941128
assertFileContains(
10951129
pet,
1096-
"interface Pet : com.some.pack.Named, com.some.pack.WithCategory, com.some.pack.WithDefaultMethods, com.some.pack.WithId, java.io.Serializable {",
1130+
"interface Pet : com.some.pack.Named, com.some.pack.WithCategory, com.some.pack.WithDefaultMethods, com.some.pack.WithId, com.some.pack.WithPhotoUrls, java.io.Serializable {",
10971131
"override val name: kotlin.String",
10981132
"val photoUrls: kotlin.collections.List<kotlin.String>",
10991133
"val petType: kotlin.String",
@@ -1114,6 +1148,45 @@ public void generateSerializableModelWithSchemaImplements() throws Exception {
11141148
);
11151149
}
11161150

1151+
@Test
1152+
public void generateSerializableModelWithXimplementsSkipAndSchemaImplements() throws Exception {
1153+
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
1154+
output.deleteOnExit();
1155+
String outputPath = output.getAbsolutePath().replace('\\', '/');
1156+
1157+
KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen();
1158+
codegen.setOutputDir(output.getAbsolutePath());
1159+
codegen.additionalProperties().put(CodegenConstants.SERIALIZABLE_MODEL, true);
1160+
//remove the old interface with likesFetch attribute here
1161+
codegen.additionalProperties().put(X_KOTLIN_IMPLEMENTS_SKIP, List.of("com.some.pack.Fetchable"));
1162+
codegen.additionalProperties().put(X_KOTLIN_IMPLEMENTS_FIELDS_SKIP, Map.of("Dog", List.of("likesFetch")));
1163+
//and add a new one that again should mark likesFetch as override
1164+
codegen.additionalProperties().put(KotlinSpringServerCodegen.SCHEMA_IMPLEMENTS, Map.of("Dog", List.of("com.some.different.pack.MyOwnFetchable")
1165+
));
1166+
codegen.additionalProperties().put(KotlinSpringServerCodegen.SCHEMA_IMPLEMENTS_FIELDS, Map.of("Dog", List.of("likesFetch")));
1167+
1168+
ClientOptInput input = new ClientOptInput()
1169+
.openAPI(TestUtils.parseSpec("src/test/resources/3_0/kotlin/petstore-with-x-kotlin-implements.yaml"))
1170+
.config(codegen);
1171+
DefaultGenerator generator = new DefaultGenerator();
1172+
1173+
generator.setGeneratorPropertyDefault(CodegenConstants.MODELS, "true");
1174+
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_TESTS, "false");
1175+
generator.setGeneratorPropertyDefault(CodegenConstants.MODEL_DOCS, "false");
1176+
generator.setGeneratorPropertyDefault(CodegenConstants.APIS, "false");
1177+
generator.setGeneratorPropertyDefault(CodegenConstants.SUPPORTING_FILES, "false");
1178+
1179+
generator.opts(input).generate();
1180+
1181+
Path path = Paths.get(outputPath + "/src/main/kotlin/org/openapitools/model/Dog.kt");
1182+
assertFileContains(
1183+
path,
1184+
"@get:JsonProperty(\"likesFetch\", required = true) override val likesFetch: kotlin.Boolean,",
1185+
") : Pet, com.some.different.pack.MyOwnFetchable, java.io.Serializable {",
1186+
"private const val serialVersionUID: kotlin.Long = 1"
1187+
);
1188+
}
1189+
11171190
@Test
11181191
public void generateHttpInterfaceReactiveWithReactorResponseEntity() throws Exception {
11191192
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();

0 commit comments

Comments
 (0)