Skip to content

Commit

Permalink
Fix various issues in doc generation related to @ConfigMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Apr 6, 2023
1 parent d2b892c commit 7e5f826
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> SUPPORTED_ANNOTATIONS_TYPES = Set.of(ANNOTATION_BUILD_STEP, ANNOTATION_CONFIG_GROUP,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -226,10 +227,11 @@ private List<ConfigDocItem> 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();
}
}
Expand All @@ -244,13 +246,9 @@ private List<ConfigDocItem> 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<ConfigDocItem> groupConfigItems = readConfigGroupItems(configPhase, rootName, name, type,
Expand Down Expand Up @@ -321,10 +319,14 @@ private List<ConfigDocItem> 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());
Expand All @@ -333,15 +335,18 @@ private List<ConfigDocItem> 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;
}
}
}
Expand Down

0 comments on commit 7e5f826

Please sign in to comment.