Skip to content

Commit

Permalink
Support Micronaut4 (#5)
Browse files Browse the repository at this point in the history
* Support Micronaut4

* fix micronaut plugin version and default api base-path to /

* retour de review

* Migrate to .kts and improve build for equisoft

* fix gradle plugin publication

* bump version
  • Loading branch information
etremblay authored Dec 19, 2023
1 parent 0c35ab5 commit b157539
Show file tree
Hide file tree
Showing 20 changed files with 198 additions and 96 deletions.
2 changes: 1 addition & 1 deletion modules/openapi-generator-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.equisoft.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>7.1.0-equisoft2-SNAPSHOT</version>
<version>7.1.0-equisoft3-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>openapi-generator-project</artifactId>
<groupId>com.equisoft.openapitools</groupId>
<!-- RELEASE_VERSION -->
<version>7.1.0-equisoft2-SNAPSHOT</version>
<version>7.1.0-equisoft3-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
4 changes: 2 additions & 2 deletions modules/openapi-generator-gradle-plugin/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ buildscript {
// url "https://plugins.gradle.org/m2/"
}
dependencies {
classpath "org.openapitools:openapi-generator-gradle-plugin:6.6.0"
classpath "com.equisoft.openapitools:openapi-generator-gradle-plugin:6.6.0"
}
}
Expand Down Expand Up @@ -761,7 +761,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath('org.openapitools:openapi-generator-gradle-plugin:6.6.0') {
classpath('com.equisoft.openapitools:openapi-generator-gradle-plugin:6.6.0') {
exclude group: 'com.google.guava'
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ gradlePlugin {
group = "com.equisoft.openapitools"
plugins {
openApiGenerator {
id = "com.equisoft.openapitools"
id = "org.openapi.generator"
description = "OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)."
displayName = "OpenAPI Generator Gradle Plugin"
implementationClass = "org.openapitools.generator.gradle.plugin.OpenApiGeneratorPlugin"
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RELEASE_VERSION
openApiGeneratorVersion=7.1.0-equisoft2-SNAPSHOT
openApiGeneratorVersion=7.1.0-equisoft3-SNAPSHOT
# /RELEASE_VERSION

# BEGIN placeholders
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.equisoft.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>7.1.0-equisoft2-SNAPSHOT</version>
<version>7.1.0-equisoft3-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
}
dependencies {
// Updated version can be passed via command line arg as -PopenApiGeneratorVersion=VERSION
classpath "org.openapitools:openapi-generator-gradle-plugin:$openApiGeneratorVersion"
classpath "com.equisoft.openapitools:openapi-generator-gradle-plugin:$openApiGeneratorVersion"
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.equisoft.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>7.1.0-equisoft2-SNAPSHOT</version>
<version>7.1.0-equisoft3-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator-online/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.equisoft.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>7.1.0-equisoft2-SNAPSHOT</version>
<version>7.1.0-equisoft3-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
2 changes: 1 addition & 1 deletion modules/openapi-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.equisoft.openapitools</groupId>
<artifactId>openapi-generator-project</artifactId>
<!-- RELEASE_VERSION -->
<version>7.1.0-equisoft2-SNAPSHOT</version>
<version>7.1.0-equisoft3-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<relativePath>../..</relativePath>
</parent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.openapitools.codegen.model.ModelsMap;
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;
import org.openapitools.codegen.utils.SemVer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -25,7 +26,6 @@

import static org.openapitools.codegen.CodegenConstants.INVOKER_PACKAGE;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

public abstract class JavaMicronautAbstractCodegen extends AbstractJavaCodegen implements BeanValidationFeatures, OptionalFeatures {
public static final String OPT_TITLE = "title";
Expand All @@ -38,6 +38,9 @@ public abstract class JavaMicronautAbstractCodegen extends AbstractJavaCodegen i
public static final String OPT_TEST_SPOCK = "spock";
public static final String OPT_REQUIRED_PROPERTIES_IN_CONSTRUCTOR = "requiredPropertiesInConstructor";
public static final String OPT_MICRONAUT_VERSION = "micronautVersion";
public static final String OPT_IS_MICRONAUT4_OR_GREATER = "isMicronaut4OrGreater";
public static final String OPT_MICRONAUT_VALIDATION_GROUP_ID = "micronautValidationGroupId";
public static final String OPT_MICRONAUT_PLUGIN_VERSION = "micronautPluginVersion";
public static final String OPT_USE_AUTH = "useAuth";
public static final String OPT_VISITABLE = "visitable";
public static final String OPT_DATE_LIBRARY_JAVA8 = "java8";
Expand Down Expand Up @@ -65,6 +68,9 @@ public enum SERIALIZATION_LIBRARY_TYPE {jackson, micronaut_serde_jackson}
protected String testTool;
protected boolean requiredPropertiesInConstructor = true;
protected String micronautVersion;
protected boolean isMicronaut4OrGreater;
protected String micronautValidationGroupId;
protected String micronautPluginVersion;
protected boolean reactive;
protected boolean wrapInHttpResponse;
protected String appName;
Expand Down Expand Up @@ -101,6 +107,9 @@ public JavaMicronautAbstractCodegen() {
modelDocPath = "docs/models";
dateLibrary = OPT_DATE_LIBRARY_JAVA8;
micronautVersion = "3.4.3";
isMicronaut4OrGreater = false;
micronautValidationGroupId = "io.micronaut";
micronautPluginVersion = "3.7.10";
reactive = true;
wrapInHttpResponse = false;
appName = artifactId;
Expand Down Expand Up @@ -218,6 +227,8 @@ public void processOpts() {
additionalProperties.put(OPT_MICRONAUT_VERSION, micronautVersion);
}

processEquisoftOpts();

if (additionalProperties.containsKey(OPT_APPLICATION_NAME)) {
appName = (String) additionalProperties.get(OPT_APPLICATION_NAME);
} else {
Expand Down Expand Up @@ -326,8 +337,8 @@ public void processOpts() {

if (buildTool.equals(OPT_BUILD_GRADLE) || buildTool.equals(OPT_BUILD_ALL)) {
// Gradle files
supportingFiles.add(new SupportingFile("common/configuration/gradle/build.gradle.mustache", "", "build.gradle").doNotOverwrite());
supportingFiles.add(new SupportingFile("common/configuration/gradle/settings.gradle.mustache", "", "settings.gradle").doNotOverwrite());
supportingFiles.add(new SupportingFile("common/configuration/gradle/build.gradle.kts.mustache", "", "build.gradle.kts").doNotOverwrite());
supportingFiles.add(new SupportingFile("common/configuration/gradle/settings.gradle.kts.mustache", "", "settings.gradle.kts").doNotOverwrite());
supportingFiles.add(new SupportingFile("common/configuration/gradle/gradle.properties.mustache", "", "gradle.properties").doNotOverwrite());

// Gradlew files
Expand Down Expand Up @@ -394,6 +405,29 @@ public void processOpts() {
additionalProperties.put("modelFolder", modelFolder);
}

private void processEquisoftOpts() {
isMicronaut4OrGreater = (new SemVer(micronautVersion)).atLeast("4.0.0");
additionalProperties.put(OPT_IS_MICRONAUT4_OR_GREATER, isMicronaut4OrGreater);

if (additionalProperties.containsKey(OPT_MICRONAUT_VALIDATION_GROUP_ID)) {
micronautValidationGroupId = (String) additionalProperties.get(OPT_MICRONAUT_VALIDATION_GROUP_ID);
} else {
if(isMicronaut4OrGreater) {
micronautValidationGroupId = "io.micronaut.validation";
}
additionalProperties.put(OPT_MICRONAUT_VALIDATION_GROUP_ID, micronautValidationGroupId);
}

if (additionalProperties.containsKey(OPT_MICRONAUT_PLUGIN_VERSION)) {
micronautPluginVersion = (String) additionalProperties.get(OPT_MICRONAUT_PLUGIN_VERSION);
} else {
if(isMicronaut4OrGreater) {
micronautPluginVersion = "4.2.1";
}
additionalProperties.put(OPT_MICRONAUT_PLUGIN_VERSION, micronautPluginVersion);
}
}

@Override
public String apiTestFileFolder() {
if (testTool.equals(OPT_TEST_SPOCK)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement;
{{>common/generatedAnnotation}}
@Client({{#configureClientId}}
id = "{{clientId}}",
path = {{/configureClientId}}"${{openbrace}}{{{applicationName}}}{{basePathSeparator}}base-path{{closebrace}}")
path = {{/configureClientId}}"${{openbrace}}{{{applicationName}}}{{basePathSeparator}}base-path:/{{closebrace}}")
public interface {{classname}} {
{{#operations}}
{{#operation}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
{{^client}}
import io.micronaut.gradle.MicronautRuntime.NETTY
{{/client}}
{{#isTestSpock}}
import io.micronaut.gradle.MicronautTestRuntime.SPOCK_2
{{/isTestSpock}}
{{#isTestJunit}}
import io.micronaut.gradle.MicronautTestRuntime.JUNIT_5
{{/isTestJunit}}

version = project.findProperty("application.version")?.toString() ?: "{{artifactVersion}}"
group = "{{invokerPackage}}"

plugins {
{{#isTestSpock}}
id("groovy")
{{/isTestSpock}}
{{#client}}
id("io.micronaut.library") version "{{micronautPluginVersion}}"
{{/client}}
{{^client}}
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.micronaut.application") version "{{micronautPluginVersion}}"
{{/client}}
{{#gitProjectName}}
`maven-publish`
{{/gitProjectName}}
}

repositories {
mavenCentral()
}

micronaut {
{{^client}}
runtime.set("netty")
{{/client}}
{{#isTestSpock}}
testRuntime.set(SPOCK_2)
{{/isTestSpock}}
{{#isTestJunit}}
testRuntime.set(JUNIT_5)
{{/isTestJunit}}
processing {
incremental.set(true)
annotations("{{invokerPackage}}.*")
}
}

dependencies {
annotationProcessor("io.micronaut:micronaut-http-validation")
{{#useAuth}}
annotationProcessor("io.micronaut.security:micronaut-security-annotations")
{{/useAuth}}
{{#micronaut_serde_jackson}}
annotationProcessor("io.micronaut.serde:micronaut-serde-processor")
implementation("io.micronaut.serde:micronaut-serde-jackson")
{{/micronaut_serde_jackson}}
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-runtime")
implementation("{{{micronautValidationGroupId}}}:micronaut-validation")
{{#useAuth}}
implementation("io.micronaut.security:micronaut-security")
implementation("io.micronaut.security:micronaut-security-oauth2")
{{/useAuth}}
{{#reactive}}
implementation("io.micronaut.reactor:micronaut-reactor")
{{/reactive}}
{{#generateSwagger1Annotations}}
implementation("io.swagger:swagger-annotations:1.6.5")
{{/generateSwagger1Annotations}}
{{#generateSwagger2Annotations}}
implementation("io.swagger.core.v3:swagger-annotations:2.2.19")
{{/generateSwagger2Annotations}}
runtimeOnly("ch.qos.logback:logback-classic")
{{#isMicronaut4OrGreater}}
runtimeOnly("org.yaml:snakeyaml")
{{/isMicronaut4OrGreater}}
}
{{#micronaut_serde_jackson}}{{^isMicronaut4OrGreater}}
// TODO Please, check the version of the serde, maybe it must be upgraded.
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute(module("io.micronaut:micronaut-jackson-databind"))
.using(module("io.micronaut.serde:micronaut-serde-jackson:1.3.3"))
}
}
{{/isMicronaut4OrGreater}}{{/micronaut_serde_jackson}}

{{^client}}
// TODO Set the main class
application {
mainClass.set("{{invokerPackage}}.Application")
}
{{/client}}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

graalvmNative.toolchainDetection = false

tasks {
wrapper {
distributionType = Wrapper.DistributionType.ALL
gradleVersion = "8.5"
}
}

{{#gitProjectName}}
configure<PublishingExtension> {
repositories {
maven {
name = "{{gitProjectName}}"
url = uri("{{packageUrl}}")
credentials {
name = "gprWrite"
username = project.findProperty("gpr.user")?.toString()
?: System.getenv("GPR_USER")
?: System.getenv("GHCR_USER")
password = project.findProperty("gpr.key")?.toString()
?: System.getenv("GPR_TOKEN")
?: System.getenv("GHCR_TOKEN")
}
}
}

publications {
create<MavenPublication>("gpr") {
from(components["java"])
}
}
}
{{/gitProjectName}}
Loading

0 comments on commit b157539

Please sign in to comment.