@@ -1064,6 +1064,73 @@ public void generateNonSerializableModelWithXimplements() throws Exception {
10641064 );
10651065 }
10661066
1067+ @ Test
1068+ public void generateModelWithRequiredFalseWithDefaults () throws Exception {
1069+ File output = Files .createTempDirectory ("test" ).toFile ().getCanonicalFile ();
1070+ output .deleteOnExit ();
1071+ String outputPath = output .getAbsolutePath ().replace ('\\' , '/' );
1072+
1073+ KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen ();
1074+ codegen .setOutputDir (output .getAbsolutePath ());
1075+ codegen .additionalProperties ().put (CodegenConstants .SERIALIZABLE_MODEL , true );
1076+
1077+ ClientOptInput input = new ClientOptInput ()
1078+ .openAPI (TestUtils .parseSpec ("src/test/resources/3_0/kotlin/petstore-with-x-kotlin-implements.yaml" ))
1079+ .config (codegen );
1080+ DefaultGenerator generator = new DefaultGenerator ();
1081+
1082+ generator .setGeneratorPropertyDefault (CodegenConstants .MODELS , "true" );
1083+ generator .setGeneratorPropertyDefault (CodegenConstants .MODEL_TESTS , "false" );
1084+ generator .setGeneratorPropertyDefault (CodegenConstants .MODEL_DOCS , "false" );
1085+ generator .setGeneratorPropertyDefault (CodegenConstants .APIS , "false" );
1086+ generator .setGeneratorPropertyDefault (CodegenConstants .SUPPORTING_FILES , "false" );
1087+
1088+ generator .opts (input ).generate ();
1089+
1090+ Path dogPath = Paths .get (outputPath + "/src/main/kotlin/org/openapitools/model/Dog.kt" );
1091+ assertFileContains (
1092+ dogPath ,
1093+ "@get:JsonProperty(\" category\" , required = false)" ,
1094+ "override val category: Category? = null" , // without default (fallback) value is nullable
1095+ "@get:JsonProperty(\" nonRequiredWithDefaultList\" , required = false)" ,
1096+ "override val nonRequiredWithDefaultList: kotlin.collections.List<kotlin.String> = arrayListOf()" , // elsewhere with default (fallback) value is not nullable
1097+ "@get:JsonProperty(\" nonRequiredWithDefaultSet\" , required = false)" ,
1098+ "override val nonRequiredWithDefaultSet: kotlin.collections.Set<kotlin.String> = setOf()" ,
1099+ "@get:JsonProperty(\" nonRequiredWithDefaultString\" , required = false)" ,
1100+ "override val nonRequiredWithDefaultString: kotlin.String = \" defaultValue\" " ,
1101+ "@get:JsonProperty(\" nonRequiredWithDefaultInt\" , required = false)" ,
1102+ "override val nonRequiredWithDefaultInt: java.math.BigDecimal = java.math.BigDecimal(\" 15\" )" ,
1103+ "@get:JsonProperty(\" nonRequiredWithDefaultLong\" , required = false)" ,
1104+ "override val nonRequiredWithDefaultLong: java.math.BigDecimal = java.math.BigDecimal(\" 15\" )" ,
1105+ "@get:JsonProperty(\" nonRequiredWithDefaultFloat\" , required = false)" ,
1106+ "override val nonRequiredWithDefaultFloat: kotlin.Float = 15.45f" ,
1107+ "@get:JsonProperty(\" nonRequiredWithDefaultDouble\" , required = false)" ,
1108+ "override val nonRequiredWithDefaultDouble: kotlin.Double = 15.45" ,
1109+ "@get:JsonProperty(\" nonRequiredWithDefaultEnum\" , required = false)" ,
1110+ "override val nonRequiredWithDefaultEnum: Dog.NonRequiredWithDefaultEnum = NonRequiredWithDefaultEnum.THIS" ,
1111+ "@get:JsonProperty(\" nonRequiredWithDefaultEnumList\" , required = false)" ,
1112+ "override val nonRequiredWithDefaultEnumList: kotlin.collections.List<Dog.NonRequiredWithDefaultEnumList> = arrayListOf(NonRequiredWithDefaultEnumList.THESE,NonRequiredWithDefaultEnumList.THOSE)" ,
1113+ "@get:JsonProperty(\" nonRequiredWithDefaultEnumSet\" , required = false)" ,
1114+ "override val nonRequiredWithDefaultEnumSet: kotlin.collections.Set<Dog.NonRequiredWithDefaultEnumSet> = setOf(NonRequiredWithDefaultEnumSet.THEM,NonRequiredWithDefaultEnumSet.THOSE)"
1115+ );
1116+
1117+ Path petPath = Paths .get (outputPath + "/src/main/kotlin/org/openapitools/model/Pet.kt" );
1118+ assertFileContains (
1119+ petPath ,
1120+ "override val category: Category?" , // without default (fallback) value is nullable
1121+ "val nonRequiredWithDefaultList: kotlin.collections.List<kotlin.String>" , // elsewhere with default (fallback) value is not nullable
1122+ "val nonRequiredWithDefaultSet: kotlin.collections.Set<kotlin.String>" ,
1123+ "val nonRequiredWithDefaultString: kotlin.String" ,
1124+ "val nonRequiredWithDefaultInt: java.math.BigDecimal" ,
1125+ "val nonRequiredWithDefaultLong: java.math.BigDecimal" ,
1126+ "val nonRequiredWithDefaultFloat: kotlin.Float" ,
1127+ "val nonRequiredWithDefaultDouble: kotlin.Double" ,
1128+ "val nonRequiredWithDefaultEnum: Pet.NonRequiredWithDefaultEnum" ,
1129+ "val nonRequiredWithDefaultEnumList: Pet.NonRequiredWithDefaultEnumList" ,
1130+ "val nonRequiredWithDefaultEnumSet: Pet.NonRequiredWithDefaultEnumSet"
1131+ );
1132+ }
1133+
10671134 @ Test
10681135 public void reactiveWithoutFlow () throws Exception {
10691136 File output = Files .createTempDirectory ("test" ).toFile ().getCanonicalFile ();
0 commit comments