Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate mapping annotation only in SmallRyeConfigBuilder #1251

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public static ConfigMappingInterface getConfigMapping(final Class<?> type) {
}

static Class<?> getConfigMappingClass(final Class<?> type) {
validateAnnotations(type);

ConfigMappingClass configMappingClass = ConfigMappingClass.getConfigurationClass(type);
if (configMappingClass == null) {
return type;
Expand Down Expand Up @@ -170,16 +168,6 @@ static Class<?> loadClass(final Class<?> parent, final ConfigMappingMetadata con
}
}

static void validateAnnotations(Class<?> type) {
if (!type.isInterface() && type.isAnnotationPresent(ConfigMapping.class)) {
throw ConfigMessages.msg.mappingAnnotationNotSupportedInClass(type);
}

if (type.isInterface() && type.isAnnotationPresent(ConfigProperties.class)) {
throw ConfigMessages.msg.propertiesAnnotationNotSupportedInInterface(type);
}
}

/**
* Do not remove this method or inline it. It is keep separate on purpose, so it is easier to substitute it with
* the GraalVM API for native image compilation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import jakarta.annotation.Priority;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperties;
import org.eclipse.microprofile.config.spi.ConfigBuilder;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.config.spi.ConfigSourceProvider;
Expand Down Expand Up @@ -541,10 +542,6 @@ public SmallRyeConfigBuilder withMapping(ConfigClass configClass) {
return this;
}

/**
* @deprecated Use {@link SmallRyeConfigBuilder#withMapping(ConfigClass)} instead.
*/
@Deprecated(forRemoval = true)
public SmallRyeConfigBuilder withMapping(Class<?> klass, String prefix) {
mappingsBuilder.mapping(klass, prefix);
return this;
Expand Down Expand Up @@ -777,6 +774,7 @@ public final class MappingBuilder {
private final StringBuilder sb = new StringBuilder();

public void mapping(ConfigClass configClass) {
validateAnnotations(configClass.getKlass());
mapping(configClass.getKlass(), configClass.getPrefix());
}

Expand Down Expand Up @@ -823,6 +821,16 @@ public Map<Class<?>, Set<String>> getMappings() {
public List<String> getIgnoredPaths() {
return ignoredPaths;
}

private void validateAnnotations(Class<?> type) {
if (!type.isInterface() && type.isAnnotationPresent(ConfigMapping.class)) {
throw ConfigMessages.msg.mappingAnnotationNotSupportedInClass(type);
}

if (type.isInterface() && type.isAnnotationPresent(ConfigProperties.class)) {
throw ConfigMessages.msg.propertiesAnnotationNotSupportedInInterface(type);
}
}
}

static class ConverterWithPriority {
Expand Down