@@ -6101,4 +6101,93 @@ public void issue20502_starSlashNotCorruptedInModelDefaults() throws IOException
61016101 assertFileContains (modelFile , "@get:JsonProperty(\" \\ $id\" )" );
61026102 assertFileContains (modelFile , "@get:JsonProperty(\" name\\ $Value\" )" );
61036103 }
6104+
6105+ @ Test
6106+ public void gradleWrapperIsGenerated () throws IOException {
6107+ File output = Files .createTempDirectory ("test" ).toFile ().getCanonicalFile ();
6108+ output .deleteOnExit ();
6109+
6110+ KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen ();
6111+ codegen .setOutputDir (output .getAbsolutePath ());
6112+ new DefaultGenerator ().opts (
6113+ new ClientOptInput ().openAPI (TestUtils .parseSpec ("src/test/resources/3_0/petstore.yaml" ))
6114+ .config (codegen )
6115+ ).generate ();
6116+ String outputPath = output .getAbsolutePath ();
6117+ Path gradleWrapperProperties = Paths .get (outputPath + "/gradle/wrapper/gradle-wrapper.properties" );
6118+ Path gradleWrapperJar = Paths .get (outputPath + "/gradle/wrapper/gradle-wrapper.jar" );
6119+ Path gradleWrapper = Paths .get (outputPath + "/gradlew" );
6120+ Path gradleWrapperBat = Paths .get (outputPath + "/gradlew.bat" );
6121+ TestUtils .assertFileExists (gradleWrapperProperties );
6122+ TestUtils .assertFileExists (gradleWrapper );
6123+ TestUtils .assertFileExists (gradleWrapperBat );
6124+ // Different because file is not a text file
6125+ Assert .assertTrue (Files .exists (gradleWrapperJar ));
6126+
6127+ // Spring Cloud
6128+ File outputCloud = Files .createTempDirectory ("testCloud" ).toFile ().getCanonicalFile ();
6129+ outputCloud .deleteOnExit ();
6130+ codegen .setLibrary (KotlinSpringServerCodegen .SPRING_CLOUD_LIBRARY );
6131+ codegen .setOutputDir (outputCloud .getAbsolutePath ());
6132+ new DefaultGenerator ().opts (
6133+ new ClientOptInput ().openAPI (TestUtils .parseSpec ("src/test/resources/3_0/petstore.yaml" ))
6134+ .config (codegen )
6135+ ).generate ();
6136+
6137+ String outputPathCloud = outputCloud .getAbsolutePath ();
6138+ Path gradleWrapperPropertiesCloud = Paths .get (outputPathCloud + "/gradle/wrapper/gradle-wrapper.properties" );
6139+ Path gradleWrapperJarCloud = Paths .get (outputPathCloud + "/gradle/wrapper/gradle-wrapper.jar" );
6140+ Path gradleWrapperCloud = Paths .get (outputPathCloud + "/gradlew" );
6141+ Path gradleWrapperBatCloud = Paths .get (outputPathCloud + "/gradlew.bat" );
6142+ TestUtils .assertFileExists (gradleWrapperPropertiesCloud );
6143+ TestUtils .assertFileExists (gradleWrapperCloud );
6144+ TestUtils .assertFileExists (gradleWrapperBatCloud );
6145+ // Different because file is not a text file
6146+ Assert .assertTrue (Files .exists (gradleWrapperJarCloud ));
6147+ }
6148+
6149+ @ Test (description = "generate polymorphic jackson model" )
6150+ public void polymorphicJacksonSerialization () throws IOException {
6151+ File output = Files .createTempDirectory ("test" ).toFile ().getCanonicalFile ();
6152+ output .deleteOnExit ();
6153+
6154+ KotlinSpringServerCodegen codegen = new KotlinSpringServerCodegen ();
6155+ codegen .setOutputDir (output .getAbsolutePath ());
6156+
6157+ new DefaultGenerator ().opts (
6158+ new ClientOptInput ()
6159+ .openAPI (TestUtils .parseSpec ("src/test/resources/3_0/kotlin/polymorphism.yaml" ))
6160+ .config (codegen )
6161+ ).generate ();
6162+
6163+ final Path animalKt = Paths .get (output + "/src/main/kotlin/org/openapitools/model/Animal.kt" );
6164+ // base has extra jackson imports
6165+ assertFileContains (animalKt , "import com.fasterxml.jackson.annotation.JsonIgnoreProperties" );
6166+ assertFileContains (animalKt , "import com.fasterxml.jackson.annotation.JsonSubTypes" );
6167+ assertFileContains (animalKt , "import com.fasterxml.jackson.annotation.JsonTypeInfo" );
6168+ // and these are being used
6169+ assertFileContains (animalKt , "@JsonIgnoreProperties" );
6170+ assertFileContains (animalKt , "@JsonSubTypes" );
6171+ assertFileContains (animalKt , "@JsonTypeInfo" );
6172+ // base is interface
6173+ assertFileContains (animalKt , "interface Animal" );
6174+ // base properties are present
6175+ assertFileContains (animalKt , "val id" );
6176+ assertFileContains (animalKt , "val optionalProperty" );
6177+ assertFileContains (animalKt , "val stringArray: kotlin.collections.List<kotlin.String>" );
6178+ assertFileContains (animalKt , "val stringSet: kotlin.collections.Set<kotlin.String>" );
6179+ // base doesn't contain discriminator
6180+ assertFileNotContains (animalKt , "val discriminator" );
6181+
6182+ final Path birdKt = Paths .get (output + "/src/main/kotlin/org/openapitools/model/Bird.kt" );
6183+ // derived has serial name set to mapping key
6184+ assertFileContains (birdKt , "data class Bird" );
6185+ // derived properties are overridden
6186+ assertFileContains (birdKt , "override val id" );
6187+ assertFileContains (birdKt , "override val optionalProperty" );
6188+ assertFileContains (birdKt , "override val stringArray: kotlin.collections.List<kotlin.String>" );
6189+ assertFileContains (birdKt , "override val stringSet: kotlin.collections.Set<kotlin.String>" );
6190+ // derived doesn't contain discriminator
6191+ assertFileNotContains (birdKt , "val discriminator" );
6192+ }
61046193}
0 commit comments