diff --git a/functional-tests/src/test/groovy/io/micronaut/gradle/openapi/OpenApiClientWithKotlinSpec.groovy b/functional-tests/src/test/groovy/io/micronaut/gradle/openapi/OpenApiClientWithKotlinSpec.groovy index 8ffb42081..08c6e97c2 100644 --- a/functional-tests/src/test/groovy/io/micronaut/gradle/openapi/OpenApiClientWithKotlinSpec.groovy +++ b/functional-tests/src/test/groovy/io/micronaut/gradle/openapi/OpenApiClientWithKotlinSpec.groovy @@ -25,6 +25,7 @@ class OpenApiClientWithKotlinSpec extends AbstractOpenApiWithKotlinSpec { useReactive = true generatedAnnotation = false fluxForArrays = true + nameMapping = [test: "changedTest"] } } } @@ -76,6 +77,8 @@ class OpenApiClientWithKotlinSpec extends AbstractOpenApiWithKotlinSpec { useReactive = true generatedAnnotation = false fluxForArrays = true + ksp = true + nameMapping = [test: "changedTest"] } } } diff --git a/functional-tests/src/test/groovy/io/micronaut/gradle/openapi/OpenApiServerWithKotlinSpec.groovy b/functional-tests/src/test/groovy/io/micronaut/gradle/openapi/OpenApiServerWithKotlinSpec.groovy index c9d4ae925..a93d345d7 100644 --- a/functional-tests/src/test/groovy/io/micronaut/gradle/openapi/OpenApiServerWithKotlinSpec.groovy +++ b/functional-tests/src/test/groovy/io/micronaut/gradle/openapi/OpenApiServerWithKotlinSpec.groovy @@ -28,6 +28,7 @@ class OpenApiServerWithKotlinSpec extends AbstractOpenApiWithKotlinSpec { generatedAnnotation = false fluxForArrays = true aot = true + nameMapping = [test: "changedTest"] } } } @@ -84,6 +85,8 @@ class OpenApiServerWithKotlinSpec extends AbstractOpenApiWithKotlinSpec { generatedAnnotation = false fluxForArrays = true aot = true + ksp = true + nameMapping = [test: "changedTest"] } } } diff --git a/functional-tests/src/test/resources/petstore.json b/functional-tests/src/test/resources/petstore.json index ad5523181..b46fa4127 100644 --- a/functional-tests/src/test/resources/petstore.json +++ b/functional-tests/src/test/resources/petstore.json @@ -963,6 +963,10 @@ }, "complete": { "type": "boolean" + }, + "test": { + "type": "string", + "description": "Test prop" } }, "xml": { 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 225492e22..0deee4f78 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 @@ -116,6 +116,7 @@ private void configureCommonExtensionDefaults(OpenApiSpec spec) { spec.getUseOptional().convention(false); spec.getUseReactive().convention(true); spec.getLombok().convention(false); + spec.getKsp().convention(false); spec.getGeneratedAnnotation().convention(true); spec.getFluxForArrays().convention(false); spec.getSerializationFramework().convention(DEFAULT_SERIALIZATION_FRAMEWORK); @@ -166,9 +167,20 @@ 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 b62e5d282..354695e15 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 @@ -16,6 +16,7 @@ package io.micronaut.gradle.openapi; import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; public interface OpenApiSpec { @@ -42,6 +43,8 @@ public interface OpenApiSpec { Property getLombok(); + Property getKsp(); + Property getGeneratedAnnotation(); Property getFluxForArrays(); @@ -51,4 +54,22 @@ public interface OpenApiSpec { ListProperty getParameterMappings(); ListProperty getResponseBodyMappings(); + + MapProperty getSchemaMapping(); + + MapProperty getImportMapping(); + + MapProperty getNameMapping(); + + MapProperty getTypeMapping(); + + MapProperty getEnumNameMapping(); + + MapProperty getModelNameMapping(); + + MapProperty getInlineSchemaNameMapping(); + + MapProperty getInlineSchemaOption(); + + MapProperty getOpenapiNormalizer(); } 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 fcd206e2d..b3968bdba 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 @@ -22,6 +22,7 @@ import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.Classpath; import org.gradle.api.tasks.Input; @@ -86,6 +87,9 @@ public abstract class AbstractOpenApiGenerator getLombok(); + @Input + public abstract Property getKsp(); + @Input public abstract Property getGeneratedAnnotation(); @@ -95,6 +99,33 @@ public abstract class AbstractOpenApiGenerator getResponseBodyMappings(); + @Input + public abstract MapProperty getSchemaMapping(); + + @Input + public abstract MapProperty getImportMapping(); + + @Input + public abstract MapProperty getNameMapping(); + + @Input + public abstract MapProperty getTypeMapping(); + + @Input + public abstract MapProperty getEnumNameMapping(); + + @Input + public abstract MapProperty getModelNameMapping(); + + @Input + public abstract MapProperty getInlineSchemaNameMapping(); + + @Input + public abstract MapProperty getInlineSchemaOption(); + + @Input + public abstract MapProperty getOpenapiNormalizer(); + @OutputDirectory public abstract DirectoryProperty getOutputDirectory(); @@ -129,6 +160,18 @@ public final void execute() { params.getFluxForArrays().set(getFluxForArrays()); params.getGeneratedAnnotation().set(getGeneratedAnnotation()); params.getLombok().set(getLombok()); + params.getKsp().set(getKsp()); + + params.getSchemaMapping().set(getSchemaMapping()); + params.getImportMapping().set(getImportMapping()); + params.getNameMapping().set(getNameMapping()); + params.getTypeMapping().set(getTypeMapping()); + params.getEnumNameMapping().set(getEnumNameMapping()); + params.getModelNameMapping().set(getModelNameMapping()); + params.getInlineSchemaNameMapping().set(getInlineSchemaNameMapping()); + params.getInlineSchemaOption().set(getInlineSchemaOption()); + params.getOpenapiNormalizer().set(getOpenapiNormalizer()); + 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 b6543c28e..1dfe8c033 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 @@ -30,6 +30,7 @@ import org.gradle.api.file.DirectoryProperty; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.provider.ListProperty; +import org.gradle.api.provider.MapProperty; import org.gradle.api.provider.Property; import org.gradle.workers.WorkAction; import org.gradle.workers.WorkParameters; @@ -68,6 +69,8 @@ interface OpenApiParameters extends WorkParameters { Property getLombok(); + Property getKsp(); + Property getGeneratedAnnotation(); Property getFluxForArrays(); @@ -75,6 +78,24 @@ interface OpenApiParameters extends WorkParameters { ListProperty getParameterMappings(); ListProperty getResponseBodyMappings(); + + MapProperty getSchemaMapping(); + + MapProperty getImportMapping(); + + MapProperty getNameMapping(); + + MapProperty getTypeMapping(); + + MapProperty getEnumNameMapping(); + + MapProperty getModelNameMapping(); + + MapProperty getInlineSchemaNameMapping(); + + MapProperty getInlineSchemaOption(); + + MapProperty getOpenapiNormalizer(); } protected abstract void configureBuilder(MicronautCodeGeneratorBuilder builder); @@ -118,9 +139,23 @@ public void execute() { .withResponseBodyMappings(parameters.getResponseBodyMappings() .get() .stream() - .map(mapping -> new ResponseBodyMapping(mapping.getHeaderName(), mapping.getMappedBodyType(), mapping.isListWrapper(), mapping.isValidated())) + .map(mapping -> new ResponseBodyMapping( + mapping.getHeaderName(), + mapping.getMappedBodyType(), + mapping.isListWrapper(), + mapping.isValidated())) .toList() - )); + ) + .withSchemaMapping(parameters.getSchemaMapping().get()) + .withImportMapping(parameters.getImportMapping().get()) + .withNameMapping(parameters.getNameMapping().get()) + .withTypeMapping(parameters.getTypeMapping().get()) + .withEnumNameMapping(parameters.getEnumNameMapping().get()) + .withModelNameMapping(parameters.getModelNameMapping().get()) + .withInlineSchemaNameMapping(parameters.getInlineSchemaNameMapping().get()) + .withInlineSchemaOption(parameters.getInlineSchemaOption().get()) + .withOpenapiNormalizer(parameters.getOpenapiNormalizer().get()) + ); configureBuilder(builder); builder.build().generate(); diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiClientWorkAction.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiClientWorkAction.java index f0f9bc44f..4cd745a5a 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiClientWorkAction.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiClientWorkAction.java @@ -44,7 +44,8 @@ protected void configureBuilder(MicronautCodeGeneratorBuilder builder) { builder.forKotlinClient(spec -> { spec.withAuthorization(parameters.getUseAuth().get()) .withAdditionalClientTypeAnnotations(parameters.getAdditionalClientTypeAnnotations().getOrElse(List.of())) - .withGeneratedAnnotation(parameters.getGeneratedAnnotation().get()); + .withGeneratedAnnotation(parameters.getGeneratedAnnotation().get()) + .withKsp(parameters.getKsp().get()); if (parameters.getClientId().isPresent()) { spec.withClientId(parameters.getClientId().get()); diff --git a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiServerWorkAction.java b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiServerWorkAction.java index 9189e1270..4c6a0f57d 100644 --- a/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiServerWorkAction.java +++ b/openapi-plugin/src/main/java/io/micronaut/gradle/openapi/tasks/OpenApiServerWorkAction.java @@ -42,6 +42,7 @@ protected void configureBuilder(MicronautCodeGeneratorBuilder builder) { .withGenerateControllerFromExamples(false) .withGenerateOperationsToReturnNotImplemented(false) .withGeneratedAnnotation(parameters.getGeneratedAnnotation().get()) + .withKsp(parameters.getKsp().get()) ); } else { builder.forJavaServer(spec -> spec.withControllerPackage(parameters.getControllerPackage().get()) 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 8d375d627..e583c7bde 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 @@ -66,6 +66,7 @@ class OpenApiClientGeneratorSpec extends AbstractOpenApiGeneratorSpec { useReactive = true generatedAnnotation = false fluxForArrays = true + nameMapping = [test: "changedTest"] } } } diff --git a/openapi-plugin/src/test/resources/petstore.json b/openapi-plugin/src/test/resources/petstore.json index d51aa2fc6..12e57fb74 100644 --- a/openapi-plugin/src/test/resources/petstore.json +++ b/openapi-plugin/src/test/resources/petstore.json @@ -963,6 +963,10 @@ }, "complete": { "type": "boolean" + }, + "test": { + "type": "string", + "description": "Test prop" } }, "xml": {