Skip to content

Commit bb41584

Browse files
committed
Allow to set default value for config options with AsciiDoc attributes for documentation
See #51024 (comment)
1 parent 750be1a commit bb41584

File tree

7 files changed

+38
-8
lines changed

7 files changed

+38
-8
lines changed

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/discovery/DiscoveryConfigProperty.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class DiscoveryConfigProperty {
1313
private final SourceElementType sourceElementType;
1414
private final String defaultValue;
1515
private final String defaultValueForDoc;
16+
private final boolean escapeDefaultValueForDoc;
1617
private final Deprecation deprecation;
1718
private final String mapKey;
1819
private final boolean unnamedMapKey;
@@ -24,8 +25,8 @@ public class DiscoveryConfigProperty {
2425

2526
public DiscoveryConfigProperty(String path, String sourceType, String sourceElementName,
2627
SourceElementType sourceElementType,
27-
String defaultValue,
28-
String defaultValueForDoc, Deprecation deprecation, String mapKey, boolean unnamedMapKey,
28+
String defaultValue, String defaultValueForDoc, boolean escapeDefaultValueForDoc,
29+
Deprecation deprecation, String mapKey, boolean unnamedMapKey,
2930
ResolvedType type, boolean converted, boolean enforceHyphenateEnumValue,
3031
boolean section, boolean sectionGenerated) {
3132
this.path = path;
@@ -34,6 +35,7 @@ public DiscoveryConfigProperty(String path, String sourceType, String sourceElem
3435
this.sourceElementType = sourceElementType;
3536
this.defaultValue = defaultValue;
3637
this.defaultValueForDoc = defaultValueForDoc;
38+
this.escapeDefaultValueForDoc = escapeDefaultValueForDoc;
3739
this.deprecation = deprecation;
3840
this.mapKey = mapKey;
3941
this.unnamedMapKey = unnamedMapKey;
@@ -68,6 +70,10 @@ public String getDefaultValueForDoc() {
6870
return defaultValueForDoc;
6971
}
7072

73+
public boolean isEscapeDefaultValueForDoc() {
74+
return escapeDefaultValueForDoc;
75+
}
76+
7177
public Deprecation getDeprecation() {
7278
return deprecation;
7379
}
@@ -150,6 +156,7 @@ public static class Builder {
150156
private final ResolvedType type;
151157
private String defaultValue;
152158
private String defaultValueForDoc;
159+
private boolean escapeDefaultValueForDoc = true;
153160
private Deprecation deprecation;
154161
private String mapKey;
155162
private boolean unnamedMapKey = false;
@@ -180,6 +187,11 @@ public Builder defaultValueForDoc(String defaultValueForDoc) {
180187
return this;
181188
}
182189

190+
public Builder escapeDefaultValueForDoc(boolean escapeDefaultValueForDoc) {
191+
this.escapeDefaultValueForDoc = escapeDefaultValueForDoc;
192+
return this;
193+
}
194+
183195
public Builder deprecated(String since, String replacement, String reason) {
184196
this.deprecation = new Deprecation(since, replacement, reason);
185197
return this;
@@ -220,7 +232,7 @@ public DiscoveryConfigProperty build() {
220232
}
221233

222234
return new DiscoveryConfigProperty(name, sourceType, sourceElementName, sourceElementType, defaultValue,
223-
defaultValueForDoc,
235+
defaultValueForDoc, escapeDefaultValueForDoc,
224236
deprecation, mapKey, unnamedMapKey, type, converted, enforceHyphenateEnumValue, section, sectionGenerated);
225237
}
226238
}

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ConfigProperty.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public final class ConfigProperty extends AbstractConfigItem {
2727
private final EnumAcceptedValues enumAcceptedValues;
2828

2929
private final String defaultValue;
30+
private final boolean escapeDefaultValue;
3031

3132
private final String javadocSiteLink;
3233

@@ -35,7 +36,7 @@ public ConfigProperty(ConfigPhase phase, String sourceType, String sourceElement
3536
boolean list, boolean optional, boolean secret,
3637
String mapKey, boolean unnamedMapKey, boolean withinMap, boolean converted, @JsonProperty("enum") boolean isEnum,
3738
EnumAcceptedValues enumAcceptedValues,
38-
String defaultValue, String javadocSiteLink,
39+
String defaultValue, boolean escapeDefaultValue, String javadocSiteLink,
3940
Deprecation deprecation) {
4041
super(sourceType, sourceElementName, sourceElementType, path, type, deprecation);
4142
this.phase = phase;
@@ -52,6 +53,7 @@ public ConfigProperty(ConfigPhase phase, String sourceType, String sourceElement
5253
this.isEnum = isEnum;
5354
this.enumAcceptedValues = enumAcceptedValues;
5455
this.defaultValue = defaultValue;
56+
this.escapeDefaultValue = escapeDefaultValue;
5557
this.javadocSiteLink = javadocSiteLink;
5658
}
5759

@@ -121,6 +123,10 @@ public String getDefaultValue() {
121123
return defaultValue;
122124
}
123125

126+
public boolean isEscapeDefaultValue() {
127+
return escapeDefaultValue;
128+
}
129+
124130
public String getJavadocSiteLink() {
125131
return javadocSiteLink;
126132
}

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/resolver/ConfigResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private void resolveProperty(ConfigRoot configRoot, Map<String, ConfigSection> e
213213
discoveryConfigProperty.isUnnamedMapKey(), context.isWithinMap(),
214214
discoveryConfigProperty.isConverted(),
215215
discoveryConfigProperty.getType().isEnum(),
216-
enumAcceptedValues, defaultValue,
216+
enumAcceptedValues, defaultValue, discoveryConfigProperty.isEscapeDefaultValueForDoc(),
217217
JavadocUtil.getJavadocSiteLink(typeBinaryName),
218218
deprecation);
219219
context.getItemCollection().addItem(configProperty);

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/scanner/ConfigMappingListener.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,12 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem
152152

153153
AnnotationMirror configDocDefaultAnnotation = methodAnnotations.get(Types.ANNOTATION_CONFIG_DOC_DEFAULT);
154154
if (configDocDefaultAnnotation != null) {
155-
builder.defaultValueForDoc(
156-
configDocDefaultAnnotation.getElementValues().values().iterator().next().getValue().toString());
155+
String value = (String) utils.element().getAnnotationValues(configDocDefaultAnnotation).get("value");
156+
builder.defaultValueForDoc(value);
157+
Boolean escape = (Boolean) utils.element().getAnnotationValues(configDocDefaultAnnotation).get("escape");
158+
if (escape != null) {
159+
builder.escapeDefaultValueForDoc(escape);
160+
}
157161
}
158162

159163
if (resolvedType.isMap()) {

core/runtime/src/main/java/io/quarkus/runtime/annotations/ConfigDocDefault.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
public @interface ConfigDocDefault {
2323

2424
String value();
25+
26+
boolean escape() default true;
2527
}

devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/AbstractFormatter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,11 @@ private String formatSingleDefaultValue(ConfigProperty configProperty, String de
252252
}
253253
}
254254

255-
return escapeDefaultValue(defaultValue);
255+
if (configProperty.isEscapeDefaultValue()) {
256+
return escapeDefaultValue(defaultValue);
257+
} else {
258+
return defaultValue;
259+
}
256260
}
257261

258262
private static String trimFinalDot(String javadoc) {

extensions/devservices/keycloak/src/main/java/io/quarkus/devservices/keycloak/KeycloakDevServicesConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.OptionalInt;
88
import java.util.Set;
99

10+
import io.quarkus.runtime.annotations.ConfigDocDefault;
1011
import io.quarkus.runtime.annotations.ConfigDocMapKey;
1112
import io.quarkus.runtime.annotations.ConfigRoot;
1213
import io.quarkus.runtime.configuration.MemorySize;
@@ -40,6 +41,7 @@ public interface KeycloakDevServicesConfig {
4041
* ends with `-legacy`.
4142
* Override with `quarkus.keycloak.devservices.keycloak-x-image`.
4243
*/
44+
@ConfigDocDefault(value = "{keycloak-docker-image}", escape = false)
4345
Optional<String> imageName();
4446

4547
/**

0 commit comments

Comments
 (0)