@@ -1040,6 +1040,80 @@ public void generateSerializableModelWithXimplements() throws Exception {
10401040 );
10411041 }
10421042
1043+ @ Test
1044+ public void generateSerializableModelWithSchemaImplements () 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 (KotlinSpringServerCodegen .SCHEMA_IMPLEMENTS , Map .of (
1053+ "Pet" , "com.some.pack.WithId" ,
1054+ "Category" , List .of ("com.some.pack.CategoryInterface" ),
1055+ "Dog" , List .of ("com.some.pack.Canine" )
1056+ ));
1057+ codegen .additionalProperties ().put (KotlinSpringServerCodegen .SCHEMA_IMPLEMENTS_FIELDS , Map .of (
1058+ "Pet" , List .of ("id" ),
1059+ "Category" , List .of ("name" , "id" ),
1060+ "Dog" , List .of ("bark" , "breed" )
1061+ ));
1062+
1063+ ClientOptInput input = new ClientOptInput ()
1064+ .openAPI (TestUtils .parseSpec ("src/test/resources/3_0/kotlin/petstore-with-x-kotlin-implements.yaml" ))
1065+ .config (codegen );
1066+ DefaultGenerator generator = new DefaultGenerator ();
1067+
1068+ generator .setGeneratorPropertyDefault (CodegenConstants .MODELS , "true" );
1069+ generator .setGeneratorPropertyDefault (CodegenConstants .MODEL_TESTS , "false" );
1070+ generator .setGeneratorPropertyDefault (CodegenConstants .MODEL_DOCS , "false" );
1071+ generator .setGeneratorPropertyDefault (CodegenConstants .APIS , "false" );
1072+ generator .setGeneratorPropertyDefault (CodegenConstants .SUPPORTING_FILES , "false" );
1073+
1074+ generator .opts (input ).generate ();
1075+
1076+ Path dog = Paths .get (outputPath + "/src/main/kotlin/org/openapitools/model/Dog.kt" );
1077+ assertFileContains (
1078+ dog ,
1079+ "@get:JsonProperty(\" bark\" , required = true) override val bark: kotlin.Boolean," ,
1080+ "@get:JsonProperty(\" breed\" , required = true) override val breed: Dog.Breed," ,
1081+ "@get:JsonProperty(\" likesFetch\" , required = true) override val likesFetch: kotlin.Boolean," ,
1082+ "@get:JsonProperty(\" name\" , required = true) override val name: kotlin.String," ,
1083+ "@get:JsonProperty(\" photoUrls\" , required = true) override val photoUrls: kotlin.collections.List<kotlin.String>," ,
1084+ "@get:JsonProperty(\" petType\" , required = true) override val petType: kotlin.String," ,
1085+ "@get:JsonProperty(\" id\" ) override val id: kotlin.Long? = null," ,
1086+ "@get:JsonProperty(\" category\" ) override val category: Category? = null," ,
1087+ "@get:JsonProperty(\" tags\" ) override val tags: kotlin.collections.List<Tag>? = null," ,
1088+ "@get:JsonProperty(\" color\" ) override val color: Color? = null" ,
1089+ ") : Pet, com.some.pack.Canine, com.some.pack.Fetchable, java.io.Serializable {" ,
1090+ "private const val serialVersionUID: kotlin.Long = 1"
1091+ );
1092+
1093+ Path pet = Paths .get (outputPath + "/src/main/kotlin/org/openapitools/model/Pet.kt" );
1094+ assertFileContains (
1095+ pet ,
1096+ "interface Pet : com.some.pack.Named, com.some.pack.WithCategory, com.some.pack.WithDefaultMethods, com.some.pack.WithId, java.io.Serializable {" ,
1097+ "override val name: kotlin.String" ,
1098+ "val photoUrls: kotlin.collections.List<kotlin.String>" ,
1099+ "val petType: kotlin.String" ,
1100+ "override val id: kotlin.Long?" ,
1101+ "override val category: Category?" ,
1102+ "val tags: kotlin.collections.List<Tag>?" ,
1103+ "val color: Color?" ,
1104+ "private const val serialVersionUID: kotlin.Long = 1"
1105+ );
1106+
1107+ Path category = Paths .get (outputPath + "/src/main/kotlin/org/openapitools/model/Category.kt" );
1108+ assertFileContains (
1109+ category ,
1110+ "@get:JsonProperty(\" id\" ) override val id: kotlin.Long? = null," ,
1111+ "@get:JsonProperty(\" name\" ) override val name: kotlin.String? = null" ,
1112+ ") : com.some.pack.CategoryInterface, java.io.Serializable {" ,
1113+ "private const val serialVersionUID: kotlin.Long = 1"
1114+ );
1115+ }
1116+
10431117 @ Test
10441118 public void generateHttpInterfaceReactiveWithReactorResponseEntity () throws Exception {
10451119 File output = Files .createTempDirectory ("test" ).toFile ().getCanonicalFile ();
@@ -1363,8 +1437,9 @@ public void generateNonSerializableModelWithXimplements() throws Exception {
13631437 assertFileNotContains (
13641438 path ,
13651439 "import java.io.Serializable" ,
1366- ") : Pet, Serializable, com.some.pack.Fetchable {" ,
1367- ") : Pet, Serializable {" ,
1440+ "Serializable" ,
1441+ ") : Pet, java.io.Serializable, com.some.pack.Fetchable {" ,
1442+ ") : Pet, java.io.Serializable {" ,
13681443 "private const val serialVersionUID: kotlin.Long = 1"
13691444 );
13701445 }
@@ -2792,7 +2867,7 @@ public void nonReactiveWithResponseEntity() throws Exception {
27922867 + " @PathVariable(\" petId\" ) petId: kotlin.Long"
27932868 + " ): ResponseEntity<Pet>" ),
27942869 root .resolve ("src/main/kotlin/org/openapitools/api/UserApi.kt" ), List .of (
2795- "fun logoutUser(): ResponseEntity<Unit>"
2870+ "fun logoutUser(): ResponseEntity<Unit>"
27962871 ),
27972872 root .resolve ("src/main/kotlin/org/openapitools/api/StoreApi.kt" ), List .of (
27982873 "fun getInventory(): ResponseEntity<Map<String, kotlin.Int>>" )
0 commit comments