Skip to content

Commit

Permalink
4289 gradle support for SE server generator (OpenAPITools#26)
Browse files Browse the repository at this point in the history
gradle support for SE server generator, fix junit tests, fix mainClass var in pom.xml

Signed-off-by: aserkes <andrii.serkes@oracle.com>
  • Loading branch information
aserkes authored Jun 16, 2022
1 parent b96ed06 commit 5fd1c51
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public void processOpts() {


supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle"));
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("openapi.mustache",
("src/main/resources/META-INF").replace("/", java.io.File.separator), "openapi.yml"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
plugins {
id 'java'
id 'application'
}

group = '{{{groupId}}}'
version = '{{{artifactVersion}}}'

{{#appDescription}}
description = """{{.}}"""
{{/appDescription}}


sourceCompatibility = 11
targetCompatibility = 11

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

ext {
helidonVersion = '{{{parentVersion}}}'
mainClass='{{{invokerPackage}}}.Main'
validationApiVersion = '2.0.1.Final'
}

test {
useJUnitPlatform()
}

repositories {
mavenCentral()
mavenLocal()
}

dependencies {
// import Helidon BOM
implementation enforcedPlatform("io.helidon:helidon-dependencies:${project.helidonVersion}")
implementation "javax.validation:validation-api:${project.validationApiVersion}"
implementation 'io.helidon.webserver:helidon-webserver'
implementation 'io.helidon.media:helidon-media-jsonp'
implementation 'io.helidon.media:helidon-media-jsonb'
implementation 'io.helidon.media:helidon-media-multipart'
implementation 'io.helidon.config:helidon-config-yaml'
implementation 'io.helidon.health:helidon-health'
implementation 'io.helidon.health:helidon-health-checks'
implementation 'io.helidon.metrics:helidon-metrics'
implementation 'io.helidon.openapi:helidon-openapi'
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'io.helidon.webclient:helidon-webclient'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}

// define a custom task to copy all dependencies in the runtime classpath
// into build/libs/libs
// uses built-in Copy
task copyLibs(type: Copy) {
from configurations.runtimeClasspath
into 'build/libs/libs'
}

// add it as a dependency of built-in task 'assemble'
copyLibs.dependsOn jar
assemble.dependsOn copyLibs

// default jar configuration
// set the main classpath
// add each jar under build/libs/libs into the classpath
jar {
archiveFileName = "${project.name}.jar"
manifest {
attributes ('Main-Class': "${project.mainClass}",
'Class-Path': configurations.runtimeClasspath.files.collect { "libs/$it.name" }.join(' ')
)
}
}

application {
mainClass = "${project.mainClass}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<name>{{{artifactId}}}</name>

<properties>
<mainClass>{{{basePackage}}}.Main</mainClass>
<mainClass>{{{invokerPackage}}}.Main</mainClass>
<version.validation.api>2.0.1.Final</version.validation.api>
</properties>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = '{{artifactId}}'
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void setup() throws IOException {
public void doGeneratePathParams() throws IOException {
generator.generate();

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
.fileContains("import java.util.Objects;")
.assertMethod("deletePet", "ServerRequest", "ServerResponse")
.bodyContainsLines(
Expand All @@ -59,7 +59,7 @@ public void doGeneratePathParams() throws IOException {
public void doGenerateQueryParams() throws IOException {
generator.generate();

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
.fileContains("import java.util.List;")
.assertMethod("findPetsByTags")
.bodyContainsLines(
Expand All @@ -80,7 +80,7 @@ public void doGenerateQueryParams() throws IOException {
public void doGenerateBodyParams() throws IOException {
generator.generate();

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
.assertMethod("update")
.bodyContainsLines(
"rules.post(\"/pet\", Handler.create(Pet.class, this::addPet));",
Expand All @@ -99,7 +99,7 @@ public void doGenerateBodyParams() throws IOException {
"handleUpdatePet(request, response, pet);"
);

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/UserService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/UserService.java"))
.assertMethod("update")
.bodyContainsLines(
"rules.post(\"/user\", Handler.create(User.class, this::createUser));",
Expand Down Expand Up @@ -128,7 +128,7 @@ public void doGenerateBodyParams() throws IOException {
public void doGenerateHeaderParams() throws IOException {
generator.generate();

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
.assertMethod("deletePet", "ServerRequest", "ServerResponse")
.bodyContainsLines(
"String apiKey = request.headers().value(\"api_key\").orElse(null);",
Expand All @@ -141,7 +141,7 @@ public void doGenerateHeaderParams() throws IOException {
public void doGenerateCookiesParams() throws IOException {
generator.generate();

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
.assertMethod("deletePet", "ServerRequest", "ServerResponse")
.bodyContainsLines(
"String cookieString = request.headers().cookies().toMap().getOrDefault(\"cookieString\", List.of" +
Expand All @@ -160,7 +160,7 @@ public void doGenerateCookiesParams() throws IOException {
public void doGenerateFormParams() throws IOException {
generator.generate();

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
.assertMethod("addPets", "ServerRequest", "ServerResponse")
.bodyContainsLines(
"Map<String, List<String>> nonFileFormContent = new HashMap<>();",
Expand Down Expand Up @@ -188,7 +188,7 @@ public void doGenerateFormParams() throws IOException {
public void doGenerateParamsValidation() throws IOException {
generator.generate();

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/PetService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/PetService.java"))
.assertMethod("findPetsByStatus")
.bodyContainsLines(
"ValidatorUtils.checkNonNull(status);",
Expand All @@ -203,7 +203,7 @@ public void doGenerateParamsValidation() throws IOException {
"ValidatorUtils.checkNonNull(tags);"
);

JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/api/UserService.java"))
JavaFileAssert.assertThat(Paths.get(outputPath + "/src/main/java/org/openapitools/server/api/UserService.java"))
.assertMethod("loginUser")
.bodyContainsLines(
"ValidatorUtils.validatePattern(username, \"^[a-zA-Z0-9]+[a-zA-Z0-9\\\\" +
Expand Down

0 comments on commit 5fd1c51

Please sign in to comment.