Skip to content

Commit

Permalink
OpenAPI generator new properties (#807)
Browse files Browse the repository at this point in the history
* OpenAPI generator 6.1.0 new properties

* Fix OpenAPI Kotlin integration

- 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

* Fix tests

* Fix openapi tests

---------

Co-authored-by: Cedric Champeau <[email protected]>
  • Loading branch information
altro3 and melix authored Nov 27, 2023
1 parent b2b17e9 commit bf01f4a
Show file tree
Hide file tree
Showing 22 changed files with 1,534 additions and 69 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 @@ -82,7 +82,7 @@ RUN mkdir -p /home/app/config-dirs/ch.qos.logback/logback-classic/4.0.0
COPY config-dirs/generateResourcesConfigFile /home/app/config-dirs/generateResourcesConfigFile
COPY config-dirs/io.netty/netty-common/4.0.0.Final /home/app/config-dirs/io.netty/netty-common/4.0.0.Final
COPY config-dirs/ch.qos.logback/logback-classic/4.0.0 /home/app/config-dirs/ch.qos.logback/logback-classic/4.0.0
RUN native-image --exclude-config .*/libs/netty-transport-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-buffer-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http2-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-common-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-handler-4.0.0.Final.jar ^/META-INF/native-image/.* -cp /home/app/libs/*.jar:/home/app/resources:/home/app/application.jar --no-fallback -o application -H:ConfigurationFileDirectories=/home/app/config-dirs/generateResourcesConfigFile,/home/app/config-dirs/io.netty/netty-buffer/4.0.0.Final,/home/app/config-dirs/io.netty/netty-common/4.0.0.Final,/home/app/config-dirs/io.netty/netty-codec-http/4.0.0.Final,/home/app/config-dirs/io.netty/netty-transport/4.0.0.Final,/home/app/config-dirs/io.netty/netty-handler/4.0.0.Final,/home/app/config-dirs/io.netty/netty-codec-http2/4.0.0.Final,/home/app/config-dirs/ch.qos.logback/logback-classic/4.0.0 demo.app.Application
RUN native-image --exclude-config .*/libs/netty-transport-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-buffer-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-handler-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-common-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http2-4.0.0.Final.jar ^/META-INF/native-image/.* -cp /home/app/libs/*.jar:/home/app/resources:/home/app/application.jar --no-fallback -o application -H:ConfigurationFileDirectories=/home/app/config-dirs/generateResourcesConfigFile,/home/app/config-dirs/io.netty/netty-buffer/4.0.0.Final,/home/app/config-dirs/io.netty/netty-common/4.0.0.Final,/home/app/config-dirs/io.netty/netty-codec-http/4.0.0.Final,/home/app/config-dirs/io.netty/netty-transport/4.0.0.Final,/home/app/config-dirs/io.netty/netty-handler/4.0.0.Final,/home/app/config-dirs/io.netty/netty-codec-http2/4.0.0.Final,/home/app/config-dirs/ch.qos.logback/logback-classic/4.0.0 demo.app.Application
FROM frolvlad/alpine-glibc:alpine-${DefaultVersions.ALPINE}
RUN apk --no-cache update && apk add libstdc++
EXPOSE 8080
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ RUN mkdir -p /home/alternate/config-dirs/generateResourcesConfigFile
RUN mkdir -p /home/alternate/config-dirs/io.netty/netty-common/4.0.0.Final
COPY config-dirs/generateResourcesConfigFile /home/alternate/config-dirs/generateResourcesConfigFile
COPY config-dirs/io.netty/netty-common/4.0.0.Final /home/alternate/config-dirs/io.netty/netty-common/4.0.0.Final
RUN native-image --exclude-config .*/libs/netty-transport-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-buffer-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http2-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-common-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-handler-4.0.0.Final.jar ^/META-INF/native-image/.* -cp /home/alternate/libs/*.jar:/home/alternate/resources:/home/alternate/application.jar --no-fallback -o application -H:ConfigurationFileDirectories=/home/alternate/config-dirs/generateResourcesConfigFile,/home/alternate/config-dirs/io.netty/netty-buffer/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-common/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-codec-http/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-transport/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-handler/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-codec-http2/4.0.0.Final example.Application
RUN native-image --exclude-config .*/libs/netty-transport-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-buffer-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-handler-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-common-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http2-4.0.0.Final.jar ^/META-INF/native-image/.* -cp /home/alternate/libs/*.jar:/home/alternate/resources:/home/alternate/application.jar --no-fallback -o application -H:ConfigurationFileDirectories=/home/alternate/config-dirs/generateResourcesConfigFile,/home/alternate/config-dirs/io.netty/netty-buffer/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-common/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-codec-http/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-transport/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-handler/4.0.0.Final,/home/alternate/config-dirs/io.netty/netty-codec-http2/4.0.0.Final example.Application
${defaultDockerFrom}
EXPOSE 8080
HEALTHCHECK CMD curl -s localhost:8090/health | grep '"status":"UP"'
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/kotlin/io/micronaut/openapi/api/PetApi.kt").exists()
file("build/generated/openapi/generateServerOpenApiModels/src/main/kotlin/io/micronaut/openapi/model/Pet.kt").exists()
file("build/classes/kotlin/main/io/micronaut/openapi/api/PetApi.class").exists()
file("build/classes/kotlin/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/kotlin/io/micronaut/openapi/api/PetApi.kt").exists()
file("build/generated/openapi/generateServerOpenApiModels/src/main/kotlin/io/micronaut/openapi/model/Pet.kt").exists()
file("build/classes/kotlin/main/io/micronaut/openapi/api/PetApi.class").exists()
file("build/classes/kotlin/main/io/micronaut/openapi/model/Pet.class").exists()
}
}
Loading

0 comments on commit bf01f4a

Please sign in to comment.