diff --git a/.openapi-generator-java-sources.ignore b/.openapi-generator-java-sources.ignore new file mode 100644 index 0000000..00d923c --- /dev/null +++ b/.openapi-generator-java-sources.ignore @@ -0,0 +1,6 @@ +* +**/* +!**/pom.xml +!**/README.md +!**/.openapi-generator-ignore +!**/src/main/java/de/hmmh/**/* diff --git a/build.gradle.kts b/build.gradle.kts index d8e2076..5860b4f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,6 +2,7 @@ import com.github.spotbugs.snom.Confidence import com.github.spotbugs.snom.Effort import com.github.spotbugs.snom.SpotBugsTask import org.hidetake.gradle.swagger.generator.GenerateSwaggerCode +import org.openapitools.codegen.languages.JavaClientCodegen repositories { mavenCentral() @@ -14,6 +15,7 @@ plugins { id("org.springframework.boot") version "3.3.3" id("io.spring.dependency-management") version "1.1.6" id("org.hidetake.swagger.generator") version "2.19.2" + id("org.openapi.generator") version "7.8.0" } checkstyle { @@ -23,7 +25,7 @@ checkstyle { } spotbugs { - toolVersion = "4.8.6" + toolVersion = "4.8.6" effort.set(Effort.MAX) reportLevel.set(Confidence.LOW) } @@ -87,6 +89,34 @@ swaggerSources { } } +openApiGenerate { + remoteInputSpec = "https://employee.szut.dev/v3/api-docs.yaml" + apiPackage = "ignored" + modelPackage = "ignored" + invokerPackage = "de.hmmh.pmt.employee" + groupId = "de.hmmh" + packageName = "de.hmmh.pmt" + generatorName = "java" + generateModelTests = false + generateApiTests = false + generateApiDocumentation = false + generateModelDocumentation = false + library = JavaClientCodegen.RESTTEMPLATE + + ignoreFileOverride.set(".openapi-generator-java-sources.ignore") + + configOptions.putAll( + mapOf( + JavaClientCodegen.GENERATE_CLIENT_AS_BEAN to "true", + JavaClientCodegen.ANNOTATION_LIBRARY to "swagger2", + JavaClientCodegen.OPENAPI_NULLABLE to "false", + JavaClientCodegen.PERFORM_BEANVALIDATION to "true", + JavaClientCodegen.USE_BEANVALIDATION to "true", + JavaClientCodegen.USE_JAKARTA_EE to "true", + ) + ) + +} tasks { withType { @@ -96,17 +126,19 @@ tasks { } } withType { - + excludeFilter.set(file("${rootDir}/src/main/resources/spotbugs-exclude.xml")) } processResources { dependsOn(generateSwaggerCode) + dependsOn(openApiGenerate) } withType { useJUnitPlatform() } named("compileJava").configure { dependsOn(swaggerSources.getByName("pmt").code) + dependsOn(openApiGenerate) } } @@ -114,5 +146,7 @@ sourceSets { main { java.srcDir("${swaggerSources.getByName("pmt").code.outputDir}/src/main/java") resources.srcDir("${swaggerSources.getByName("pmt").code.outputDir}/src/main/resources") + + java.srcDir("${openApiGenerate.outputDir}/src/main/java") } } diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index d210430..476d60e 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -1,9 +1,11 @@ package de.hmmh.pmt; import com.fasterxml.jackson.databind.ObjectMapper; +import de.hmmh.pmt.employee.ApiClient; import de.hmmh.pmt.oas.DefaultApi; import de.hmmh.pmt.dtos.HelloOut; import jakarta.servlet.http.HttpServletRequest; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -13,6 +15,9 @@ import java.util.Optional; @Controller @RequestMapping("${openapi.projectManagement.base-path:/api/v1}") public class ApiController implements DefaultApi { + + @Autowired + private ApiClient apiClient; @Override public Optional getObjectMapper() {