Skip to content

Commit

Permalink
Fix OpenAPI Kotlin integration
Browse files Browse the repository at this point in the history
- moves tests to functional tests, since we want to make sure that the plugins
can work _without_ the Kotlin plugin on classpath. The tests which involve
external plugins must live in `functionalTests`
- fixes missing integration with Kotlin plugin
  • Loading branch information
melix committed Nov 23, 2023
1 parent 0fda0db commit c2f1b21
Show file tree
Hide file tree
Showing 9 changed files with 1,246 additions and 224 deletions.
1 change: 1 addition & 0 deletions functional-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ functionalTesting {
pluginUnderTest('docker')
pluginUnderTest('aot')
pluginUnderTest('gradle')
pluginUnderTest('openapi')
pluginUnderTest('test-resources')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract class AbstractFunctionalTest extends AbstractGradleBuildSpec {
id 'io.micronaut.graalvm' version '${version}'
id 'io.micronaut.docker' version '${version}'
id 'io.micronaut.aot' version '${version}'
id 'io.micronaut.openapi' version '${version}'
id 'io.micronaut.test-resources' version '${version}'
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.micronaut.gradle.openapi

import io.micronaut.gradle.fixtures.AbstractEagerConfiguringFunctionalTest
import spock.lang.Shared

class AbstractOpenApiWithKotlinSpec extends AbstractEagerConfiguringFunctionalTest {
@Shared
protected final String kotlinVersion = System.getProperty("kotlinVersion")

@Shared
protected final String kspVersion = System.getProperty("kspVersion")

protected void withPetstore() {
file("petstore.json").text = this.class.getResourceAsStream("/petstore.json").getText("UTF-8")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package io.micronaut.gradle.openapi


import org.gradle.testkit.runner.TaskOutcome

class OpenApiClientWithKotlinSpec extends AbstractOpenApiWithKotlinSpec {

def "can generate an kotlin OpenAPI client implementation with some properties (KAPT)"() {
given:
settingsFile << "rootProject.name = 'openapi-client'"
buildFile << """
plugins {
id "io.micronaut.minimal.application"
id "io.micronaut.openapi"
id "org.jetbrains.kotlin.jvm" version "$kotlinVersion"
id "org.jetbrains.kotlin.plugin.allopen" version "$kotlinVersion"
id "org.jetbrains.kotlin.kapt" version "$kotlinVersion"
}

micronaut {
version "$micronautVersion"
openapi {
client(file("petstore.json")) {
lang = "kotlin"
useReactive = true
generatedAnnotation = false
fluxForArrays = true
}
}
}

$repositoriesBlock

dependencies {

kapt "io.micronaut.serde:micronaut-serde-processor"

implementation "io.micronaut.serde:micronaut-serde-jackson"
implementation "io.micronaut.reactor:micronaut-reactor"
implementation "io.micronaut:micronaut-inject-kotlin"
}

"""
withPetstore()
when:
def result = build('test')
then:
result.task(":generateClientOpenApiApis").outcome == TaskOutcome.SUCCESS
result.task(":generateClientOpenApiModels").outcome == TaskOutcome.SUCCESS
result.task(":compileKotlin").outcome == TaskOutcome.SUCCESS
and:
file("build/generated/openapi/generateClientOpenApiModels/src/main/kotlin/io/micronaut/openapi/model/Pet.kt").exists()
}
def "can generate an kotlin OpenAPI client implementation with some properties (KSP)"() {
given:
settingsFile << "rootProject.name = 'openapi-client'"
buildFile << """
plugins {
id "io.micronaut.minimal.application"
id "io.micronaut.openapi"
id "org.jetbrains.kotlin.jvm" version "$kotlinVersion"
id "org.jetbrains.kotlin.plugin.allopen" version "$kotlinVersion"
id "com.google.devtools.ksp" version "$kspVersion"
}

micronaut {
version "$micronautVersion"
openapi {
client(file("petstore.json")) {
lang = "kotlin"
useReactive = true
generatedAnnotation = false
fluxForArrays = true
}
}
}

$repositoriesBlock

dependencies {

ksp "io.micronaut.serde:micronaut-serde-processor"

implementation "io.micronaut.serde:micronaut-serde-jackson"
implementation "io.micronaut.reactor:micronaut-reactor"
implementation "io.micronaut:micronaut-inject-kotlin"
}

"""
withPetstore()
when:
def result = build('test')
then:
result.task(":generateClientOpenApiApis").outcome == TaskOutcome.SUCCESS
result.task(":generateClientOpenApiModels").outcome == TaskOutcome.SUCCESS
result.task(":compileKotlin").outcome == TaskOutcome.SUCCESS
and:
file("build/generated/openapi/generateClientOpenApiModels/src/main/kotlin/io/micronaut/openapi/model/Pet.kt").exists()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package io.micronaut.gradle.openapi


import org.gradle.testkit.runner.TaskOutcome

class OpenApiServerWithKotlinSpec extends AbstractOpenApiWithKotlinSpec {

def "can generate an kotlin OpenAPI server implementation with properties (KAPT)"() {
given:
settingsFile << "rootProject.name = 'openapi-server'"
buildFile << """
plugins {
id "io.micronaut.minimal.application"
id "io.micronaut.openapi"
id "org.jetbrains.kotlin.jvm" version "$kotlinVersion"
id "org.jetbrains.kotlin.plugin.allopen" version "$kotlinVersion"
id "org.jetbrains.kotlin.kapt" version "$kotlinVersion"
}

micronaut {
version "$micronautVersion"
runtime "netty"
testRuntime "junit5"
openapi {
server(file("petstore.json")) {
lang = "kotlin"
useReactive = true
generatedAnnotation = false
fluxForArrays = true
aot = true
}
}
}

$repositoriesBlock
mainClassName="example.Application"

dependencies {

kapt "io.micronaut.serde:micronaut-serde-processor"

implementation "io.micronaut.security:micronaut-security"
implementation "io.micronaut.serde:micronaut-serde-jackson"
}
"""
withPetstore()
when:
def result = build('test')
then:
result.task(":generateServerOpenApiApis").outcome == TaskOutcome.SUCCESS
result.task(":generateServerOpenApiModels").outcome == TaskOutcome.SUCCESS
result.task(":compileKotlin").outcome == TaskOutcome.SUCCESS
and:
file("build/generated/openapi/generateServerOpenApiApis/src/main/java/io/micronaut/openapi/api/PetApi.java").exists()
file("build/generated/openapi/generateServerOpenApiModels/src/main/java/io/micronaut/openapi/model/Pet.java").exists()
file("build/classes/java/main/io/micronaut/openapi/api/PetApi.class").exists()
file("build/classes/java/main/io/micronaut/openapi/model/Pet.class").exists()
}
def "can generate an kotlin OpenAPI server implementation with properties (KSP)"() {
given:
settingsFile << "rootProject.name = 'openapi-server'"
buildFile << """
plugins {
id "io.micronaut.minimal.application"
id "io.micronaut.openapi"
id "org.jetbrains.kotlin.jvm" version "$kotlinVersion"
id "org.jetbrains.kotlin.plugin.allopen" version "$kotlinVersion"
id "com.google.devtools.ksp" version "$kspVersion"
}

micronaut {
version "$micronautVersion"
runtime "netty"
testRuntime "junit5"
openapi {
server(file("petstore.json")) {
lang = "kotlin"
useReactive = true
generatedAnnotation = false
fluxForArrays = true
aot = true
}
}
}

$repositoriesBlock
mainClassName="example.Application"

dependencies {

ksp "io.micronaut.serde:micronaut-serde-processor"

implementation "io.micronaut.security:micronaut-security"
implementation "io.micronaut.serde:micronaut-serde-jackson"
}
"""
withPetstore()
when:
def result = build('test')
then:
result.task(":generateServerOpenApiApis").outcome == TaskOutcome.SUCCESS
result.task(":generateServerOpenApiModels").outcome == TaskOutcome.SUCCESS
result.task(":compileKotlin").outcome == TaskOutcome.SUCCESS
and:
file("build/generated/openapi/generateServerOpenApiApis/src/main/java/io/micronaut/openapi/api/PetApi.java").exists()
file("build/generated/openapi/generateServerOpenApiModels/src/main/java/io/micronaut/openapi/model/Pet.java").exists()
file("build/classes/java/main/io/micronaut/openapi/api/PetApi.class").exists()
file("build/classes/java/main/io/micronaut/openapi/model/Pet.class").exists()
}
}
Loading

0 comments on commit c2f1b21

Please sign in to comment.