Skip to content

Commit ca455c6

Browse files
committed
Use @ConfigMapping annotation instead legacy @configroot on the client
1 parent 3baafe8 commit ca455c6

29 files changed

+481
-429
lines changed

client/deployment/pom.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,6 @@
150150
<version>${quarkus.version}</version>
151151
</path>
152152
</annotationProcessorPaths>
153-
<compilerArgs>
154-
<arg>-AlegacyConfigRoot=true</arg>
155-
</compilerArgs>
156153
</configuration>
157154
</execution>
158155
</executions>
Lines changed: 12 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,26 @@
11
package io.quarkiverse.openapi.generator.deployment;
22

3-
import java.nio.file.Path;
4-
import java.util.Arrays;
5-
import java.util.List;
63
import java.util.Map;
7-
import java.util.stream.Collectors;
84

9-
import io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorOutputPaths;
10-
import io.quarkus.runtime.annotations.ConfigItem;
115
import io.quarkus.runtime.annotations.ConfigPhase;
126
import io.quarkus.runtime.annotations.ConfigRoot;
13-
import io.smallrye.config.common.utils.StringUtil;
7+
import io.smallrye.config.ConfigMapping;
8+
import io.smallrye.config.WithName;
149

1510
// 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 {
18-
19-
static final String CODEGEN_TIME_CONFIG_PREFIX = "openapi-generator.codegen";
20-
21-
public static final String API_PKG_SUFFIX = ".api";
22-
public static final String MODEL_PKG_SUFFIX = ".model";
23-
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-
// 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-
30-
public static final List<String> SUPPORTED_CONFIGURATIONS = Arrays.stream(ConfigName.values()).map(cn -> cn.name)
31-
.collect(Collectors.toList());
32-
33-
public enum ConfigName {
34-
//global configs
35-
VERBOSE("verbose"),
36-
INPUT_BASE_DIR("input-base-dir"),
37-
INCLUDE("include"),
38-
EXCLUDE("exclude"),
39-
VALIDATE_SPEC("validateSpec"),
40-
DEFAULT_SECURITY_SCHEME("default-security-scheme"),
41-
42-
//spec configs only
43-
BASE_PACKAGE("base-package"),
44-
API_NAME_SUFFIX("api-name-suffix"),
45-
MODEL_NAME_SUFFIX("model-name-suffix"),
46-
MODEL_NAME_PREFIX("model-name-prefix"),
47-
48-
//global & spec configs
49-
SKIP_FORM_MODEL("skip-form-model"),
50-
MUTINY("mutiny"),
51-
MUTINY_RETURN_RESPONSE("mutiny.return-response"),
52-
MUTINY_OPERATION_IDS("mutiny.operation-ids"),
53-
ADDITIONAL_MODEL_TYPE_ANNOTATIONS("additional-model-type-annotations"),
54-
ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER("additional-enum-type-unexpected-member"),
55-
ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME("additional-enum-type-unexpected-member-name"),
56-
ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE("additional-enum-type-unexpected-member-string-value"),
57-
ADDITIONAL_API_TYPE_ANNOTATIONS("additional-api-type-annotations"),
58-
TYPE_MAPPINGS("type-mappings"),
59-
IMPORT_MAPPINGS("import-mappings"),
60-
NORMALIZER("open-api-normalizer"),
61-
RETURN_RESPONSE("return-response"),
62-
ENABLE_SECURITY_GENERATION("enable-security-generation"),
63-
CONFIG_KEY("config-key"),
64-
GENERATE_PART_FILENAME("generate-part-filename"),
65-
PART_FILENAME_VALUE("part-filename-value"),
66-
USE_FIELD_NAME_IN_PART_FILENAME("use-field-name-in-part-filename"),
67-
ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"),
68-
ADDITIONAL_REQUEST_ARGS("additional-request-args"),
69-
BEAN_VALIDATION("use-bean-validation");
70-
71-
private final String name;
72-
73-
ConfigName(String name) {
74-
this.name = name;
75-
}
76-
77-
}
78-
11+
@ConfigMapping(prefix = "openapi-generator.codegen")
12+
@ConfigRoot(phase = ConfigPhase.BUILD_TIME)
13+
public interface CodegenConfig {
7914
/**
80-
* OpenAPI Spec details for codegen configuration.
15+
* Common item test.
8116
*/
82-
@ConfigItem(name = "spec")
83-
public Map<String, SpecItemConfig> specItem;
84-
85-
public static String resolveApiPackage(final String basePackage) {
86-
return String.format("%s%s", basePackage, API_PKG_SUFFIX);
87-
}
88-
89-
public static String resolveModelPackage(final String basePackage) {
90-
return String.format("%s%s", basePackage, MODEL_PKG_SUFFIX);
91-
}
92-
93-
/**
94-
* Return global config name, openapi-generator.codegen.config-name
95-
*/
96-
public static String getGlobalConfigName(ConfigName configName) {
97-
return String.format(BUILD_TIME_GLOBAL_PREFIX_FORMAT, configName.name);
98-
}
99-
100-
/**
101-
* Return spec config name openapi-generator.codegen.spec.%s.config-name
102-
*/
103-
public static String getSpecConfigName(ConfigName configName, final Path openApiFilePath) {
104-
return String.format("%s.%s", getBuildTimeSpecPropertyPrefix(openApiFilePath), configName.name);
105-
}
106-
107-
/**
108-
* Return spec config name by config-key (<b>openapi-generator.codegen.spec.%s.config-key</b>) property.
109-
* For example, given a configuration <code>quarkus.openapi.generator.codegen.spec.spec_yaml.config-key=petstore</code>, the
110-
* returned value is
111-
* <code>openapi.generator.codegen.spec.petstore.mutiny</code>.
112-
*/
113-
public static String getSpecConfigNameByConfigKey(final String configKey, final ConfigName configName) {
114-
String buildTimeSpecPropertyPrefix = String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, configKey);
115-
return String.format("%s.%s", buildTimeSpecPropertyPrefix, configName.name);
116-
}
17+
@WithName("common-item-config")
18+
CommonItemConfig commonItemConfig();
11719

11820
/**
119-
* Gets the config prefix for a given OpenAPI file in the path.
120-
* For example, given a path like /home/luke/projects/petstore.json, the returned value is
121-
* `quarkus.openapi-generator."petstore_json"`.
122-
* Every the periods (.) in the file name will be replaced by underscore (_).
21+
* OpenAPI Spec details for codegen configuration.
12322
*/
124-
public static String getBuildTimeSpecPropertyPrefix(final Path openApiFilePath) {
125-
return String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, getSanitizedFileName(openApiFilePath));
126-
}
127-
128-
public static String getSanitizedFileName(final Path openApiFilePath) {
129-
return StringUtil
130-
.replaceNonAlphanumericByUnderscores(OpenApiGeneratorOutputPaths.getRelativePath(openApiFilePath).toString());
131-
}
23+
@WithName("spec")
24+
Map<String, SpecItemConfig> specItem();
25+
//
13226
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.quarkiverse.openapi.generator.deployment;
2+
3+
import java.nio.file.Path;
4+
import java.util.Arrays;
5+
import java.util.List;
6+
import java.util.stream.Collectors;
7+
8+
import io.quarkiverse.openapi.generator.deployment.codegen.OpenApiGeneratorOutputPaths;
9+
import io.smallrye.config.common.utils.StringUtil;
10+
11+
public class CodegenConfigMethods {
12+
static final String CODEGEN_TIME_CONFIG_PREFIX = "openapi-generator.codegen";
13+
14+
public static final String API_PKG_SUFFIX = ".api";
15+
public static final String MODEL_PKG_SUFFIX = ".model";
16+
17+
public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME_DEFAULT = "UNEXPECTED";
18+
public static final String ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE_DEFAULT = "unexpected";
19+
// package visibility for unit tests
20+
static final String BUILD_TIME_GLOBAL_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".%s";
21+
static final String BUILD_TIME_SPEC_PREFIX_FORMAT = "quarkus." + CODEGEN_TIME_CONFIG_PREFIX + ".spec.%s";
22+
23+
public static final List<String> SUPPORTED_CONFIGURATIONS = Arrays.stream(CodegenConfigName.values()).map(cn -> cn.name)
24+
.collect(Collectors.toList());
25+
26+
/**
27+
* Return spec config name openapi-generator.codegen.spec.%s.config-name
28+
*/
29+
public static String getSpecConfigName(CodegenConfigName configName, final Path openApiFilePath) {
30+
return String.format("%s.%s", getBuildTimeSpecPropertyPrefix(openApiFilePath), configName.name);
31+
}
32+
33+
/**
34+
* Return spec con fig name by config-key (<b>openapi-generator.codegen.spec.%s.config-key</b>) property.
35+
* For example, given a configuration <code>quarkus.openapi.generator.codegen.spec.spec_yaml.config-key=petstore</code>, the
36+
* returned value is
37+
* <code>openapi.generator.codegen.spec.petstore.mutiny</code>.
38+
*/
39+
public static String getSpecConfigNameByConfigKey(final String configKey, final CodegenConfigName configName) {
40+
String buildTimeSpecPropertyPrefix = String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, configKey);
41+
return String.format("%s.%s", buildTimeSpecPropertyPrefix, configName.name);
42+
}
43+
44+
/**
45+
* Gets the config prefix for a given OpenAPI file in the path.
46+
* For example, given a path like /home/luke/projects/petstore.json, the returned value is
47+
* `quarkus.openapi-generator."petstore_json"`.
48+
* Every the periods (.) in the file name will be replaced by underscore (_).
49+
*/
50+
51+
public static String resolveApiPackage(final String basePackage) {
52+
return String.format("%s%s", basePackage, API_PKG_SUFFIX);
53+
}
54+
55+
public static String resolveModelPackage(final String basePackage) {
56+
return String.format("%s%s", basePackage, MODEL_PKG_SUFFIX);
57+
}
58+
59+
/**
60+
* Return global config name, openapi-generator.codegen.config-name
61+
*/
62+
public static String getGlobalConfigName(CodegenConfigName configName) {
63+
return String.format(BUILD_TIME_GLOBAL_PREFIX_FORMAT, configName.name);
64+
}
65+
66+
/**
67+
* Gets the config prefix for a given OpenAPI file in the path.
68+
* For example, given a path like /home/luke/projects/petstore.json, the returned value is
69+
* `quarkus.openapi-generator."petstore_json"`.
70+
* Every the periods (.) in the file name will be replaced by underscore (_).
71+
*/
72+
public static String getBuildTimeSpecPropertyPrefix(final Path openApiFilePath) {
73+
return String.format(BUILD_TIME_SPEC_PREFIX_FORMAT, getSanitizedFileName(openApiFilePath));
74+
}
75+
76+
public static String getSanitizedFileName(final Path openApiFilePath) {
77+
return StringUtil
78+
.replaceNonAlphanumericByUnderscores(OpenApiGeneratorOutputPaths.getRelativePath(openApiFilePath).toString());
79+
}
80+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package io.quarkiverse.openapi.generator.deployment;
2+
3+
public enum CodegenConfigName {
4+
//global configs
5+
VERBOSE("verbose"),
6+
INPUT_BASE_DIR("input-base-dir"),
7+
INCLUDE("include"),
8+
EXCLUDE("exclude"),
9+
VALIDATE_SPEC("validateSpec"),
10+
DEFAULT_SECURITY_SCHEME("default-security-scheme"),
11+
12+
//spec configs only
13+
BASE_PACKAGE("base-package"),
14+
API_NAME_SUFFIX("api-name-suffix"),
15+
MODEL_NAME_SUFFIX("model-name-suffix"),
16+
MODEL_NAME_PREFIX("model-name-prefix"),
17+
18+
//global & spec configs
19+
SKIP_FORM_MODEL("skip-form-model"),
20+
MUTINY("mutiny"),
21+
MUTINY_OPERATION_IDS("mutiny.operation-ids"),
22+
ADDITIONAL_MODEL_TYPE_ANNOTATIONS("additional-model-type-annotations"),
23+
ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER("additional-enum-type-unexpected-member"),
24+
ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_NAME("additional-enum-type-unexpected-member-name"),
25+
ADDITIONAL_ENUM_TYPE_UNEXPECTED_MEMBER_STRING_VALUE("additional-enum-type-unexpected-member-string-value"),
26+
ADDITIONAL_API_TYPE_ANNOTATIONS("additional-api-type-annotations"),
27+
TYPE_MAPPINGS("type-mappings"),
28+
IMPORT_MAPPINGS("import-mappings"),
29+
NORMALIZER("open-api-normalizer"),
30+
RETURN_RESPONSE("return-response"),
31+
ENABLE_SECURITY_GENERATION("enable-security-generation"),
32+
CONFIG_KEY("config-key"),
33+
GENERATE_PART_FILENAME("generate-part-filename"),
34+
PART_FILENAME_VALUE("part-filename-value"),
35+
USE_FIELD_NAME_IN_PART_FILENAME("use-field-name-in-part-filename"),
36+
ADDITIONAL_PROPERTIES_AS_ATTRIBUTE("additional-properties-as-attribute"),
37+
ADDITIONAL_REQUEST_ARGS("additional-request-args"),
38+
BEAN_VALIDATION("use-bean-validation");
39+
40+
public final String name;
41+
42+
CodegenConfigName(String name) {
43+
this.name = name;
44+
}
45+
}

0 commit comments

Comments
 (0)