Skip to content

Commit

Permalink
New micronaut-openapi generator properties
Browse files Browse the repository at this point in the history
  • Loading branch information
altro3 committed Feb 11, 2024
1 parent 229d70d commit 4f317cb
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class OpenApiClientWithKotlinSpec extends AbstractOpenApiWithKotlinSpec {
useReactive = true
generatedAnnotation = false
fluxForArrays = true
nameMapping = [test: "changedTest"]
}
}
}
Expand Down Expand Up @@ -76,6 +77,8 @@ class OpenApiClientWithKotlinSpec extends AbstractOpenApiWithKotlinSpec {
useReactive = true
generatedAnnotation = false
fluxForArrays = true
ksp = true
nameMapping = [test: "changedTest"]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class OpenApiServerWithKotlinSpec extends AbstractOpenApiWithKotlinSpec {
generatedAnnotation = false
fluxForArrays = true
aot = true
nameMapping = [test: "changedTest"]
}
}
}
Expand Down Expand Up @@ -84,6 +85,8 @@ class OpenApiServerWithKotlinSpec extends AbstractOpenApiWithKotlinSpec {
generatedAnnotation = false
fluxForArrays = true
aot = true
ksp = true
nameMapping = [test: "changedTest"]
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions functional-tests/src/test/resources/petstore.json
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@
},
"complete": {
"type": "boolean"
},
"test": {
"type": "string",
"description": "Test prop"
}
},
"xml": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -166,9 +167,20 @@ private void configureCommonProperties(String name, AbstractOpenApiGenerator<?,
task.getParameterMappings().convention(openApiSpec.getParameterMappings());
task.getLang().convention(openApiSpec.getLang());
task.getLombok().convention(openApiSpec.getLombok());
task.getKsp().convention(openApiSpec.getKsp());
task.getGeneratedAnnotation().convention(openApiSpec.getGeneratedAnnotation());
task.getFluxForArrays().convention(openApiSpec.getFluxForArrays());
task.getResponseBodyMappings().convention(openApiSpec.getResponseBodyMappings());

task.getSchemaMapping().convention(openApiSpec.getSchemaMapping());
task.getImportMapping().convention(openApiSpec.getImportMapping());
task.getNameMapping().convention(openApiSpec.getNameMapping());
task.getTypeMapping().convention(openApiSpec.getTypeMapping());
task.getEnumNameMapping().convention(openApiSpec.getEnumNameMapping());
task.getModelNameMapping().convention(openApiSpec.getModelNameMapping());
task.getInlineSchemaNameMapping().convention(openApiSpec.getInlineSchemaNameMapping());
task.getInlineSchemaOption().convention(openApiSpec.getInlineSchemaOption());
task.getOpenapiNormalizer().convention(openApiSpec.getOpenapiNormalizer());
}

private void withJavaSourceSets(Consumer<? super SourceSetContainer> consumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -42,6 +43,8 @@ public interface OpenApiSpec {

Property<Boolean> getLombok();

Property<Boolean> getKsp();

Property<Boolean> getGeneratedAnnotation();

Property<Boolean> getFluxForArrays();
Expand All @@ -51,4 +54,22 @@ public interface OpenApiSpec {
ListProperty<ParameterMappingModel> getParameterMappings();

ListProperty<ResponseBodyMappingModel> getResponseBodyMappings();

MapProperty<String, String> getSchemaMapping();

MapProperty<String, String> getImportMapping();

MapProperty<String, String> getNameMapping();

MapProperty<String, String> getTypeMapping();

MapProperty<String, String> getEnumNameMapping();

MapProperty<String, String> getModelNameMapping();

MapProperty<String, String> getInlineSchemaNameMapping();

MapProperty<String, String> getInlineSchemaOption();

MapProperty<String, String> getOpenapiNormalizer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,6 +87,9 @@ public abstract class AbstractOpenApiGenerator<W extends AbstractOpenApiWorkActi
@Input
public abstract Property<Boolean> getLombok();

@Input
public abstract Property<Boolean> getKsp();

@Input
public abstract Property<Boolean> getGeneratedAnnotation();

Expand All @@ -95,6 +99,33 @@ public abstract class AbstractOpenApiGenerator<W extends AbstractOpenApiWorkActi
@Input
public abstract ListProperty<ResponseBodyMappingModel> getResponseBodyMappings();

@Input
public abstract MapProperty<String, String> getSchemaMapping();

@Input
public abstract MapProperty<String, String> getImportMapping();

@Input
public abstract MapProperty<String, String> getNameMapping();

@Input
public abstract MapProperty<String, String> getTypeMapping();

@Input
public abstract MapProperty<String, String> getEnumNameMapping();

@Input
public abstract MapProperty<String, String> getModelNameMapping();

@Input
public abstract MapProperty<String, String> getInlineSchemaNameMapping();

@Input
public abstract MapProperty<String, String> getInlineSchemaOption();

@Input
public abstract MapProperty<String, String> getOpenapiNormalizer();

@OutputDirectory
public abstract DirectoryProperty getOutputDirectory();

Expand Down Expand Up @@ -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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,13 +69,33 @@ interface OpenApiParameters extends WorkParameters {

Property<Boolean> getLombok();

Property<Boolean> getKsp();

Property<Boolean> getGeneratedAnnotation();

Property<Boolean> getFluxForArrays();

ListProperty<ParameterMappingModel> getParameterMappings();

ListProperty<ResponseBodyMappingModel> getResponseBodyMappings();

MapProperty<String, String> getSchemaMapping();

MapProperty<String, String> getImportMapping();

MapProperty<String, String> getNameMapping();

MapProperty<String, String> getTypeMapping();

MapProperty<String, String> getEnumNameMapping();

MapProperty<String, String> getModelNameMapping();

MapProperty<String, String> getInlineSchemaNameMapping();

MapProperty<String, String> getInlineSchemaOption();

MapProperty<String, String> getOpenapiNormalizer();
}

protected abstract void configureBuilder(MicronautCodeGeneratorBuilder builder);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class OpenApiClientGeneratorSpec extends AbstractOpenApiGeneratorSpec {
useReactive = true
generatedAnnotation = false
fluxForArrays = true
nameMapping = [test: "changedTest"]
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions openapi-plugin/src/test/resources/petstore.json
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,10 @@
},
"complete": {
"type": "boolean"
},
"test": {
"type": "string",
"description": "Test prop"
}
},
"xml": {
Expand Down

0 comments on commit 4f317cb

Please sign in to comment.