Skip to content

Commit

Permalink
Micronaut openapi 6.13.1
Browse files Browse the repository at this point in the history
  • Loading branch information
altro3 committed Oct 19, 2024
1 parent 50c0186 commit 5f11566
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 8 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand Down Expand Up @@ -190,9 +210,26 @@ private void configureCommonProperties(String name, AbstractOpenApiGenerator<?,
task.getModelNamePrefix().convention(openApiSpec.getModelNamePrefix());
task.getModelNameSuffix().convention(openApiSpec.getModelNameSuffix());

task.getUseEnumCaseInsensitive().convention(openApiSpec.getUseEnumCaseInsensitive());
task.getGenerateSwaggerAnnotations().convention(openApiSpec.getGenerateSwaggerAnnotations());
task.getImplicitHeaders().convention(openApiSpec.getImplicitHeaders());
task.getImplicitHeadersRegex().convention(openApiSpec.getImplicitHeadersRegex());

task.getAdditionalEnumTypeAnnotations().convention(openApiSpec.getAdditionalEnumTypeAnnotations());
task.getAdditionalModelTypeAnnotations().convention(openApiSpec.getAdditionalModelTypeAnnotations());
task.getAdditionalOneOfTypeAnnotations().convention(openApiSpec.getAdditionalOneOfTypeAnnotations());
task.getAdditionalProperties().convention(openApiSpec.getAdditionalProperties());

task.getUseJakartaEe().convention(openApiSpec.getUseJakartaEe());
task.getSortParamsByRequiredFlag().convention(openApiSpec.getSortParamsByRequiredFlag());
task.getSkipOperationExample().convention(openApiSpec.getSkipOperationExample());
task.getSkipSortingOperations().convention(openApiSpec.getSkipSortingOperations());
task.getRemoveOperationIdPrefixDelimiter().convention(openApiSpec.getRemoveOperationIdPrefixDelimiter());
task.getRemoveOperationIdPrefixCount().convention(openApiSpec.getRemoveOperationIdPrefixCount());
task.getSortModelPropertiesByRequiredFlag().convention(openApiSpec.getSortModelPropertiesByRequiredFlag());
task.getEnsureUniqueParams().convention(openApiSpec.getEnsureUniqueParams());
task.getAllowUnicodeIdentifiers().convention(openApiSpec.getAllowUnicodeIdentifiers());
task.getPrependFormOrBodyParameters().convention(openApiSpec.getPrependFormOrBodyParameters());
}

private void withJavaSourceSets(Consumer<? super SourceSetContainer> consumer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -83,9 +85,39 @@ public interface OpenApiSpec {

Property<String> getModelNameSuffix();

Property<Boolean> getUseEnumCaseInsensitive();

Property<Boolean> getGenerateSwaggerAnnotations();

Property<Boolean> getImplicitHeaders();

Property<String> getImplicitHeadersRegex();

ListProperty<String> getAdditionalEnumTypeAnnotations();

ListProperty<String> getAdditionalModelTypeAnnotations();

ListProperty<String> getAdditionalOneOfTypeAnnotations();

MapProperty<String, Object> getAdditionalProperties();

Property<Boolean> getUseJakartaEe();

Property<Boolean> getSortParamsByRequiredFlag();

Property<Boolean> getSkipOperationExample();

Property<Boolean> getSkipSortingOperations();

Property<String> getRemoveOperationIdPrefixDelimiter();

Property<Integer> getRemoveOperationIdPrefixCount();

Property<Boolean> getSortModelPropertiesByRequiredFlag();

Property<Boolean> getEnsureUniqueParams();

Property<Boolean> getAllowUnicodeIdentifiers();

Property<Boolean> getPrependFormOrBodyParameters();
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public abstract class AbstractOpenApiGenerator<W extends AbstractOpenApiWorkActi
@Input
public abstract Property<String> getModelNameSuffix();

@Optional
@Input
public abstract Property<Boolean> getUseEnumCaseInsensitive();

@Optional
@Input
public abstract Property<Boolean> getGenerateSwaggerAnnotations();
Expand All @@ -158,6 +162,62 @@ public abstract class AbstractOpenApiGenerator<W extends AbstractOpenApiWorkActi
@Input
public abstract Property<String> getImplicitHeadersRegex();

@Optional
@Input
public abstract ListProperty<String> getAdditionalEnumTypeAnnotations();

@Optional
@Input
public abstract ListProperty<String> getAdditionalModelTypeAnnotations();

@Optional
@Input
public abstract ListProperty<String> getAdditionalOneOfTypeAnnotations();

@Optional
@Input
public abstract MapProperty<String, Object> getAdditionalProperties();

@Optional
@Input
public abstract Property<Boolean> getUseJakartaEe();

@Optional
@Input
public abstract Property<Boolean> getSortParamsByRequiredFlag();

@Optional
@Input
public abstract Property<Boolean> getSkipOperationExample();

@Optional
@Input
public abstract Property<Boolean> getSkipSortingOperations();

@Optional
@Input
public abstract Property<String> getRemoveOperationIdPrefixDelimiter();

@Optional
@Input
public abstract Property<Integer> getRemoveOperationIdPrefixCount();

@Optional
@Input
public abstract Property<Boolean> getSortModelPropertiesByRequiredFlag();

@Optional
@Input
public abstract Property<Boolean> getEnsureUniqueParams();

@Optional
@Input
public abstract Property<Boolean> getAllowUnicodeIdentifiers();

@Optional
@Input
public abstract Property<Boolean> getPrependFormOrBodyParameters();

@OutputDirectory
public abstract DirectoryProperty getOutputDirectory();

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

Property<String> getModelNameSuffix();

Property<Boolean> getUseEnumCaseInsensitive();

Property<Boolean> getGenerateSwaggerAnnotations();

Property<Boolean> getImplicitHeaders();

Property<String> getImplicitHeadersRegex();

ListProperty<String> getAdditionalEnumTypeAnnotations();

ListProperty<String> getAdditionalModelTypeAnnotations();

ListProperty<String> getAdditionalOneOfTypeAnnotations();

MapProperty<String, Object> getAdditionalProperties();

Property<Boolean> getUseJakartaEe();

Property<Boolean> getSortParamsByRequiredFlag();

Property<Boolean> getSkipOperationExample();

Property<Boolean> getSkipSortingOperations();

Property<String> getRemoveOperationIdPrefixDelimiter();

Property<Integer> getRemoveOperationIdPrefixCount();

Property<Boolean> getSortModelPropertiesByRequiredFlag();

Property<Boolean> getEnsureUniqueParams();

Property<Boolean> getAllowUnicodeIdentifiers();

Property<Boolean> getPrependFormOrBodyParameters();
}

protected abstract void configureBuilder(MicronautCodeGeneratorBuilder builder);
Expand All @@ -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())
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class OpenApiClientGeneratorSpec extends AbstractOpenApiGeneratorSpec {
clientId = "my-client"
generateSwaggerAnnotations = true
implicitHeadersRegex = ".*"
useEnumCaseInsensitive = true
}
}
}
Expand Down

0 comments on commit 5f11566

Please sign in to comment.