From a940d8239770ce3272200c2d4edca62e0f1dab92 Mon Sep 17 00:00:00 2001
From: Matheus Cruz <56329339+mcruzdev@users.noreply.github.com>
Date: Wed, 22 Jan 2025 09:40:02 -0300
Subject: [PATCH] Convert client and server modules to use @ConfigMapping
(#944)
---
client/deployment/pom.xml | 3 -
.../generator/deployment/CodegenConfig.java | 44 ++++-----
.../deployment/CommonItemConfig.java | 90 +++++++++----------
.../deployment/GlobalCodegenConfig.java | 37 ++++----
.../generator/deployment/SpecItemConfig.java | 35 ++++----
client/runtime/pom.xml | 3 -
.../openapi/generator/AuthsConfig.java | 21 ++---
.../generator/OpenApiGeneratorConfig.java | 27 +++---
.../openapi/generator/SpecItemConfig.java | 22 ++---
server/deployment/pom.xml | 3 -
.../generator/deployment/CodegenConfig.java | 24 ++---
11 files changed, 138 insertions(+), 171 deletions(-)
diff --git a/client/deployment/pom.xml b/client/deployment/pom.xml
index 68c372563..5fb3f85ca 100644
--- a/client/deployment/pom.xml
+++ b/client/deployment/pom.xml
@@ -169,9 +169,6 @@
${quarkus.version}
-
- -AlegacyConfigRoot=true
-
diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java
index 02192c6a6..883a6cf95 100644
--- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java
+++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java
@@ -7,30 +7,32 @@
import java.util.stream.Collectors;
import io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorOutputPaths;
-import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
+import io.smallrye.config.ConfigMapping;
+import io.smallrye.config.WithName;
import io.smallrye.config.common.utils.StringUtil;
// This configuration is read in codegen phase (before build time), the annotation is for document purposes and avoiding quarkus warns
-@ConfigRoot(name = CodegenConfig.CODEGEN_TIME_CONFIG_PREFIX, phase = ConfigPhase.BUILD_TIME)
-public class CodegenConfig extends GlobalCodegenConfig {
+@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
+@ConfigMapping(prefix = "quarkus." + CodegenConfig.CODEGEN_TIME_CONFIG_PREFIX)
+public interface CodegenConfig extends GlobalCodegenConfig {
- static final String CODEGEN_TIME_CONFIG_PREFIX = "openapi-generator.codegen";
+ String CODEGEN_TIME_CONFIG_PREFIX = "openapi-generator.codegen";
- public static final String API_PKG_SUFFIX = ".api";
- public static final String MODEL_PKG_SUFFIX = ".model";
+ String API_PKG_SUFFIX = ".api";
+ String MODEL_PKG_SUFFIX = ".model";
- public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT = "UNEXPECTED";
- public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT = "unexpected";
+ String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT = "UNEXPECTED";
+ String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT = "unexpected";
// package visibility for unit tests
- static final String BUILD_TIME_GLOBAL_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".%s";
- static final String BUILD_TIME_SPEC_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".spec.%s";
+ String BUILD_TIME_GLOBAL_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".%s";
+ String BUILD_TIME_SPEC_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".spec.%s";
- public static final List SUPPORTED_CONFIGURATIONS = Arrays.stream(ConfigName.values()).map(cn -> cn.name)
+ List SUPPORTED_CONFIGURATIONS = Arrays.stream(ConfigName.values()).map(cn -> cn.name)
.collect(Collectors.toList());
- public enum ConfigName {
+ enum ConfigName {
//global configs
VERBOSE("verbose"),
INPUT_BASE_DIR("input-base-dir"),
@@ -88,28 +90,28 @@ public enum ConfigName {
/**
* OpenAPI Spec details for codegen configuration.
*/
- @ConfigItem(name = "spec")
- public Map specItem;
+ @WithName("spec")
+ Map specItem();
- public static String resolveApiPackage(final String basePackage) {
+ static String resolveApiPackage(final String basePackage) {
return String.format("%s%s", basePackage, API_PKG_SUFFIX);
}
- public static String resolveModelPackage(final String basePackage) {
+ static String resolveModelPackage(final String basePackage) {
return String.format("%s%s", basePackage, MODEL_PKG_SUFFIX);
}
/**
* Return global config name, openapi-generator.codegen.config-name
*/
- public static String getGlobalConfigName(ConfigName configName) {
+ static String getGlobalConfigName(ConfigName configName) {
return String.format(BUILD_TIME_GLOBAL_PREFIX_FORMAT, configName.name);
}
/**
* Return spec config name openapi-generator.codegen.spec.%s.config-name
*/
- public static String getSpecConfigName(ConfigName configName, final Path openApiFilePath) {
+ static String getSpecConfigName(ConfigName configName, final Path openApiFilePath) {
return String.format("%s.%s", getBuildTimeSpecPropertyPrefix(openApiFilePath), configName.name);
}
@@ -119,7 +121,7 @@ public static String getSpecConfigName(ConfigName configName, final Path openApi
* returned value is
* openapi.generator.codegen.spec.petstore.mutiny
.
*/
- public static String getSpecConfigNameByConfigKey(final String configKey, final ConfigName configName) {
+ static String getSpecConfigNameByConfigKey(final String configKey, final ConfigName configName) {
String buildTimeSpecPropertyPrefix = String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, configKey);
return String.format("%s.%s", buildTimeSpecPropertyPrefix, configName.name);
}
@@ -130,11 +132,11 @@ public static String getSpecConfigNameByConfigKey(final String configKey, final
* `quarkus.openapi-generator."petstore_json"`.
* Every the periods (.) in the file name will be replaced by underscore (_).
*/
- public static String getBuildTimeSpecPropertyPrefix(final Path openApiFilePath) {
+ static String getBuildTimeSpecPropertyPrefix(final Path openApiFilePath) {
return String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, getSanitizedFileName(openApiFilePath));
}
- public static String getSanitizedFileName(final Path openApiFilePath) {
+ static String getSanitizedFileName(final Path openApiFilePath) {
return StringUtil
.replaceNonAlphanumericByUnderscores(OpenApiGeneratorOutputPaths.getRelativePath(openApiFilePath).toString());
}
diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java
index 6d65cf4b8..487403b55 100644
--- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java
+++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java
@@ -3,8 +3,7 @@
import java.util.Map;
import java.util.Optional;
-import io.quarkus.runtime.annotations.ConfigGroup;
-import io.quarkus.runtime.annotations.ConfigItem;
+import io.smallrye.config.WithName;
/*
* Model for the configuration of this extension.
@@ -13,92 +12,91 @@
* Not meant to be used outside this scope.
* Config items can be applied on spec and globally as well
*/
-@ConfigGroup
-public class CommonItemConfig {
+public interface CommonItemConfig {
/**
* Whether to skip the generation of models for form parameters
*/
- @ConfigItem(name = "skip-form-model")
- public Optional skipFormModel;
+ @WithName("skip-form-model")
+ Optional skipFormModel();
/**
* Type Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be used for a
* given OAS datatype (the keys of this map)
*/
- @ConfigItem(name = "type-mappings")
- public Map typeMappings;
+ @WithName("type-mappings")
+ Map typeMappings();
/**
* Import Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be
* imported when a given OAS datatype (the keys of this map) is used
*/
- @ConfigItem(name = "import-mappings")
- public Map importMappings;
+ @WithName("import-mappings")
+ Map importMappings();
/**
* Schema Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be
* imported when a given schema type (the keys of this map) is used
*/
- @ConfigItem(name = "schema-mappings")
- public Map schemaMappings;
+ @WithName("schema-mappings")
+ Map schemaMappings();
/**
* The specified annotations will be added to the generated model files
*/
- @ConfigItem(name = "additional-model-type-annotations")
- public Optional additionalModelTypeAnnotations;
+ @WithName("additional-model-type-annotations")
+ Optional additionalModelTypeAnnotations();
/**
* Defines if the enums should have an `UNEXPECTED` member to convey values that cannot be parsed. Default is
* {@code false}.
*/
- @ConfigItem(name = "additional-enum-type-unexpected-member")
- public Optional additionalEnumTypeUnexpectedMemberAnnotations;
+ @WithName("additional-enum-type-unexpected-member")
+ Optional additionalEnumTypeUnexpectedMemberAnnotations();
/**
* The specified annotations will be added to the generated api files
*/
- @ConfigItem(name = "additional-api-type-annotations")
- public Optional additionalApiTypeAnnotations;
+ @WithName("additional-api-type-annotations")
+ Optional additionalApiTypeAnnotations();
/**
* Add custom/additional HTTP Headers or other args to every request
*/
- @ConfigItem(name = "additional-request-args")
- public Optional additionalRequestArgs;
+ @WithName("additional-request-args")
+ Optional additionalRequestArgs();
/**
* Defines if the methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is {@code false}.
*/
- @ConfigItem(name = "return-response")
- public Optional returnResponse;
+ @WithName("return-response")
+ Optional returnResponse();
/**
* Defines if security support classes should be generated
*/
- @ConfigItem(name = "enable-security-generation")
- public Optional enableSecurityGeneration;
+ @WithName("enable-security-generation")
+ Optional enableSecurityGeneration();
/**
* Defines the normalizer options.
*/
- @ConfigItem(name = "open-api-normalizer")
- public Map normalizer;
+ @WithName("open-api-normalizer")
+ Map normalizer();
/**
* Enable SmallRye Mutiny support. If you set this to {@code true}, all return types will be wrapped in
* {@link io.smallrye.mutiny.Uni}.
*/
- @ConfigItem(name = "mutiny")
- public Optional supportMutiny;
+ @WithName("mutiny")
+ Optional supportMutiny();
/**
* Defines with SmallRye Mutiny enabled if methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is
* {@code false}.
*/
- @ConfigItem(name = "mutiny.return-response")
- public Optional mutinyReturnResponse;
+ @WithName("mutiny.return-response")
+ Optional mutinyReturnResponse();
/**
* Handles the return type for each operation, depending on the configuration.
@@ -125,16 +123,16 @@ public class CommonItemConfig {
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni}.
* - Otherwise, it will return {@link io.smallrye.mutiny.Uni}`.
*/
- @ConfigItem(name = "mutiny.operation-ids")
- public Optional