From 7e5f8268a4737cace5af1929c7c60a4dac906b6d Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Wed, 5 Apr 2023 19:26:17 +0200 Subject: [PATCH] Fix various issues in doc generation related to @ConfigMapping --- .../annotation/processor/Constants.java | 1 + .../generate_doc/ConfigDocItemFinder.java | 41 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java b/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java index 5dd32bc4c85dc..c664e4e5228bc 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java @@ -64,6 +64,7 @@ final public class Constants { public static final String ANNOTATION_CONFIG_DOC_DEFAULT = "io.quarkus.runtime.annotations.ConfigDocDefault"; public static final String ANNOTATION_CONFIG_WITH_NAME = "io.smallrye.config.WithName"; + public static final String ANNOTATION_CONFIG_WITH_PARENT_NAME = "io.smallrye.config.WithParentName"; public static final String ANNOTATION_CONFIG_WITH_DEFAULT = "io.smallrye.config.WithDefault"; public static final Set SUPPORTED_ANNOTATIONS_TYPES = Set.of(ANNOTATION_BUILD_STEP, ANNOTATION_CONFIG_GROUP, diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java index ee5374595e209..26035efd27f36 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java @@ -7,6 +7,7 @@ import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_ITEM; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_DEFAULT; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_NAME; +import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_WITH_PARENT_NAME; import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONVERT_WITH; import static io.quarkus.annotation.processor.Constants.ANNOTATION_DEFAULT_CONVERTER; import static io.quarkus.annotation.processor.Constants.DOT; @@ -226,10 +227,11 @@ private List recursivelyFindConfigItems(Element element, String r // Mappings if (annotationName.equals(ANNOTATION_CONFIG_WITH_NAME)) { name = parentName + DOT + annotationMirror.getElementValues().values().iterator().next().getValue(); + } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_PARENT_NAME)) { + name = parentName; } else if (annotationName.equals(ANNOTATION_CONFIG_DOC_DEFAULT)) { - defaultValue = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); - } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT) - && defaultValue == null) { + defaultValueDoc = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); + } else if (annotationName.equals(ANNOTATION_CONFIG_WITH_DEFAULT)) { defaultValue = annotationMirror.getElementValues().values().iterator().next().getValue().toString(); } } @@ -244,13 +246,9 @@ private List recursivelyFindConfigItems(Element element, String r if (name == null) { name = parentName + DOT + hyphenatedFieldName; } - if (NO_DEFAULT.equals(defaultValue)) { defaultValue = EMPTY; } - if (EMPTY.equals(defaultValue)) { - defaultValue = defaultValueDoc; - } if (isConfigGroup(type)) { List groupConfigItems = readConfigGroupItems(configPhase, rootName, name, type, @@ -321,10 +319,14 @@ private List recursivelyFindConfigItems(Element element, String r type = simpleTypeToString(realTypeMirror); if (isEnumType(realTypeMirror)) { - if (useHyphenateEnumValue) { - defaultValue = Arrays.stream(defaultValue.split(COMMA)) - .map(defaultEnumValue -> hyphenateEnumValue(defaultEnumValue.trim())) - .collect(Collectors.joining(COMMA)); + if (defaultValueDoc.isBlank()) { + if (useHyphenateEnumValue) { + defaultValue = Arrays.stream(defaultValue.split(COMMA)) + .map(defaultEnumValue -> hyphenateEnumValue(defaultEnumValue.trim())) + .collect(Collectors.joining(COMMA)); + } + } else { + defaultValue = defaultValueDoc; } acceptedValues = extractEnumValues(realTypeMirror, useHyphenateEnumValue, clazz.getQualifiedName().toString()); @@ -333,15 +335,18 @@ private List recursivelyFindConfigItems(Element element, String r } } else { type = simpleTypeToString(declaredType); - if (isEnumType(declaredType)) { - if (useHyphenateEnumValue) { + + if (defaultValueDoc.isBlank()) { + if (isEnumType(declaredType)) { defaultValue = hyphenateEnumValue(defaultValue); + acceptedValues = extractEnumValues(declaredType, useHyphenateEnumValue, + clazz.getQualifiedName().toString()); + configDocKey.setEnum(true); + } else if (isDurationType(declaredType) && !defaultValue.isEmpty()) { + defaultValue = DocGeneratorUtil.normalizeDurationValue(defaultValue); } - acceptedValues = extractEnumValues(declaredType, useHyphenateEnumValue, - clazz.getQualifiedName().toString()); - configDocKey.setEnum(true); - } else if (isDurationType(declaredType) && !defaultValue.isEmpty()) { - defaultValue = DocGeneratorUtil.normalizeDurationValue(defaultValue); + } else { + defaultValue = defaultValueDoc; } } }