diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b17a8cf1..d718ee5e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,10 +13,10 @@ log4j2 = "2.24.1" jetbrains-annotations = "24.1.0" tomlj = "1.1.1" -micronaut-platform = "4.6.0" # This is the platform version, used in our tests +micronaut-platform = "4.6.3" # This is the platform version, used in our tests micronaut-aot = "2.5.0" micronaut-testresources = "2.6.2" -micronaut-openapi = "6.12.2" +micronaut-openapi = "6.13.1" [libraries] # Core diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/DefaultOpenApiExtension.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/DefaultOpenApiExtension.java index 5d671801..f3292b2d 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/DefaultOpenApiExtension.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/DefaultOpenApiExtension.java @@ -126,6 +126,26 @@ private void configureCommonExtensionDefaults(OpenApiSpec spec) { spec.getGenerateHttpResponseWhereRequired().convention(false); spec.getDateTimeFormat().convention("ZONED_DATETIME"); spec.getLang().convention("java"); + spec.getGenerateSwaggerAnnotations().convention(false); + spec.getApiNamePrefix().convention(""); + spec.getApiNameSuffix().convention(""); + spec.getModelNamePrefix().convention(""); + spec.getModelNameSuffix().convention(""); + spec.getImplicitHeaders().convention(false); + spec.getImplicitHeadersRegex().convention(""); + spec.getUseEnumCaseInsensitive().convention(false); + + spec.getUseJakartaEe().convention(true); + spec.getSortParamsByRequiredFlag().convention(true); + spec.getSkipOperationExample().convention(false); + spec.getSkipSortingOperations().convention(false); + spec.getRemoveOperationIdPrefixDelimiter().convention("_"); + spec.getRemoveOperationIdPrefixCount().convention(1); + spec.getSortModelPropertiesByRequiredFlag().convention(true); + spec.getEnsureUniqueParams().convention(true); + spec.getAllowUnicodeIdentifiers().convention(false); + spec.getPrependFormOrBodyParameters().convention(false); + withJava(() -> { var compileOnlyDeps = project.getConfigurations().getByName("compileOnly").getDependencies(); if ("java".equalsIgnoreCase(spec.getLang().get())) { @@ -190,9 +210,26 @@ private void configureCommonProperties(String name, AbstractOpenApiGenerator consumer) { diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/OpenApiSpec.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/OpenApiSpec.java index 26844bcd..2cf74c97 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/OpenApiSpec.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/OpenApiSpec.java @@ -18,6 +18,8 @@ import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; +import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.Optional; public interface OpenApiSpec { @@ -83,9 +85,39 @@ public interface OpenApiSpec { Property getModelNameSuffix(); + Property getUseEnumCaseInsensitive(); + Property getGenerateSwaggerAnnotations(); Property getImplicitHeaders(); Property getImplicitHeadersRegex(); + + ListProperty getAdditionalEnumTypeAnnotations(); + + ListProperty getAdditionalModelTypeAnnotations(); + + ListProperty getAdditionalOneOfTypeAnnotations(); + + MapProperty getAdditionalProperties(); + + Property getUseJakartaEe(); + + Property getSortParamsByRequiredFlag(); + + Property getSkipOperationExample(); + + Property getSkipSortingOperations(); + + Property getRemoveOperationIdPrefixDelimiter(); + + Property getRemoveOperationIdPrefixCount(); + + Property getSortModelPropertiesByRequiredFlag(); + + Property getEnsureUniqueParams(); + + Property getAllowUnicodeIdentifiers(); + + Property getPrependFormOrBodyParameters(); } diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/AbstractOpenApiGenerator.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/AbstractOpenApiGenerator.java index b0843720..cf5c894c 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/AbstractOpenApiGenerator.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/AbstractOpenApiGenerator.java @@ -146,6 +146,10 @@ public abstract class AbstractOpenApiGenerator getModelNameSuffix(); + @Optional + @Input + public abstract Property getUseEnumCaseInsensitive(); + @Optional @Input public abstract Property getGenerateSwaggerAnnotations(); @@ -158,6 +162,62 @@ public abstract class AbstractOpenApiGenerator getImplicitHeadersRegex(); + @Optional + @Input + public abstract ListProperty getAdditionalEnumTypeAnnotations(); + + @Optional + @Input + public abstract ListProperty getAdditionalModelTypeAnnotations(); + + @Optional + @Input + public abstract ListProperty getAdditionalOneOfTypeAnnotations(); + + @Optional + @Input + public abstract MapProperty getAdditionalProperties(); + + @Optional + @Input + public abstract Property getUseJakartaEe(); + + @Optional + @Input + public abstract Property getSortParamsByRequiredFlag(); + + @Optional + @Input + public abstract Property getSkipOperationExample(); + + @Optional + @Input + public abstract Property getSkipSortingOperations(); + + @Optional + @Input + public abstract Property getRemoveOperationIdPrefixDelimiter(); + + @Optional + @Input + public abstract Property getRemoveOperationIdPrefixCount(); + + @Optional + @Input + public abstract Property getSortModelPropertiesByRequiredFlag(); + + @Optional + @Input + public abstract Property getEnsureUniqueParams(); + + @Optional + @Input + public abstract Property getAllowUnicodeIdentifiers(); + + @Optional + @Input + public abstract Property getPrependFormOrBodyParameters(); + @OutputDirectory public abstract DirectoryProperty getOutputDirectory(); @@ -209,10 +269,27 @@ public final void execute() { params.getModelNamePrefix().set(getModelNamePrefix().orElse("")); params.getModelNameSuffix().set(getModelNameSuffix().orElse("")); + params.getUseEnumCaseInsensitive().set(getUseEnumCaseInsensitive()); params.getGenerateSwaggerAnnotations().set(getGenerateSwaggerAnnotations()); params.getImplicitHeaders().set(getImplicitHeaders()); params.getImplicitHeadersRegex().set(getImplicitHeadersRegex().orElse("")); + params.getAdditionalEnumTypeAnnotations().set(getAdditionalEnumTypeAnnotations()); + params.getAdditionalModelTypeAnnotations().set(getAdditionalModelTypeAnnotations()); + params.getAdditionalOneOfTypeAnnotations().set(getAdditionalOneOfTypeAnnotations()); + params.getAdditionalProperties().set(getAdditionalProperties()); + + params.getUseJakartaEe().set(getUseJakartaEe().get()); + params.getSortParamsByRequiredFlag().set(getSortParamsByRequiredFlag().get()); + params.getSkipOperationExample().set(getSkipOperationExample().get()); + params.getSkipSortingOperations().set(getSkipSortingOperations().get()); + params.getRemoveOperationIdPrefixDelimiter().set(getRemoveOperationIdPrefixDelimiter().get()); + params.getRemoveOperationIdPrefixCount().set(getRemoveOperationIdPrefixCount().get()); + params.getSortModelPropertiesByRequiredFlag().set(getSortModelPropertiesByRequiredFlag().get()); + params.getEnsureUniqueParams().set(getEnsureUniqueParams().get()); + params.getAllowUnicodeIdentifiers().set(getAllowUnicodeIdentifiers().get()); + params.getPrependFormOrBodyParameters().set(getPrependFormOrBodyParameters().get()); + configureWorkerParameters(params); }); } diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/AbstractOpenApiWorkAction.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/AbstractOpenApiWorkAction.java index 282a362b..2af3be40 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/AbstractOpenApiWorkAction.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/AbstractOpenApiWorkAction.java @@ -106,11 +106,41 @@ interface OpenApiParameters extends WorkParameters { Property getModelNameSuffix(); + Property getUseEnumCaseInsensitive(); + Property getGenerateSwaggerAnnotations(); Property getImplicitHeaders(); Property getImplicitHeadersRegex(); + + ListProperty getAdditionalEnumTypeAnnotations(); + + ListProperty getAdditionalModelTypeAnnotations(); + + ListProperty getAdditionalOneOfTypeAnnotations(); + + MapProperty getAdditionalProperties(); + + Property getUseJakartaEe(); + + Property getSortParamsByRequiredFlag(); + + Property getSkipOperationExample(); + + Property getSkipSortingOperations(); + + Property getRemoveOperationIdPrefixDelimiter(); + + Property getRemoveOperationIdPrefixCount(); + + Property getSortModelPropertiesByRequiredFlag(); + + Property getEnsureUniqueParams(); + + Property getAllowUnicodeIdentifiers(); + + Property getPrependFormOrBodyParameters(); } protected abstract void configureBuilder(MicronautCodeGeneratorBuilder builder); @@ -131,8 +161,8 @@ public void execute() { .withOptions(options -> options .withLang("kotlin".equalsIgnoreCase(lang) ? GeneratorLanguage.KOTLIN : GeneratorLanguage.JAVA) .withApiPackage(parameters.getApiPackageName().get()) - .withModelPackage(parameters.getModelPackageName().get()) .withInvokerPackage(parameters.getInvokerPackageName().get()) + .withModelPackage(parameters.getModelPackageName().get()) .withBeanValidation(parameters.getUseBeanValidation().get()) .withUseOneOfInterfaces(parameters.getUseOneOfInterfaces().get()) .withOptional(parameters.getUseOptional().get()) @@ -172,13 +202,29 @@ public void execute() { .withInlineSchemaNameMapping(parameters.getInlineSchemaNameMapping().get()) .withInlineSchemaOption(parameters.getInlineSchemaOption().get()) .withOpenapiNormalizer(parameters.getOpenapiNormalizer().get()) - .withApiNamePrefix(parameters.getApiNamePrefix().orElse("").get()) - .withApiNameSuffix(parameters.getApiNameSuffix().orElse("").get()) - .withModelNamePrefix(parameters.getModelNamePrefix().orElse("").get()) - .withModelNameSuffix(parameters.getModelNameSuffix().orElse("").get()) + .withApiNamePrefix(parameters.getApiNamePrefix().get()) + .withApiNameSuffix(parameters.getApiNameSuffix().get()) + .withModelNamePrefix(parameters.getModelNamePrefix().get()) + .withModelNameSuffix(parameters.getModelNameSuffix().get()) .withGenerateSwaggerAnnotations(parameters.getGenerateSwaggerAnnotations().get()) .withImplicitHeaders(parameters.getImplicitHeaders().get()) - .withImplicitHeadersRegex(parameters.getImplicitHeadersRegex().orElse("").get()) + .withImplicitHeadersRegex(parameters.getImplicitHeadersRegex().get()) + .withUseEnumCaseInsensitive(parameters.getUseEnumCaseInsensitive().get()) + .withAdditionalEnumTypeAnnotations(parameters.getAdditionalEnumTypeAnnotations().get()) + .withAdditionalModelTypeAnnotations(parameters.getAdditionalModelTypeAnnotations().get()) + .withAdditionalOneOfTypeAnnotations(parameters.getAdditionalOneOfTypeAnnotations().get()) + .withAdditionalProperties(parameters.getAdditionalProperties().get()) + + .withUseJakartaEe(parameters.getUseJakartaEe().get()) + .withSortParamsByRequiredFlag(parameters.getSortParamsByRequiredFlag().get()) + .withSkipOperationExample(parameters.getSkipOperationExample().get()) + .withSkipSortingOperations(parameters.getSkipSortingOperations().get()) + .withRemoveOperationIdPrefixDelimiter(parameters.getRemoveOperationIdPrefixDelimiter().get()) + .withRemoveOperationIdPrefixCount(parameters.getRemoveOperationIdPrefixCount().get()) + .withSortModelPropertiesByRequiredFlag(parameters.getSortModelPropertiesByRequiredFlag().get()) + .withEnsureUniqueParams(parameters.getEnsureUniqueParams().get()) + .withAllowUnicodeIdentifiers(parameters.getAllowUnicodeIdentifiers().get()) + .withPrependFormOrBodyParameters(parameters.getPrependFormOrBodyParameters().get()) ); configureBuilder(builder); diff --git a/openapi-plugin/src/test/groovy/io/micronaut/openapi/gradle/OpenApiClientGeneratorSpec.groovy b/openapi-plugin/src/test/groovy/io/micronaut/openapi/gradle/OpenApiClientGeneratorSpec.groovy index efc676c0..9d3a234c 100644 --- a/openapi-plugin/src/test/groovy/io/micronaut/openapi/gradle/OpenApiClientGeneratorSpec.groovy +++ b/openapi-plugin/src/test/groovy/io/micronaut/openapi/gradle/OpenApiClientGeneratorSpec.groovy @@ -70,6 +70,7 @@ class OpenApiClientGeneratorSpec extends AbstractOpenApiGeneratorSpec { clientId = "my-client" generateSwaggerAnnotations = true implicitHeadersRegex = ".*" + useEnumCaseInsensitive = true } } }