Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
use openapi generator plugin to update spring boot 3
Browse files Browse the repository at this point in the history
  • Loading branch information
jackjii79 committed Jan 23, 2024
1 parent e6c44b9 commit 346124c
Show file tree
Hide file tree
Showing 54 changed files with 2,426 additions and 791 deletions.
3 changes: 1 addition & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import ai.h2o.ci.Utils

JAVA_IMAGE = 'eclipse-temurin@sha256:24643c2dd329ef482ecd042b59cbfb7fe13716342e22674a0abd763559c8a1dd'
JAVA_8_IMAGE = 'harbor.h2o.ai/dockerhub-proxy/library/openjdk:8u222-jdk-slim'
NODE_LABEL = 'docker'
DOCKERHUB_CREDS = 'dockerhub'
HARBOR_URL = "http://harbor.h2o.ai/"
Expand Down Expand Up @@ -94,7 +93,7 @@ pipeline {
docker {
registryCredentialsId HARBOR_CREDS
registryUrl HARBOR_URL
image JAVA_8_IMAGE
image JAVA_IMAGE
label NODE_LABEL
}
}
Expand Down
8 changes: 8 additions & 0 deletions aws-lambda-scorer/lambda-template/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id 'org.springframework.boot'
}

apply from: project(":").file('gradle/java.gradle')

dependencies {
Expand All @@ -15,6 +19,10 @@ dependencies {
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine'
}

bootJar {
enabled=false
}

test {
useJUnitPlatform()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public final class MojoScorer {
private static final Object pipelineLock = new Object();
private static MojoPipeline pipeline;

private final ScoreRequestToMojoFrameConverter requestConverter
= new ScoreRequestToMojoFrameConverter();
private final MojoFrameToScoreResponseConverter responseConverter
= new MojoFrameToScoreResponseConverter();
private final ScoreRequestToMojoFrameConverter requestConverter =
new ScoreRequestToMojoFrameConverter();
private final MojoFrameToScoreResponseConverter responseConverter =
new MojoFrameToScoreResponseConverter();
private final RequestChecker requestChecker = new RequestChecker(new SampleRequestBuilder());

/** Processes a single {@link ScoreRequest} in the given AWS Lambda {@link Context}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ public MojoScorer mojoScorer(
ScoreRequestTransformer scoreRequestTransformer,
CsvToMojoFrameConverter csvConverter) {
return new MojoScorer(
requestConverter,
responseConverter,
contributionRequestConverter,
contributionResponseConverter,
modelInfoConverter,
scoreRequestTransformer,
csvConverter);
requestConverter,
responseConverter,
contributionRequestConverter,
contributionResponseConverter,
modelInfoConverter,
scoreRequestTransformer,
csvConverter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -25,10 +24,9 @@
@Controller
public class ModelsApiController implements ModelApi {

private static final String UNIMPLEMENTED_MESSAGE
= "Shapley values are not implemented yet";
private static final List<CapabilityType> SUPPORTED_CAPABILITIES
= Arrays.asList(CapabilityType.SCORE);
private static final String UNIMPLEMENTED_MESSAGE = "Shapley values are not implemented yet";
private static final List<CapabilityType> SUPPORTED_CAPABILITIES =
Arrays.asList(CapabilityType.SCORE);
private static final Logger log = LoggerFactory.getLogger(ModelsApiController.class);

private final MojoScorer scorer;
Expand Down Expand Up @@ -101,8 +99,7 @@ public ResponseEntity<ScoreResponse> getScoreByFile(String file) {
}

@Override
public ResponseEntity<ContributionResponse> getContribution(
ContributionRequest request) {
public ResponseEntity<ContributionResponse> getContribution(ContributionRequest request) {
// TODO: to be implemented in the future
log.info(" Unsupported operation: " + UNIMPLEMENTED_MESSAGE);
return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).build();
Expand Down
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
Expand All @@ -8,20 +10,22 @@ buildscript {
dependencies {
classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin',
version: springBootPluginVersion
classpath group: 'gradle.plugin.org.hidetake', name: 'gradle-swagger-generator-plugin',
version: swaggerGradlePluginVersion
//classpath group: 'gradle.plugin.org.hidetake', name: 'gradle-swagger-generator-plugin',
// version: swaggerGradlePluginVersion
classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow',
version: shadowJarVersion
// classpath group: 'com.diffplug.spotless', name: 'spotless-plugin-gradle', version: spotlessPluginVersion
classpath group: 'net.ltgt.gradle', name: 'gradle-errorprone-plugin',
version: errorpronePluginVersion
classpath group: 'com.google.cloud.tools.jib', name: 'com.google.cloud.tools.jib.gradle.plugin',
version: jibPluginVersion
classpath group: 'org.openapitools', name: 'openapi-generator-gradle-plugin',
version: openApiGeneratorGradlePluginVersion
}
}

subprojects {
repositories {
mavenLocal()
mavenCentral()
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/jdbc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {

testImplementation group: 'org.scalatest', name: 'scalatest_2.12', version: '3.0.5'
testRuntimeOnly group:'org.scala-lang.modules', name: 'scala-xml_2.12', version: '1.1.1'
//testImplementation group: 'com.google.truth.extensions', name: 'truth-java8-extension'
testImplementation group: 'com.google.truth.extensions', name: 'truth-java8-extension'
testImplementation group: 'org.mockito', name: 'mockito-core'
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api'
Expand Down
2 changes: 1 addition & 1 deletion common/kdb-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply from: project(":").file('gradle/java_no_style.gradle')
dependencies {
implementation group: 'com.google.code.gson', name: 'gson'

//testImplementation group: 'com.google.truth.extensions', name: 'truth-java8-extension'
testImplementation group: 'com.google.truth.extensions', name: 'truth-java8-extension'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine'
}
Expand Down
61 changes: 36 additions & 25 deletions common/rest-java-model/build.gradle
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
plugins {
id 'org.hidetake.swagger.generator'
id 'org.springframework.boot'
id 'org.openapi.generator'
}
apply from: project(":").file('gradle/java.gradle')

dependencies {
implementation group: 'com.google.code.gson', name: 'gson'
//implementation group: 'javax.annotation', name: 'javax.annotation-api'
implementation group: 'io.swagger.core.v3', name: 'swagger-annotations'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable'
swaggerCodegen group: 'org.openapitools', name: 'openapi-generator-cli'
//swaggerCodegen group: 'io.swagger.codegen.v3', name: 'swagger-codegen-cli'
}

swaggerSources {
model {
inputFile = file('../swagger/v1/swagger.yaml')
code {
language = 'java'
configFile = file('../swagger/v1/swagger_codegen.json')
components = [models: true]
dependsOn validation
}
}
modelV1Exp {
inputFile = file('../swagger/v1exp/swagger.yaml')
code {
language = 'java'
configFile = file('../swagger/v1exp/swagger_codegen.json')
components = [models: true]
dependsOn validation
}
}
openApiValidate {
inputSpec = "$rootDir/common/swagger/v1openapi3/swagger.json"
recommend = true
}

openApiGenerate {
generatorName = 'spring'
packageName = "ai.h2o.mojos.deploy.common.rest"
invokerPackage = "ai.h2o.mojos.deploy.common.rest"
inputSpec = "$rootDir/common/swagger/v1openapi3/swagger.json"
outputDir = "$buildDir/gen"
globalProperties.set([
"skipFormModel": "false",
])
configOptions.set([
"useSpringBoot3": "true",
"interfaceOnly": "true",
"basePackage": "ai.h2o.mojos.deploy.common.rest",
"modelPackage": "ai.h2o.mojos.deploy.common.rest.model",
])
}

bootJar {
enabled=false
}

compileJava.dependsOn swaggerSources.model.code, swaggerSources.modelV1Exp.code
sourceSets.main.java.srcDirs "${swaggerSources.model.code.outputDir}/src/main/java", "${swaggerSources.modelV1Exp.code.outputDir}/src/main/java"
compileJava.dependsOn tasks.openApiValidate, tasks.openApiGenerate
sourceSets {
main {
java {
srcDir("$buildDir/gen/src/main/java")
}
}
}
35 changes: 19 additions & 16 deletions common/rest-jdbc-spring-api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
plugins {
id 'org.springframework.boot'
id 'org.hidetake.swagger.generator'
id 'org.openapi.generator'
}
apply from: project(":").file('gradle/java.gradle')

dependencies {
implementation group: 'io.swagger.core.v3', name: 'swagger-annotations'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable'
swaggerCodegen group: 'org.openapitools', name: 'openapi-generator-cli'
//swaggerCodegen group: 'io.swagger.codegen.v3', name: 'swagger-codegen-cli'
}

swaggerSources {
api {
inputFile = file('../swagger/v1/jdbc-swagger.yaml')
code {
language = 'spring'
configFile = file('../swagger/v1/jdbc_swagger_codegen.json')
components = [models: true, apis: true]
dependsOn validation
}
}
openApiValidate {
inputSpec = "$rootDir/common/swagger/v1/jdbc_swagger.json"
recommend = true
}

openApiGenerate {
generatorName = 'spring'
inputSpec = "$rootDir/common/swagger/v1/jdbc_swagger.json"
outputDir = "$rootDir/common/rest-jdbc-spring-api/build/openApi"
configOptions.set([
"useSpringBoot3": "true",
"interfaceOnly": "true",
"basePackage": "ai.h2o.mojos.deploy.common.rest.jdbc",
"configPackage": "ai.h2o.mojos.deploy.common.rest.jdbc.config",
"apiPackage": "ai.h2o.mojos.deploy.common.rest.jdbc.api",
"modelPackage": "ai.h2o.mojos.deploy.common.rest.jdbc.model",
])
}

jar {
Expand All @@ -34,5 +38,4 @@ bootJar {
enabled=false
}

compileJava.dependsOn swaggerSources.api.code
sourceSets.main.java.srcDir "${swaggerSources.api.code.outputDir}/src/main/java"
compileJava.dependsOn tasks.openApiValidate, tasks.openApiGenerate
69 changes: 22 additions & 47 deletions common/rest-spring-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,34 @@ plugins {
apply from: project(":").file('gradle/java.gradle')

dependencies {
//implementation group: 'io.swagger.core.v3', name: 'swagger-annotations'
implementation group: 'io.swagger.core.v3', name: 'swagger-annotations'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable'
//swaggerCodegen group: 'org.openapitools', name: 'openapi-generator-cli'
//swaggerCodegen group: 'io.swagger.codegen.v3', name: 'swagger-codegen-cli'
}

openApiMeta {
generatorName = "rest-spring-api"
packageName = "ai.h2o.mojos.deploy.common.rest"
outputFolder = "$buildDir/swagger-code-api"
}

openApiValidate {
inputSpec = "../$rootDir/swagger/v1openapi3/swagger.yaml"
inputSpec = "$rootDir/common/swagger/v1openapi3/swagger.json"
recommend = true
}

openApiGenerate {
apiPackage = "ai.h2o.mojos.deploy.common.rest.api"
modelPackage = "ai.h2o.mojos.deploy.common.rest.model"
generatorName = 'spring'
inputSpec = "$rootDir/common/swagger/v1openapi3/swagger.json"
outputDir = "$buildDir/gen"
globalProperties.set([
useSpringBoot3: true
"skipFormModel": "false",
])
}

task buildSwaggerV1Sdk(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName = "rest-spring-api-swagger-v1"
inputSpec = "../$rootDir/swagger/v1/swagger.yaml"
outputDir.set("$buildDir/swagger-code-api")
apiPackage.set("ai.h2o.mojos.deploy.common.rest.api")
modelPackage.set("ai.h2o.mojos.deploy.common.rest.model")
globalProperties.set([
useSpringBoot3: "true"
configOptions.set([
"useSpringBoot3": "true",
"interfaceOnly": "true",
"basePackage": "ai.h2o.mojos.deploy.common.rest",
"configPackage": "ai.h2o.mojos.deploy.common.rest.config",
"apiPackage": "ai.h2o.mojos.deploy.common.rest.api",
"modelPackage": "ai.h2o.mojos.deploy.common.rest.model",
])
}
/*
swaggerSources {
api {
inputFile = file('../swagger/v1/swagger.yaml')
code {
language = 'spring'
configFile = file('../swagger/v1/swagger_codegen.json')
components = [models: true, apis: true]
dependsOn validation
}
}
apiV1Exp {
inputFile = file('../swagger/v1exp/swagger.yaml')
code {
language = 'spring'
configFile = file('../swagger/v1exp/swagger_codegen.json')
components = [models: true, apis: true]
dependsOn validation
}
}
}
*/

jar {
// As a SpringBoot module, we need to enable the jar file generation.
enabled=true
Expand All @@ -73,5 +42,11 @@ bootJar {
enabled=false
}

compileJava.dependsOn openApiGenerate
sourceSets.main.java.srcDirs "$buildDir/swagger-code-api/src/main/java"
compileJava.dependsOn tasks.openApiValidate, tasks.openApiGenerate
sourceSets {
main {
java {
srcDir("$buildDir/gen/src/main/java")
}
}
}
Loading

0 comments on commit 346124c

Please sign in to comment.