Skip to content

Commit

Permalink
Merge branch '6.12.x' into add-spring-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	gradle/libs.versions.toml
  • Loading branch information
altro3 committed Sep 26, 2024
2 parents 3a7165b + 903ab75 commit 4ecff18
Show file tree
Hide file tree
Showing 32 changed files with 1,261 additions and 921 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ repositories {
}

tasks.withType(Test).configureEach {
useJUnitPlatform()
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import io.micronaut.build.internal.openapi.OpenApiGeneratorTask

plugins {
id 'io.micronaut.minimal.application'
id("io.micronaut.build.internal.openapi-base")
id("io.micronaut.minimal.application")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.micronaut.build.internal.openapi.OpenApiGeneratorTask

plugins {
id 'io.micronaut.minimal.application'
id("io.micronaut.minimal.application")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io.micronaut.build.internal.openapi.OpenApiGeneratorTask

plugins {
id 'io.micronaut.minimal.application'
id("io.micronaut.minimal.application")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'io.micronaut.build.internal.openapi-base'
id 'io.micronaut.build.internal.module'
id("io.micronaut.build.internal.openapi-base")
id("io.micronaut.build.internal.module")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'io.micronaut.build.internal.openapi-base'
id 'io.micronaut.build.internal.base-module'
id 'java-test-fixtures'
id("io.micronaut.build.internal.openapi-base")
id("io.micronaut.build.internal.base-module")
id("java-test-fixtures")
}

components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@ dependencies {
testRuntimeOnly(mnTest.junit.jupiter.engine)
testRuntimeOnly(mnLogging.logback.classic)
}
tasks.test {
useJUnitPlatform()
}
3 changes: 1 addition & 2 deletions docs-examples/example-groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ test {
jvmArgs '-Duser.country=US'
jvmArgs '-Duser.language=en'
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
failFast = true
}

tasks.withType(GroovyCompile) {
tasks.withType(GroovyCompile).configureEach {
groovyOptions.forkOptions.jvmArgs.add('-Dgroovy.parameters=true')
}

Expand Down
4 changes: 1 addition & 3 deletions docs-examples/example-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ compileJava.options.compilerArgs += '-parameters'
compileTestJava.options.compilerArgs += '-parameters'

test {
useJUnitPlatform()

jvmArgs '-Duser.country=US'
jvmArgs '-Duser.language=en'
useJUnitPlatform()
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
failFast = true
Expand Down
4 changes: 1 addition & 3 deletions docs-examples/example-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ ksp {
}

test {
useJUnitPlatform()

jvmArgs '-Duser.country=US'
jvmArgs '-Duser.language=en'
useJUnitPlatform()
testLogging {
showStandardStreams = true
exceptionFormat = 'full'
}
failFast = true
Expand Down
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ openapi-generator = "7.8.0"
swagger-parser = "1.0.71"
swagger-parser-v3 = "2.1.22"
javaparser = "3.26.2"
commons-lang3 = "3.17.0"
commons-codec = "1.17.1"
commons-io = "2.16.1"
commons-text = "1.12.0"
guava = "33.3.1-jre"
jmustache = "1.15"
commonmark = "0.23.0"
spring-boot = "3.3.3"

micronaut = "4.6.5"
Expand Down Expand Up @@ -81,9 +86,14 @@ jdt-annotation = { module = "org.eclipse.jdt:org.eclipse.jdt.annotation", versio
android-annotation = { module = "androidx.annotation:annotation", version.ref = "android-annotation" }
javaparser = { module = "com.github.javaparser:javaparser-symbol-solver-core", version.ref = "javaparser" }
commons-codec = { module = "commons-codec:commons-codec", version.ref = "commons-codec" }
commons-io = { module = "commons-io:commons-io", version.ref = "commons-io" }
commons-lang3 = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang3" }
commons-text = { module = "org.apache.commons:commons-text", version.ref = "commons-text" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
commonmark = { module = "org.commonmark:commonmark", version.ref = "commonmark" }
spring-boot-dependencies = { module = "org.springframework.boot:spring-boot-dependencies", version.ref = "spring-boot" }

openapi-generator = { module = "org.openapitools:openapi-generator", version.ref = "openapi-generator" }
swagger-parser = { module = "io.swagger:swagger-parser", version.ref = "swagger-parser" }
swagger-parser-v3 = { module = "io.swagger.parser.v3:swagger-parser-v3", version.ref = "swagger-parser-v3" }
jmustache = { module = "com.samskivert:jmustache", version.ref = "jmustache" }
48 changes: 37 additions & 11 deletions openapi-generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ plugins {
}

dependencies {
constraints {
api(libs.swagger.parser) {
because("OpenAPI generator depends on older release which isn't compatible with SnakeYAML")
}
api(libs.swagger.parser.v3) {
because("OpenAPI generator depends on older release which isn't compatible with SnakeYAML")
}
}
api(libs.openapi.generator) {
exclude group: "org.projectlombok"
}
api libs.openapi.generator
api libs.swagger.parser
api libs.swagger.parser.v3
api libs.commons.lang3
api libs.commons.text
api libs.commons.codec
api libs.commons.io
api libs.managed.evo.inflector
api libs.jmustache
api libs.commonmark
api libs.guava
api mnLogging.slf4j.ext
api mn.snakeyaml

testImplementation mnTest.micronaut.test.junit5
testImplementation mnTest.junit.jupiter.params
Expand All @@ -28,3 +28,29 @@ dependencies {

testRuntimeOnly mnTest.junit.jupiter.engine
}

configurations.configureEach {
exclude group: "com.google.code.findbugs", module: "jsr305"
exclude group: "javax.validation", module: "validation-api"
exclude group: "org.slf4j", module: "slf4j-simple"
exclude group: "org.projectlombok"
exclude group: "com.google.guava", module: "listenablefuture"
exclude group: "com.google.guava", module: "failureaccess"
exclude group: "com.google.errorprone", module: "error_prone_annotations"
exclude group: "com.google.j2objc", module: "j2objc-annotations"
exclude group: "org.checkerframework", module: "checker-qual"
exclude group: "com.github.jknack"
exclude group: "org.apache.maven.resolver"
exclude group: "com.github.mifmif", module: "generex"
exclude group: "com.github.curious-odd-man", module: "rgxgen"
exclude group: "net.java.dev.jna", module: "jna"
exclude group: "commons-cli", module: "commons-cli"
exclude group: "com.github.joschi.jackson", module: "jackson-datatype-threetenbp"
exclude group: "com.fasterxml.jackson.datatype", module: "jackson-datatype-guava"
exclude group: "com.fasterxml.jackson.datatype", module: "jackson-datatype-joda"
}

test {
maxParallelForks = Runtime.runtime.availableProcessors()
maxHeapSize = "2048m"
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import static io.micronaut.openapi.generator.Utils.isDateType;
import static io.micronaut.openapi.generator.Utils.normalizeExtraAnnotations;
import static io.micronaut.openapi.generator.Utils.processGenericAnnotations;
import static io.micronaut.openapi.generator.Utils.readListOfStringsProperty;
import static org.openapitools.codegen.CodegenConstants.API_PACKAGE;
import static org.openapitools.codegen.CodegenConstants.INVOKER_PACKAGE;
import static org.openapitools.codegen.CodegenConstants.MODEL_PACKAGE;
Expand Down Expand Up @@ -385,6 +386,21 @@ public void setGeneratedAnnotation(boolean generatedAnnotation) {

@Override
public void processOpts() {

// need it to add ability to set List<String> in `additionalModelTypeAnnotations` property
if (additionalProperties.containsKey(ADDITIONAL_MODEL_TYPE_ANNOTATIONS)) {
setAdditionalModelTypeAnnotations(readListOfStringsProperty(ADDITIONAL_MODEL_TYPE_ANNOTATIONS, additionalProperties));
additionalProperties.remove(ADDITIONAL_MODEL_TYPE_ANNOTATIONS);
}
if (additionalProperties.containsKey(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS)) {
setAdditionalOneOfTypeAnnotations(readListOfStringsProperty(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS, additionalProperties));
additionalProperties.remove(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS);
}
if (additionalProperties.containsKey(ADDITIONAL_ENUM_TYPE_ANNOTATIONS)) {
setAdditionalEnumTypeAnnotations(readListOfStringsProperty(ADDITIONAL_ENUM_TYPE_ANNOTATIONS, additionalProperties));
additionalProperties.remove(ADDITIONAL_ENUM_TYPE_ANNOTATIONS);
}

super.processOpts();

// Get properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand All @@ -88,6 +89,7 @@
import static io.micronaut.openapi.generator.Utils.isDateType;
import static io.micronaut.openapi.generator.Utils.normalizeExtraAnnotations;
import static io.micronaut.openapi.generator.Utils.processGenericAnnotations;
import static io.micronaut.openapi.generator.Utils.readListOfStringsProperty;
import static org.openapitools.codegen.CodegenConstants.API_PACKAGE;
import static org.openapitools.codegen.CodegenConstants.INVOKER_PACKAGE;
import static org.openapitools.codegen.CodegenConstants.MODEL_PACKAGE;
Expand Down Expand Up @@ -132,6 +134,8 @@ public abstract class AbstractMicronautKotlinCodegen<T extends GeneratorOptionsB
public static final String OPT_IMPLICIT_HEADERS_REGEX = "implicitHeadersRegex";
public static final String OPT_USE_ENUM_CASE_INSENSITIVE = "useEnumCaseInsensitive";
public static final String OPT_KSP = "ksp";
public static final String ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS = "additionalOneOfTypeAnnotations";
public static final String ADDITIONAL_ENUM_TYPE_ANNOTATIONS = "additionalEnumTypeAnnotations";
public static final String CONTENT_TYPE_APPLICATION_FORM_URLENCODED = "application/x-www-form-urlencoded";
public static final String CONTENT_TYPE_APPLICATION_JSON = "application/json";
public static final String CONTENT_TYPE_MULTIPART_FORM_DATA = "multipart/form-data";
Expand Down Expand Up @@ -167,6 +171,8 @@ public abstract class AbstractMicronautKotlinCodegen<T extends GeneratorOptionsB
protected List<ParameterMapping> parameterMappings = new ArrayList<>();
protected List<ResponseBodyMapping> responseBodyMappings = new ArrayList<>();
protected Map<String, CodegenModel> allModels = new HashMap<>();
protected List<String> additionalOneOfTypeAnnotations = new LinkedList<>();
protected List<String> additionalEnumTypeAnnotations = new LinkedList<>();

private final Logger log = LoggerFactory.getLogger(getClass());

Expand Down Expand Up @@ -280,6 +286,8 @@ protected AbstractMicronautKotlinCodegen() {

cliOptions.add(new CliOption(OPT_TITLE, "Client service name").defaultValue(title));
cliOptions.add(new CliOption(OPT_APPLICATION_NAME, "Micronaut application name (Defaults to the " + CodegenConstants.ARTIFACT_ID + " value)").defaultValue(appName));
cliOptions.add(CliOption.newString(ADDITIONAL_ENUM_TYPE_ANNOTATIONS, "Additional annotations for enum type (class level annotations)"));
cliOptions.add(CliOption.newString(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS, "Additional annotations for oneOf interfaces (class level annotations). List separated by semicolon(;) or new line (Linux or Windows)"));
cliOptions.add(CliOption.newBoolean(OPT_USE_PLURAL, "Whether or not to use plural for request body parameter name", plural));
cliOptions.add(CliOption.newBoolean(OPT_FLUX_FOR_ARRAYS, "Whether or not to use Flux<?> instead Mono<List<?>> for arrays in generated code", fluxForArrays));
cliOptions.add(CliOption.newBoolean(OPT_GENERATED_ANNOTATION, "Generate code with \"@Generated\" annotation", generatedAnnotation));
Expand Down Expand Up @@ -457,6 +465,21 @@ public void setKsp(boolean ksp) {

@Override
public void processOpts() {

// need it to add ability to set List<String> in `additionalModelTypeAnnotations` property
if (additionalProperties.containsKey(ADDITIONAL_MODEL_TYPE_ANNOTATIONS)) {
setAdditionalModelTypeAnnotations(readListOfStringsProperty(ADDITIONAL_MODEL_TYPE_ANNOTATIONS, additionalProperties));
additionalProperties.remove(ADDITIONAL_MODEL_TYPE_ANNOTATIONS);
}
if (additionalProperties.containsKey(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS)) {
setAdditionalOneOfTypeAnnotations(readListOfStringsProperty(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS, additionalProperties));
additionalProperties.remove(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS);
}
if (additionalProperties.containsKey(ADDITIONAL_ENUM_TYPE_ANNOTATIONS)) {
setAdditionalEnumTypeAnnotations(readListOfStringsProperty(ADDITIONAL_ENUM_TYPE_ANNOTATIONS, additionalProperties));
additionalProperties.remove(ADDITIONAL_ENUM_TYPE_ANNOTATIONS);
}

super.processOpts();

// Get properties
Expand Down Expand Up @@ -1554,6 +1577,20 @@ public String toVarName(String name) {
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
objs = super.postProcessAllModels(objs);

if (!additionalOneOfTypeAnnotations.isEmpty()) {
for (String modelName : objs.keySet()) {
Map<String, Object> models = objs.get(modelName);
models.put(ADDITIONAL_ONE_OF_TYPE_ANNOTATIONS, additionalOneOfTypeAnnotations);
}
}

if (!additionalEnumTypeAnnotations.isEmpty()) {
for (String modelName : objs.keySet()) {
Map<String, Object> models = objs.get(modelName);
models.put(ADDITIONAL_ENUM_TYPE_ANNOTATIONS, additionalEnumTypeAnnotations);
}
}

var isServer = isServer();

for (ModelsMap models : objs.values()) {
Expand Down Expand Up @@ -2230,6 +2267,14 @@ public void setUseEnumCaseInsensitive(boolean useEnumCaseInsensitive) {
this.useEnumCaseInsensitive = useEnumCaseInsensitive;
}

public void setAdditionalOneOfTypeAnnotations(List<String> additionalOneOfTypeAnnotations) {
this.additionalOneOfTypeAnnotations = additionalOneOfTypeAnnotations;
}

public void setAdditionalEnumTypeAnnotations(List<String> additionalEnumTypeAnnotations) {
this.additionalEnumTypeAnnotations = additionalEnumTypeAnnotations;
}

@Override
public void postProcess() {
// disable output donation suggestion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import static io.micronaut.openapi.generator.Utils.processMultipartBody;
import static io.micronaut.openapi.generator.Utils.readListOfStringsProperty;

/**
* The generator for creating Micronaut clients.
Expand Down Expand Up @@ -182,14 +182,8 @@ public void processOpts() {
writePropertyBack(AUTHORIZATION_FILTER_PATTERN, this.authorizationFilterPattern);
}

Object additionalClientAnnotations = additionalProperties.get(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS);
if (additionalClientAnnotations != null) {
if (additionalClientAnnotations instanceof @SuppressWarnings("rawtypes") List additionalClientAnnotationsAsList) {
//noinspection unchecked
additionalClientTypeAnnotations = additionalClientAnnotationsAsList;
} else {
additionalClientTypeAnnotations = Arrays.asList(additionalClientAnnotations.toString().trim().split("\\s*(;|\\r?\\n)\\s*"));
}
if (additionalProperties.containsKey(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS)) {
setAdditionalClientTypeAnnotations(readListOfStringsProperty(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS, additionalProperties));
}
writePropertyBack(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS, additionalClientTypeAnnotations);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import org.openapitools.codegen.model.OperationMap;
import org.openapitools.codegen.model.OperationsMap;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import static io.micronaut.openapi.generator.Utils.processMultipartBody;
import static io.micronaut.openapi.generator.Utils.readListOfStringsProperty;

/**
* The generator for creating Micronaut clients.
Expand Down Expand Up @@ -180,14 +180,8 @@ public void processOpts() {
writePropertyBack(AUTHORIZATION_FILTER_PATTERN, this.authorizationFilterPattern);
}

Object additionalClientAnnotations = additionalProperties.get(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS);
if (additionalClientAnnotations != null) {
if (additionalClientAnnotations instanceof @SuppressWarnings("rawtypes") List additionalClientAnnotationsAsList) {
//noinspection unchecked
additionalClientTypeAnnotations = additionalClientAnnotationsAsList;
} else {
additionalClientTypeAnnotations = Arrays.asList(additionalClientAnnotations.toString().trim().split("\\s*(;|\\r?\\n)\\s*"));
}
if (additionalProperties.containsKey(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS)) {
setAdditionalClientTypeAnnotations(readListOfStringsProperty(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS, additionalProperties));
}
writePropertyBack(ADDITIONAL_CLIENT_TYPE_ANNOTATIONS, additionalClientTypeAnnotations);

Expand Down
Loading

0 comments on commit 4ecff18

Please sign in to comment.