Skip to content

Commit a940d82

Browse files
authored
Convert client and server modules to use @ConfigMapping (#944)
1 parent b9d49cf commit a940d82

File tree

11 files changed

+138
-171
lines changed

11 files changed

+138
-171
lines changed

client/deployment/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,6 @@
169169
<version>${quarkus.version}</version>
170170
</path>
171171
</annotationProcessorPaths>
172-
<compilerArgs>
173-
<arg>-AlegacyConfigRoot=true</arg>
174-
</compilerArgs>
175172
</configuration>
176173
</execution>
177174
</executions>

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CodegenConfig.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,32 @@
77
import java.util.stream.Collectors;
88

99
import io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorOutputPaths;
10-
import io.quarkus.runtime.annotations.ConfigItem;
1110
import io.quarkus.runtime.annotations.ConfigPhase;
1211
import io.quarkus.runtime.annotations.ConfigRoot;
12+
import io.smallrye.config.ConfigMapping;
13+
import io.smallrye.config.WithName;
1314
import io.smallrye.config.common.utils.StringUtil;
1415

1516
// This configuration is read in codegen phase (before build time), the annotation is for document purposes and avoiding quarkus warns
16-
@ConfigRoot(name = CodegenConfig.CODEGEN_TIME_CONFIG_PREFIX, phase = ConfigPhase.BUILD_TIME)
17-
public class CodegenConfig extends GlobalCodegenConfig {
17+
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
18+
@ConfigMapping(prefix = "quarkus." + CodegenConfig.CODEGEN_TIME_CONFIG_PREFIX)
19+
public interface CodegenConfig extends GlobalCodegenConfig {
1820

19-
static final String CODEGEN_TIME_CONFIG_PREFIX = "openapi-generator.codegen";
21+
String CODEGEN_TIME_CONFIG_PREFIX = "openapi-generator.codegen";
2022

21-
public static final String API_PKG_SUFFIX = ".api";
22-
public static final String MODEL_PKG_SUFFIX = ".model";
23+
String API_PKG_SUFFIX = ".api";
24+
String MODEL_PKG_SUFFIX = ".model";
2325

24-
public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT = "UNEXPECTED";
25-
public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT = "unexpected";
26+
String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT = "UNEXPECTED";
27+
String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT = "unexpected";
2628
// package visibility for unit tests
27-
static final String BUILD_TIME_GLOBAL_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".%s";
28-
static final String BUILD_TIME_SPEC_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".spec.%s";
29+
String BUILD_TIME_GLOBAL_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".%s";
30+
String BUILD_TIME_SPEC_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".spec.%s";
2931

30-
public static final List<String> SUPPORTED_CONFIGURATIONS = Arrays.stream(ConfigName.values()).map(cn -> cn.name)
32+
List<String> SUPPORTED_CONFIGURATIONS = Arrays.stream(ConfigName.values()).map(cn -> cn.name)
3133
.collect(Collectors.toList());
3234

33-
public enum ConfigName {
35+
enum ConfigName {
3436
//global configs
3537
VERBOSE("verbose"),
3638
INPUT_BASE_DIR("input-base-dir"),
@@ -88,28 +90,28 @@ public enum ConfigName {
8890
/**
8991
* OpenAPI Spec details for codegen configuration.
9092
*/
91-
@ConfigItem(name = "spec")
92-
public Map<String, SpecItemConfig> specItem;
93+
@WithName("spec")
94+
Map<String, SpecItemConfig> specItem();
9395

94-
public static String resolveApiPackage(final String basePackage) {
96+
static String resolveApiPackage(final String basePackage) {
9597
return String.format("%s%s", basePackage, API_PKG_SUFFIX);
9698
}
9799

98-
public static String resolveModelPackage(final String basePackage) {
100+
static String resolveModelPackage(final String basePackage) {
99101
return String.format("%s%s", basePackage, MODEL_PKG_SUFFIX);
100102
}
101103

102104
/**
103105
* Return global config name, openapi-generator.codegen.config-name
104106
*/
105-
public static String getGlobalConfigName(ConfigName configName) {
107+
static String getGlobalConfigName(ConfigName configName) {
106108
return String.format(BUILD_TIME_GLOBAL_PREFIX_FORMAT, configName.name);
107109
}
108110

109111
/**
110112
* Return spec config name openapi-generator.codegen.spec.%s.config-name
111113
*/
112-
public static String getSpecConfigName(ConfigName configName, final Path openApiFilePath) {
114+
static String getSpecConfigName(ConfigName configName, final Path openApiFilePath) {
113115
return String.format("%s.%s", getBuildTimeSpecPropertyPrefix(openApiFilePath), configName.name);
114116
}
115117

@@ -119,7 +121,7 @@ public static String getSpecConfigName(ConfigName configName, final Path openApi
119121
* returned value is
120122
* <code>openapi.generator.codegen.spec.petstore.mutiny</code>.
121123
*/
122-
public static String getSpecConfigNameByConfigKey(final String configKey, final ConfigName configName) {
124+
static String getSpecConfigNameByConfigKey(final String configKey, final ConfigName configName) {
123125
String buildTimeSpecPropertyPrefix = String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, configKey);
124126
return String.format("%s.%s", buildTimeSpecPropertyPrefix, configName.name);
125127
}
@@ -130,11 +132,11 @@ public static String getSpecConfigNameByConfigKey(final String configKey, final
130132
* `quarkus.openapi-generator."petstore_json"`.
131133
* Every the periods (.) in the file name will be replaced by underscore (_).
132134
*/
133-
public static String getBuildTimeSpecPropertyPrefix(final Path openApiFilePath) {
135+
static String getBuildTimeSpecPropertyPrefix(final Path openApiFilePath) {
134136
return String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, getSanitizedFileName(openApiFilePath));
135137
}
136138

137-
public static String getSanitizedFileName(final Path openApiFilePath) {
139+
static String getSanitizedFileName(final Path openApiFilePath) {
138140
return StringUtil
139141
.replaceNonAlphanumericByUnderscores(OpenApiGeneratorOutputPaths.getRelativePath(openApiFilePath).toString());
140142
}

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/CommonItemConfig.java

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import java.util.Map;
44
import java.util.Optional;
55

6-
import io.quarkus.runtime.annotations.ConfigGroup;
7-
import io.quarkus.runtime.annotations.ConfigItem;
6+
import io.smallrye.config.WithName;
87

98
/*
109
* Model for the configuration of this extension.
@@ -13,92 +12,91 @@
1312
* Not meant to be used outside this scope.
1413
* Config items can be applied on spec and globally as well
1514
*/
16-
@ConfigGroup
17-
public class CommonItemConfig {
15+
public interface CommonItemConfig {
1816

1917
/**
2018
* Whether to skip the generation of models for form parameters
2119
*/
22-
@ConfigItem(name = "skip-form-model")
23-
public Optional<Boolean> skipFormModel;
20+
@WithName("skip-form-model")
21+
Optional<Boolean> skipFormModel();
2422

2523
/**
2624
* Type Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be used for a
2725
* given OAS datatype (the keys of this map)
2826
*/
29-
@ConfigItem(name = "type-mappings")
30-
public Map<String, String> typeMappings;
27+
@WithName("type-mappings")
28+
Map<String, String> typeMappings();
3129

3230
/**
3331
* Import Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be
3432
* imported when a given OAS datatype (the keys of this map) is used
3533
*/
36-
@ConfigItem(name = "import-mappings")
37-
public Map<String, String> importMappings;
34+
@WithName("import-mappings")
35+
Map<String, String> importMappings();
3836

3937
/**
4038
* Schema Mapping is an OpenAPI Generator configuration specifying which Java types (the values) should be
4139
* imported when a given schema type (the keys of this map) is used
4240
*/
43-
@ConfigItem(name = "schema-mappings")
44-
public Map<String, String> schemaMappings;
41+
@WithName("schema-mappings")
42+
Map<String, String> schemaMappings();
4543

4644
/**
4745
* The specified annotations will be added to the generated model files
4846
*/
49-
@ConfigItem(name = "additional-model-type-annotations")
50-
public Optional<String> additionalModelTypeAnnotations;
47+
@WithName("additional-model-type-annotations")
48+
Optional<String> additionalModelTypeAnnotations();
5149

5250
/**
5351
* Defines if the enums should have an `UNEXPECTED` member to convey values that cannot be parsed. Default is
5452
* {@code false}.
5553
*/
56-
@ConfigItem(name = "additional-enum-type-unexpected-member")
57-
public Optional<Boolean> additionalEnumTypeUnexpectedMemberAnnotations;
54+
@WithName("additional-enum-type-unexpected-member")
55+
Optional<Boolean> additionalEnumTypeUnexpectedMemberAnnotations();
5856

5957
/**
6058
* The specified annotations will be added to the generated api files
6159
*/
62-
@ConfigItem(name = "additional-api-type-annotations")
63-
public Optional<String> additionalApiTypeAnnotations;
60+
@WithName("additional-api-type-annotations")
61+
Optional<String> additionalApiTypeAnnotations();
6462

6563
/**
6664
* Add custom/additional HTTP Headers or other args to every request
6765
*/
68-
@ConfigItem(name = "additional-request-args")
69-
public Optional<String> additionalRequestArgs;
66+
@WithName("additional-request-args")
67+
Optional<String> additionalRequestArgs();
7068

7169
/**
7270
* Defines if the methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is {@code false}.
7371
*/
74-
@ConfigItem(name = "return-response")
75-
public Optional<Boolean> returnResponse;
72+
@WithName("return-response")
73+
Optional<Boolean> returnResponse();
7674

7775
/**
7876
* Defines if security support classes should be generated
7977
*/
80-
@ConfigItem(name = "enable-security-generation")
81-
public Optional<String> enableSecurityGeneration;
78+
@WithName("enable-security-generation")
79+
Optional<String> enableSecurityGeneration();
8280

8381
/**
8482
* Defines the normalizer options.
8583
*/
86-
@ConfigItem(name = "open-api-normalizer")
87-
public Map<String, String> normalizer;
84+
@WithName("open-api-normalizer")
85+
Map<String, String> normalizer();
8886

8987
/**
9088
* Enable SmallRye Mutiny support. If you set this to {@code true}, all return types will be wrapped in
9189
* {@link io.smallrye.mutiny.Uni}.
9290
*/
93-
@ConfigItem(name = "mutiny")
94-
public Optional<Boolean> supportMutiny;
91+
@WithName("mutiny")
92+
Optional<Boolean> supportMutiny();
9593

9694
/**
9795
* Defines with SmallRye Mutiny enabled if methods should return {@link jakarta.ws.rs.core.Response} or a model. Default is
9896
* {@code false}.
9997
*/
100-
@ConfigItem(name = "mutiny.return-response")
101-
public Optional<Boolean> mutinyReturnResponse;
98+
@WithName("mutiny.return-response")
99+
Optional<Boolean> mutinyReturnResponse();
102100

103101
/**
104102
* Handles the return type for each operation, depending on the configuration.
@@ -125,16 +123,16 @@ public class CommonItemConfig {
125123
* - If the operation has a void return type, it will return {@link io.smallrye.mutiny.Uni<jakarta.ws.rs.core.Response>}.
126124
* - Otherwise, it will return {@link io.smallrye.mutiny.Uni<returnType>}`.
127125
*/
128-
@ConfigItem(name = "mutiny.operation-ids")
129-
public Optional<Map<String, String>> mutinyMultiOperationIds;
126+
@WithName("mutiny.operation-ids")
127+
Map<String, String> mutinyMultiOperationIds();
130128

131129
/**
132130
* Defines, whether the `PartFilename` ({@link org.jboss.resteasy.reactive.PartFilename} or
133131
* {@link org.jboss.resteasy.annotations.providers.multipart.PartFilename}) annotation should be generated for
134132
* MultipartForm POJOs. By setting to {@code false}, the annotation will not be generated.
135133
*/
136-
@ConfigItem(name = "generate-part-filename")
137-
public Optional<Boolean> generatePartFilename;
134+
@WithName("generate-part-filename")
135+
Optional<Boolean> generatePartFilename();
138136

139137
/**
140138
* Defines the filename for a part in case the `PartFilename` annotation
@@ -143,40 +141,40 @@ public class CommonItemConfig {
143141
* In case no value is set, the default one is `&lt;fieldName&gt;File` or `file`, depending on the
144142
* {@link CommonItemConfig#useFieldNameInPartFilename} configuration.
145143
*/
146-
@ConfigItem(name = "part-filename-value")
147-
public Optional<String> partFilenameValue;
144+
@WithName("part-filename-value")
145+
Optional<String> partFilenameValue();
148146

149147
/**
150148
* Defines, whether the filename should also include the property name in case the `PartFilename` annotation
151149
* ({@link org.jboss.resteasy.reactive.PartFilename} or
152150
* {@link org.jboss.resteasy.annotations.providers.multipart.PartFilename}) is generated.
153151
*/
154-
@ConfigItem(name = "use-field-name-in-part-filename")
155-
public Optional<Boolean> useFieldNameInPartFilename;
152+
@WithName("use-field-name-in-part-filename")
153+
Optional<Boolean> useFieldNameInPartFilename();
156154

157155
/**
158156
* Enable bean validation. If you set this to {@code true}, validation annotations are added to generated sources E.g.
159157
* {@code @Size}.
160158
*/
161-
@ConfigItem(name = "use-bean-validation")
162-
public Optional<Boolean> useBeanValidation;
159+
@WithName("use-bean-validation")
160+
Optional<Boolean> useBeanValidation();
163161

164162
/**
165163
* Enable the generation of APIs. If you set this to {@code false}, APIs will not be generated.
166164
*/
167-
@ConfigItem(name = "generate-apis")
168-
public Optional<Boolean> generateApis;
165+
@WithName("generate-apis")
166+
Optional<Boolean> generateApis();
169167

170168
/**
171169
* Enable the generation of models. If you set this to {@code false}, models will not be generated.
172170
*/
173-
@ConfigItem(name = "generate-models")
174-
public Optional<Boolean> generateModels;
171+
@WithName("generate-models")
172+
Optional<Boolean> generateModels();
175173

176174
/**
177175
* Enable the generation of equals and hashcode in models. If you set this to {@code false}, the models
178176
* will not have equals and hashcode.
179177
*/
180-
@ConfigItem(name = "equals-hashcode")
181-
public Optional<Boolean> equalsHashcode;
178+
@WithName("equals-hashcode")
179+
Optional<Boolean> equalsHashcode();
182180
}

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GlobalCodegenConfig.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.util.Optional;
44

5-
import io.quarkus.runtime.annotations.ConfigGroup;
6-
import io.quarkus.runtime.annotations.ConfigItem;
5+
import io.smallrye.config.WithDefault;
6+
import io.smallrye.config.WithName;
77

88
/*
99
* Model for the configuration of this extension.
@@ -12,50 +12,51 @@
1212
* Not meant to be used outside this scope.
1313
* Config items can be applied only globally
1414
*/
15-
@ConfigGroup
16-
public class GlobalCodegenConfig extends CommonItemConfig {
15+
public interface GlobalCodegenConfig extends CommonItemConfig {
1716

1817
/**
1918
* Whether to log the internal generator codegen process in the default output or not.
2019
*/
21-
@ConfigItem(name = "verbose", defaultValue = "false")
22-
public boolean verbose;
20+
@WithDefault("false")
21+
@WithName("verbose")
22+
boolean verbose();
2323

2424
/**
2525
* Option to change the directory where OpenAPI files must be found.
2626
*/
27-
@ConfigItem(name = "input-base-dir")
28-
public Optional<String> inputBaseDir;
27+
@WithName("input-base-dir")
28+
Optional<String> inputBaseDir();
2929

3030
/**
3131
* Option to change the directory where template files must be found.
3232
*/
33-
@ConfigItem(name = "template-base-dir")
34-
public Optional<String> templateBaseDir;
33+
@WithName("template-base-dir")
34+
Optional<String> templateBaseDir();
3535

3636
/**
3737
* Whether or not to skip validating the input spec prior to generation. By default, invalid specifications will result in
3838
* an error.
3939
*/
40-
@ConfigItem(name = "validateSpec", defaultValue = "true")
41-
public boolean validateSpec;
40+
@WithName("validateSpec")
41+
@WithDefault("true")
42+
boolean validateSpec();
4243

4344
/**
4445
* Option to specify files for which generation should be executed only
4546
*/
46-
@ConfigItem(name = "include")
47-
public Optional<String> include;
47+
@WithName("include")
48+
Optional<String> include();
4849

4950
/**
5051
* Option to exclude file from generation
5152
*/
52-
@ConfigItem(name = "exclude")
53-
public Optional<String> exclude;
53+
@WithName("exclude")
54+
Optional<String> exclude();
5455

5556
/**
5657
* Create security for the referenced security scheme
5758
*/
58-
@ConfigItem(name = "default-security-scheme")
59-
public Optional<String> defaultSecuritySchema;
59+
@WithName("default-security-scheme")
60+
Optional<String> defaultSecuritySchema();
6061

6162
}

0 commit comments

Comments
 (0)