From 4b46befd10179716cce92b7b845799da736d8e9e Mon Sep 17 00:00:00 2001 From: altro3 Date: Sat, 24 Aug 2024 16:03:22 +0700 Subject: [PATCH] Full compatibility with micronaut openapi 6.13.0 --- examples/groovy/pom.xml | 4 +- examples/java/pom.xml | 4 +- examples/kotlin/pom.xml | 6 +- examples/multi-project/pom.xml | 4 +- micronaut-maven-integration-tests/pom.xml | 3 +- .../lib/pom.xml | 3 +- .../multi-project-multi-runnable/lib/pom.xml | 3 +- .../src/it/multi-project/lib/pom.xml | 3 +- .../pom.xml | 6 +- .../openapi/controller/MappedController.java | 2 - .../src/it/openapi-generate-server/pom.xml | 17 + .../it/openapi-generate-server/verify.groovy | 7 + micronaut-maven-jib-integration/pom.xml | 6 +- micronaut-maven-plugin/pom.xml | 14 +- .../maven/openapi/AbstractOpenApiMojo.java | 293 +++++++++++++++++- .../maven/openapi/OpenApiClientMojo.java | 35 ++- .../maven/openapi/OpenApiGenericMojo.java | 4 +- .../maven/openapi/OpenApiServerMojo.java | 49 +-- pom.xml | 37 ++- 19 files changed, 407 insertions(+), 93 deletions(-) diff --git a/examples/groovy/pom.xml b/examples/groovy/pom.xml index 62a54de76..e5faac2d8 100644 --- a/examples/groovy/pom.xml +++ b/examples/groovy/pom.xml @@ -14,8 +14,8 @@ jar - 4.0.0-SNAPSHOT - 4.0.0-SNAPSHOT + 4.6.2 + 4.6.3 netty io.micronaut.maven.examples.Application 4.0.12 diff --git a/examples/java/pom.xml b/examples/java/pom.xml index 09b6744ba..a7552a46c 100644 --- a/examples/java/pom.xml +++ b/examples/java/pom.xml @@ -13,8 +13,8 @@ - 4.0.0-M1 - 4.0.0-SNAPSHOT + 4.6.2 + 4.6.3 io.micronaut.maven.examples.Application jar netty diff --git a/examples/kotlin/pom.xml b/examples/kotlin/pom.xml index 8397c57a6..e03f03416 100644 --- a/examples/kotlin/pom.xml +++ b/examples/kotlin/pom.xml @@ -14,10 +14,10 @@ jar - 4.0.0-SNAPSHOT - 4.0.0-SNAPSHOT + 4.6.2 + 4.6.3 netty - 1.8.22 + 1.9.25 io.micronaut.maven.examples.ApplicationKt diff --git a/examples/multi-project/pom.xml b/examples/multi-project/pom.xml index 6977e3cf1..e5986d978 100644 --- a/examples/multi-project/pom.xml +++ b/examples/multi-project/pom.xml @@ -15,8 +15,8 @@ pom - 4.0.0-SNAPSHOT - 4.0.0-SNAPSHOT + 4.6.2 + 4.6.3 netty io.micronaut.build.examples.Application diff --git a/micronaut-maven-integration-tests/pom.xml b/micronaut-maven-integration-tests/pom.xml index ed47656cf..12a12d69a 100644 --- a/micronaut-maven-integration-tests/pom.xml +++ b/micronaut-maven-integration-tests/pom.xml @@ -19,6 +19,7 @@ true true + 4.7.0 4.6.2 @@ -74,7 +75,7 @@ org.apache.groovy groovy - 4.0.23 + ${groovy.version} diff --git a/micronaut-maven-integration-tests/src/it/multi-project-multi-runnable-error/lib/pom.xml b/micronaut-maven-integration-tests/src/it/multi-project-multi-runnable-error/lib/pom.xml index 4f73b7819..fd6f771c2 100644 --- a/micronaut-maven-integration-tests/src/it/multi-project-multi-runnable-error/lib/pom.xml +++ b/micronaut-maven-integration-tests/src/it/multi-project-multi-runnable-error/lib/pom.xml @@ -14,6 +14,7 @@ @it.micronaut.version@ + @it.micronaut.core.version@ @@ -90,7 +91,7 @@ io.micronaut micronaut-http-validation - ${micronaut.version} + ${micronaut.core.version} diff --git a/micronaut-maven-integration-tests/src/it/multi-project-multi-runnable/lib/pom.xml b/micronaut-maven-integration-tests/src/it/multi-project-multi-runnable/lib/pom.xml index 4f73b7819..fd6f771c2 100644 --- a/micronaut-maven-integration-tests/src/it/multi-project-multi-runnable/lib/pom.xml +++ b/micronaut-maven-integration-tests/src/it/multi-project-multi-runnable/lib/pom.xml @@ -14,6 +14,7 @@ @it.micronaut.version@ + @it.micronaut.core.version@ @@ -90,7 +91,7 @@ io.micronaut micronaut-http-validation - ${micronaut.version} + ${micronaut.core.version} diff --git a/micronaut-maven-integration-tests/src/it/multi-project/lib/pom.xml b/micronaut-maven-integration-tests/src/it/multi-project/lib/pom.xml index 4f73b7819..fd6f771c2 100644 --- a/micronaut-maven-integration-tests/src/it/multi-project/lib/pom.xml +++ b/micronaut-maven-integration-tests/src/it/multi-project/lib/pom.xml @@ -14,6 +14,7 @@ @it.micronaut.version@ + @it.micronaut.core.version@ @@ -90,7 +91,7 @@ io.micronaut micronaut-http-validation - ${micronaut.version} + ${micronaut.core.version} diff --git a/micronaut-maven-integration-tests/src/it/openapi-generate-server-mapped-types/pom.xml b/micronaut-maven-integration-tests/src/it/openapi-generate-server-mapped-types/pom.xml index b68007f95..d3252ebc1 100644 --- a/micronaut-maven-integration-tests/src/it/openapi-generate-server-mapped-types/pom.xml +++ b/micronaut-maven-integration-tests/src/it/openapi-generate-server-mapped-types/pom.xml @@ -165,7 +165,11 @@ true - + + true + @io.micronaut.aot.core.AOTModule + @io.test.MyAnnotation + diff --git a/micronaut-maven-integration-tests/src/it/openapi-generate-server-mapped-types/src/main/java/io/micronaut/openapi/controller/MappedController.java b/micronaut-maven-integration-tests/src/it/openapi-generate-server-mapped-types/src/main/java/io/micronaut/openapi/controller/MappedController.java index 7ed65aa72..a2f87bf81 100644 --- a/micronaut-maven-integration-tests/src/it/openapi-generate-server-mapped-types/src/main/java/io/micronaut/openapi/controller/MappedController.java +++ b/micronaut-maven-integration-tests/src/it/openapi-generate-server-mapped-types/src/main/java/io/micronaut/openapi/controller/MappedController.java @@ -1,6 +1,5 @@ package io.micronaut.openapi.controller; - import io.micronaut.http.annotation.*; import reactor.core.publisher.Mono; import io.micronaut.openapi.dated.DatedResponse; @@ -25,7 +24,6 @@ import io.micronaut.openapi.api.MappedApi; import java.time.ZonedDateTime; - @Controller public class MappedController implements MappedApi { diff --git a/micronaut-maven-integration-tests/src/it/openapi-generate-server/pom.xml b/micronaut-maven-integration-tests/src/it/openapi-generate-server/pom.xml index afc9c485d..fadb93104 100644 --- a/micronaut-maven-integration-tests/src/it/openapi-generate-server/pom.xml +++ b/micronaut-maven-integration-tests/src/it/openapi-generate-server/pom.xml @@ -14,6 +14,7 @@ @it.micronaut.version@ + 1.18.34 @project.version@ jar netty @@ -24,6 +25,11 @@ + + org.projectlombok + lombok + provided + io.micronaut micronaut-inject @@ -101,6 +107,12 @@ io.micronaut.maven micronaut-maven-plugin ${micronaut-maven-plugin.version} + + true + + StreamingFileUpload + + org.apache.maven.plugins @@ -109,6 +121,11 @@ + + org.projectlombok + lombok + ${lombok.version} + io.micronaut micronaut-graal diff --git a/micronaut-maven-integration-tests/src/it/openapi-generate-server/verify.groovy b/micronaut-maven-integration-tests/src/it/openapi-generate-server/verify.groovy index 66381ba95..873db09bc 100644 --- a/micronaut-maven-integration-tests/src/it/openapi-generate-server/verify.groovy +++ b/micronaut-maven-integration-tests/src/it/openapi-generate-server/verify.groovy @@ -10,3 +10,10 @@ assert new File(basedir, "target/classes/io/micronaut/openapi/api/PetApi.class") assert new File(basedir, "target/classes/io/micronaut/openapi/model/Pet.class").exists() assert !petApi.text.contains("import jakarta.annotation.Generated;") + +def category = new File(basedir, "target/generated-sources/openapi/src/main/java/io/micronaut/openapi/model/Category.java") +assert category.exists() +assert category.text.contains("@Accessors(chain = true)") +assert category.text.contains("@NoArgsConstructor") +assert category.text.contains("@AllArgsConstructor") +assert category.text.contains("@Data") diff --git a/micronaut-maven-jib-integration/pom.xml b/micronaut-maven-jib-integration/pom.xml index 816dea394..ce1cbe481 100644 --- a/micronaut-maven-jib-integration/pom.xml +++ b/micronaut-maven-jib-integration/pom.xml @@ -32,17 +32,17 @@ com.google.cloud.tools jib-maven-plugin-extension-api - 0.4.0 + ${jib.maven-plugin-extension-api.version} com.google.cloud.tools jib-native-image-extension-maven - 0.1.0 + ${jib.maven-native-image-extension.version} com.google.cloud.tools jib-core - 0.27.1 + ${jib.core.version} org.yaml diff --git a/micronaut-maven-plugin/pom.xml b/micronaut-maven-plugin/pom.xml index 6859b7c7d..9fa4db854 100644 --- a/micronaut-maven-plugin/pom.xml +++ b/micronaut-maven-plugin/pom.xml @@ -42,7 +42,7 @@ org.apache.maven.shared maven-invoker - 3.3.0 + ${maven.invoker-plugin.version} org.apache.maven.plugin-tools @@ -56,7 +56,7 @@ org.twdata.maven mojo-executor - 2.4.0 + ${mojo-executor.version} io.methvin @@ -71,12 +71,12 @@ org.apache.commons commons-compress - 1.26.2 + ${commons-compress.version} org.apache.commons commons-lang3 - 3.17.0 + ${commons-lang3.version} @@ -98,7 +98,7 @@ org.fusesource.jansi jansi - 2.4.1 + ${jansi.version} @@ -114,13 +114,13 @@ org.apache.maven.plugin-testing maven-plugin-testing-harness - 3.3.0 + ${maven.testing-harness-plugin.version} test org.mockito mockito-core - 5.12.0 + ${mockito.version} test diff --git a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/AbstractOpenApiMojo.java b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/AbstractOpenApiMojo.java index 5f8eefd51..f89b5558b 100644 --- a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/AbstractOpenApiMojo.java +++ b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/AbstractOpenApiMojo.java @@ -28,6 +28,7 @@ import java.io.File; import java.util.List; import java.util.Locale; +import java.util.Map; /** * Base class for OpenAPI generator mojos. This provides the common @@ -69,6 +70,12 @@ public abstract class AbstractOpenApiMojo extends AbstractMicronautMojo { @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".use.bean.validation", defaultValue = "true", required = true) protected boolean useBeanValidation; + /** + * Flag to indicate whether to use the utils.OneOfImplementorAdditionalData related logic. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".use.one.of.interfaces", defaultValue = "true", required = true) + protected boolean useOneOfInterfaces; + /** * Whether to use {@link java.util.Optional} for non-required model properties and API parameters. */ @@ -81,6 +88,36 @@ public abstract class AbstractOpenApiMojo extends AbstractMicronautMojo { @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".use.reactive", defaultValue = "true", required = true) protected boolean useReactive; + /** + * Configure the serialization library. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".serialization.framework", defaultValue = "MICRONAUT_SERDE_JACKSON", required = true) + protected String serializationFramework; + + /** + * If true, the generated operation return types will be wrapped in HttpResponse. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".always.use.generate.http.response", defaultValue = "false", required = true) + protected boolean alwaysUseGenerateHttpResponse; + + /** + * Wrap the operations response in HttpResponse object where non-200 HTTP status codes or additional headers are defined. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".generate.http.response.where.required", defaultValue = "false", required = true) + protected boolean generateHttpResponseWhereRequired; + + /** + * If set to true, generated code will be fully compatible with KSP, but not 100% with KAPT. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".ksp", defaultValue = "false", required = true) + protected boolean ksp; + + /** + * Configure the date-time format. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".date.time.format", defaultValue = "ZONED_DATETIME", required = true) + protected String dateTimeFormat; + /** * Comma-separated values of output kinds to generate. The values are defined by the * {@link MicronautCodeGeneratorEntryPoint.OutputKind} enum. @@ -108,6 +145,84 @@ public abstract class AbstractOpenApiMojo extends AbstractMicronautMojo { @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".responseBodyMappings") protected List responseBodyMappings; + /** + * Add the schema mappings. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".schemaMapping") + protected Map schemaMapping; + + /** + * Add the import mappings. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".importMapping") + protected Map importMapping; + + /** + * Add the name mappings. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".nameMapping") + protected Map nameMapping; + + /** + * Add the type mappings. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".typeMapping") + protected Map typeMapping; + + /** + * Add the enum name mappings. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".enumNameMapping") + protected Map enumNameMapping; + + /** + * Add the model name mappings. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".modelNameMapping") + protected Map modelNameMapping; + + /** + * Add the inline schema name mappings. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".inlineSchemaNameMapping") + protected Map inlineSchemaNameMapping; + + /** + * Add the inline schema options. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".inlineSchemaOption") + protected Map inlineSchemaOption; + + /** + * Add the OpenAPI normalizer options. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".openapiNormalizer") + protected Map openapiNormalizer; + + /** + * Set the api name prefix. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".apiNamePrefix") + protected String apiNamePrefix; + + /** + * Set the api name suffix. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".apiNameSuffix") + protected String apiNameSuffix; + + /** + * Set the model name prefix. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".modelNamePrefix") + protected String modelNamePrefix; + + /** + * Set the model name suffix. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".modelNameSuffix") + protected String modelNameSuffix; + /** * Allows specifying the language of the generated code. * @@ -116,8 +231,119 @@ public abstract class AbstractOpenApiMojo extends AbstractMicronautMojo { @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".lang", defaultValue = "java") protected String lang; + /** + * If set to true, the generated enums check enum value with ignoring case. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".useEnumCaseInsensitive", defaultValue = "false") + protected boolean useEnumCaseInsensitive; + + /** + * Additional annotations for enum type (class level annotations). + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".additionalEnumTypeAnnotations") + protected List additionalEnumTypeAnnotations; + + /** + * Additional annotations for model type (class level annotations). + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".additionalModelTypeAnnotations") + protected List additionalModelTypeAnnotations; + + /** + * Additional annotations for oneOf interfaces (class level annotations). + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".additionalOneOfTypeAnnotations") + protected List additionalOneOfTypeAnnotations; + + /** + * Additional generator properties. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".additionalProperties") + protected Map additionalProperties; + + /** + * If set to true, controller and client method will be generated with openAPI annotations. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".generateSwaggerAnnotations", defaultValue = "false") + protected boolean generateSwaggerAnnotations; + + /** + * Set the implicit headers flag. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".implicitHeaders", defaultValue = "false") + protected boolean implicitHeaders; + + /** + * Set the implicit headers regex. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".implicitHeadersRegex") + protected String implicitHeadersRegex; + + /** + * Flag to indicate whether to use the "jakarta" or "javax" package. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".useJakartaEe", defaultValue = "true") + protected boolean useJakartaEe = true; + + /** + * Sort method arguments to place required parameters before optional parameters. + * Default: true + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".sortParamsByRequiredFlag", defaultValue = "true") + protected boolean sortParamsByRequiredFlag = true; + + /** + * Skip examples defined in operations to avoid out of memory errors. + * Default: false + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".skipOperationExample") + protected boolean skipOperationExample; + + /** + * Skip sorting operations. + * Default: false + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".skipSortingOperations") + protected boolean skipSortingOperations; + + /** + * Character to use as a delimiter for the prefix. Default: '_' + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".removeOperationIdPrefixDelimiter", defaultValue = "_") + protected String removeOperationIdPrefixDelimiter = "_"; + + /** + * Count of delimiter for the prefix. Use -1 for last. Default: 1 + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".removeOperationIdPrefixCount", defaultValue = "1") + protected int removeOperationIdPrefixCount = 1; + + /** + * Sort model properties to place required parameters before optional parameters. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".sortModelPropertiesByRequiredFlag", defaultValue = "true") + protected boolean sortModelPropertiesByRequiredFlag = true; + + /** + * Whether to ensure parameter names are unique in an operation (rename parameters that are not). + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".ensureUniqueParams", defaultValue = "true") + protected boolean ensureUniqueParams = true; + + /** + * boolean, toggles whether Unicode identifiers are allowed in names or not, default is false. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".allowUnicodeIdentifiers") + protected boolean allowUnicodeIdentifiers; + + /** + * Add form or body parameters to the beginning of the parameter list. + */ + @Parameter(property = MICRONAUT_OPENAPI_PREFIX + ".prependFormOrBodyParameters") + protected boolean prependFormOrBodyParameters; + @Parameter(defaultValue = "${project}", readonly = true) - private MavenProject project; + protected MavenProject project; /** * Determines if this mojo must be executed. @@ -142,6 +368,7 @@ public final void execute() throws MojoExecutionException, MojoFailureException getLog().debug(this.getClass().getSimpleName() + " is disabled"); return; } + project.addCompileSourceRoot(outputDirectory.getAbsolutePath()); var builder = MicronautCodeGeneratorEntryPoint.builder() .withDefinitionFile(definitionFile.toURI()) @@ -149,16 +376,20 @@ public final void execute() throws MojoExecutionException, MojoFailureException .withOutputs( outputKinds.stream().map(String::toUpperCase).map(MicronautCodeGeneratorEntryPoint.OutputKind::valueOf).toList().toArray(new MicronautCodeGeneratorEntryPoint.OutputKind[0]) ) - .withOptions(options -> { - options.withLang(MicronautCodeGeneratorOptionsBuilder.GeneratorLanguage.valueOf(lang.toUpperCase(Locale.ENGLISH))); - options.withInvokerPackage(invokerPackageName); - options.withApiPackage(apiPackageName); - options.withModelPackage(modelPackageName); - options.withBeanValidation(useBeanValidation); - options.withOptional(useOptional); - options.withReactive(useReactive); - options.withSerializationLibrary(SerializationLibraryKind.MICRONAUT_SERDE_JACKSON); - options.withParameterMappings(parameterMappings.stream() + .withOptions(options -> options + .withLang(MicronautCodeGeneratorOptionsBuilder.GeneratorLanguage.valueOf(lang.toUpperCase(Locale.ENGLISH))) + .withApiPackage(apiPackageName) + .withModelPackage(modelPackageName) + .withInvokerPackage(invokerPackageName) + .withBeanValidation(useBeanValidation) + .withUseOneOfInterfaces(useOneOfInterfaces) + .withOptional(useOptional) + .withReactive(useReactive) + .withSerializationLibrary(SerializationLibraryKind.valueOf(serializationFramework.toUpperCase(Locale.ENGLISH))) + .withGenerateHttpResponseAlways(alwaysUseGenerateHttpResponse) + .withGenerateHttpResponseWhereRequired(generateHttpResponseWhereRequired) + .withDateTimeFormat(MicronautCodeGeneratorOptionsBuilder.DateTimeFormat.valueOf(dateTimeFormat.toUpperCase(Locale.ENGLISH))) + .withParameterMappings(parameterMappings.stream() .map(mapping -> new io.micronaut.openapi.generator.ParameterMapping( mapping.getName(), io.micronaut.openapi.generator.ParameterMapping.ParameterLocation.valueOf( @@ -169,8 +400,8 @@ public final void execute() throws MojoExecutionException, MojoFailureException mapping.isValidated() )) .toList() - ); - options.withResponseBodyMappings(responseBodyMappings.stream() + ) + .withResponseBodyMappings(responseBodyMappings.stream() .map(mapping -> new io.micronaut.openapi.generator.ResponseBodyMapping( mapping.getHeaderName(), mapping.getMappedBodyType(), @@ -178,8 +409,40 @@ public final void execute() throws MojoExecutionException, MojoFailureException mapping.isValidated() )) .toList() - ); - }); + ) + .withSchemaMapping(schemaMapping) + .withImportMapping(importMapping) + .withNameMapping(nameMapping) + .withTypeMapping(typeMapping) + .withEnumNameMapping(enumNameMapping) + .withModelNameMapping(modelNameMapping) + .withInlineSchemaNameMapping(inlineSchemaNameMapping) + .withInlineSchemaOption(inlineSchemaOption) + .withOpenapiNormalizer(openapiNormalizer) + .withApiNamePrefix(apiNamePrefix != null ? apiNamePrefix : "") + .withApiNameSuffix(apiNameSuffix != null ? apiNameSuffix : "") + .withModelNamePrefix(modelNamePrefix != null ? modelNamePrefix : "") + .withModelNameSuffix(modelNameSuffix != null ? modelNameSuffix : "") + .withGenerateSwaggerAnnotations(generateSwaggerAnnotations) + .withImplicitHeaders(implicitHeaders) + .withImplicitHeadersRegex(implicitHeadersRegex != null ? implicitHeadersRegex : "") + .withUseEnumCaseInsensitive(useEnumCaseInsensitive) + .withAdditionalEnumTypeAnnotations(additionalEnumTypeAnnotations) + .withAdditionalModelTypeAnnotations(additionalModelTypeAnnotations) + .withAdditionalOneOfTypeAnnotations(additionalOneOfTypeAnnotations) + .withAdditionalProperties(additionalProperties) + + .withUseJakartaEe(useJakartaEe) + .withSortParamsByRequiredFlag(sortParamsByRequiredFlag) + .withSkipOperationExample(skipOperationExample) + .withSkipSortingOperations(skipSortingOperations) + .withRemoveOperationIdPrefixDelimiter(removeOperationIdPrefixDelimiter) + .withRemoveOperationIdPrefixCount(removeOperationIdPrefixCount) + .withSortModelPropertiesByRequiredFlag(sortModelPropertiesByRequiredFlag) + .withEnsureUniqueParams(ensureUniqueParams) + .withAllowUnicodeIdentifiers(allowUnicodeIdentifiers) + .withPrependFormOrBodyParameters(prependFormOrBodyParameters) + ); configureBuilder(builder); builder.build().generate(); } diff --git a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiClientMojo.java b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiClientMojo.java index bc776d16a..b94d3e6dc 100644 --- a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiClientMojo.java +++ b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiClientMojo.java @@ -28,7 +28,9 @@ */ @Mojo(name = OpenApiClientMojo.MOJO_NAME, defaultPhase = LifecyclePhase.GENERATE_SOURCES) public class OpenApiClientMojo extends AbstractOpenApiMojo { + public static final String MOJO_NAME = "generate-openapi-client"; + private static final String CLIENT_PREFIX = MICRONAUT_OPENAPI_PREFIX + ".client."; /** @@ -37,6 +39,12 @@ public class OpenApiClientMojo extends AbstractOpenApiMojo { @Parameter(property = CLIENT_PREFIX + "id") protected String clientId; + /** + * If set to true, Api annotation {@literal @}Client will be with `path` attribute. + */ + @Parameter(property = CLIENT_PREFIX + "path") + protected boolean clientPath; + /** * Whether to configure authentication for client. */ @@ -98,9 +106,14 @@ protected boolean isEnabled() { @Override protected void configureBuilder(MicronautCodeGeneratorBuilder builder) { - if ("java".equalsIgnoreCase(lang)) { - builder.forJavaClient(spec -> { - spec.withAuthorization(useAuth); + if ("kotlin".equalsIgnoreCase(lang)) { + builder.forKotlinClient(spec -> { + spec.withAuthorization(useAuth) + .withGeneratedAnnotation(generatedAnnotation) + .withFluxForArrays(fluxForArrays) + .withKsp(ksp) + .withClientPath(clientPath); + if (clientId != null && !clientId.isEmpty()) { spec.withClientId(clientId); } @@ -113,13 +126,15 @@ protected void configureBuilder(MicronautCodeGeneratorBuilder builder) { if (authorizationFilterPattern != null) { spec.withAuthorizationFilterPattern(authorizationFilterPattern); } - spec.withLombok(lombok); - spec.withFluxForArrays(fluxForArrays); - spec.withGeneratedAnnotation(generatedAnnotation); }); - } else if ("kotlin".equalsIgnoreCase(lang)) { - builder.forKotlinClient(spec -> { - spec.withAuthorization(useAuth); + } else if ("java".equalsIgnoreCase(lang)) { + builder.forJavaClient(spec -> { + spec.withAuthorization(useAuth) + .withLombok(lombok) + .withGeneratedAnnotation(generatedAnnotation) + .withFluxForArrays(fluxForArrays) + .withClientPath(clientPath); + if (clientId != null && !clientId.isEmpty()) { spec.withClientId(clientId); } @@ -132,8 +147,6 @@ protected void configureBuilder(MicronautCodeGeneratorBuilder builder) { if (authorizationFilterPattern != null) { spec.withAuthorizationFilterPattern(authorizationFilterPattern); } - spec.withFluxForArrays(fluxForArrays); - spec.withGeneratedAnnotation(generatedAnnotation); }); } else { throw new UnsupportedOperationException("Unsupported language:" + lang); diff --git a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiGenericMojo.java b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiGenericMojo.java index ebb1b9333..0920515e5 100644 --- a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiGenericMojo.java +++ b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiGenericMojo.java @@ -35,6 +35,7 @@ */ @Mojo(name = OpenApiGenericMojo.MOJO_NAME, defaultPhase = LifecyclePhase.GENERATE_SOURCES) public class OpenApiGenericMojo extends AbstractOpenApiMojo { + public static final String MOJO_NAME = "generate-openapi-generic"; public static final String CONFIGURATION_PROPERTIES = MICRONAUT_OPENAPI_PREFIX + ".generator.properties"; @@ -118,7 +119,7 @@ private static boolean invokeIfMatches(String name, GeneratorOptionsBuilder buil method.invoke(builder, value); return true; } else if (parameterType.equals(Boolean.TYPE)) { - var coerced = value.toLowerCase(Locale.US); + var coerced = value.toLowerCase(Locale.ENGLISH); if ("true".equals(coerced) || "false".equals(coerced)) { method.invoke(builder, Boolean.parseBoolean(coerced)); return true; @@ -136,6 +137,7 @@ private static boolean invokeIfMatches(String name, GeneratorOptionsBuilder buil * Exception to be thrown when OpenAPI generator configuration fails. */ static class OpenAPIInvocationException extends RuntimeException { + public OpenAPIInvocationException(String message) { super(message); } diff --git a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiServerMojo.java b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiServerMojo.java index 2506ee816..284535a3c 100644 --- a/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiServerMojo.java +++ b/micronaut-maven-plugin/src/main/java/io/micronaut/maven/openapi/OpenApiServerMojo.java @@ -26,7 +26,9 @@ */ @Mojo(name = OpenApiServerMojo.MOJO_NAME, defaultPhase = LifecyclePhase.GENERATE_SOURCES) public class OpenApiServerMojo extends AbstractOpenApiMojo { + public static final String MOJO_NAME = "generate-openapi-server"; + private static final String SERVER_PREFIX = MICRONAUT_OPENAPI_PREFIX + ".server."; /** @@ -86,31 +88,32 @@ protected boolean isEnabled() { @Override protected void configureBuilder(MicronautCodeGeneratorBuilder builder) { - if ("java".equalsIgnoreCase(lang)) { - builder.forJavaServer(spec -> { - spec.withControllerPackage(controllerPackageName); - spec.withAuthentication(useAuth); + if ("kotlin".equalsIgnoreCase(lang)) { + builder.forKotlinServer(spec -> spec + .withControllerPackage(controllerPackageName) + .withAuthentication(useAuth) + .withAot(aotCompatible) // we don't want these to be configurable in the plugin for now - spec.withGenerateImplementationFiles(false); - spec.withGenerateControllerFromExamples(false); - spec.withGenerateOperationsToReturnNotImplemented(false); - spec.withLombok(lombok); - spec.withFluxForArrays(fluxForArrays); - spec.withGeneratedAnnotation(generatedAnnotation); - spec.withAot(aotCompatible); - }); - } else if ("kotlin".equalsIgnoreCase(lang)) { - builder.forKotlinServer(spec -> { - spec.withControllerPackage(controllerPackageName); - spec.withAuthentication(useAuth); + .withGenerateImplementationFiles(false) + .withGenerateControllerFromExamples(false) + .withGenerateOperationsToReturnNotImplemented(false) + .withGeneratedAnnotation(generatedAnnotation) + .withFluxForArrays(fluxForArrays) + .withKsp(ksp) + ); + } else if ("java".equalsIgnoreCase(lang)) { + builder.forJavaServer(spec -> spec + .withControllerPackage(controllerPackageName) + .withAuthentication(useAuth) + .withAot(aotCompatible) // we don't want these to be configurable in the plugin for now - spec.withGenerateImplementationFiles(false); - spec.withGenerateControllerFromExamples(false); - spec.withGenerateOperationsToReturnNotImplemented(false); - spec.withFluxForArrays(fluxForArrays); - spec.withGeneratedAnnotation(generatedAnnotation); - spec.withAot(aotCompatible); - }); + .withGenerateImplementationFiles(false) + .withGenerateControllerFromExamples(false) + .withGenerateOperationsToReturnNotImplemented(false) + .withGeneratedAnnotation(generatedAnnotation) + .withFluxForArrays(fluxForArrays) + .withLombok(lombok) + ); } else { throw new UnsupportedOperationException("Unsupported language: " + lang); } diff --git a/pom.xml b/pom.xml index 2416a2f19..de7b8a119 100644 --- a/pom.xml +++ b/pom.xml @@ -72,15 +72,23 @@ 17 17 - 3.9.8 + 3.9.9 4.6.2 0.10.3 - 2.4.0 + 2.5.0 2.6.2 - 6.11.1 + 6.13.0 3.3.1 - 3.6.0 + 3.6.2 + 3.3.0 + 3.3.0 + 3.5.0 + 3.4.2 + 0.27.1 + 0.4.0 + 0.1.0 + 3.0.0 ${project.artifactId} ${project.name} @@ -99,8 +107,13 @@ 5.11.2 0.18.0 1.20.2 - 3.4.2 - 2.2 + 5.14.2 + 4.0.23 + 1.27.1 + 3.17.0 + 2.4.1 + 2.4.0 + 2.3 0.9.0.M2 3.4.0 ${maven.multiModuleProjectDirectory}/config/checkstyle @@ -169,16 +182,6 @@ junit-jupiter-params ${junit-jupiter.version} - - io.swagger.parser - swagger-parser - 1.0.67 - - - io.swagger.parser.v3 - swagger-parser - 2.1.22 - com.github.docker-java docker-java-core @@ -547,7 +550,7 @@ org.asciidoctor asciidoctor-maven-plugin - 3.0.0 + ${asciidoctor-plugin.version}