refactor!: Invert middleware application order

The previous ordering was pretty confusing and even led to a mess-up in the serde validation.
This commit is contained in:
2025-12-17 23:55:57 +01:00
parent e83d87b606
commit c71a01452d
5 changed files with 15 additions and 10 deletions

View File

@@ -31,11 +31,11 @@ import java.util.*;
public class AttributesReadWriteFilterExtensionImpl
implements AttributesReadWriteFilterExtension, AttributesRelatedExtension, ReadWriteRelatedExtension {
private static final Set<String> MIDDLEWARES_MUST_COME_BEFORE = Collections.emptySet();
private static final Set<String> MIDDLEWARES_MUST_COME_AFTER = new HashSet<>(Arrays.asList(
Middleware.DEFAULT_END,
private static final Set<String> MIDDLEWARES_MUST_COME_BEFORE = new HashSet<>(Arrays.asList(
Middleware.DEFAULT_START,
"validation"
));
private static final Set<String> MIDDLEWARES_MUST_COME_AFTER = Collections.emptySet();
private static final UniqueSymbol TWEED_DATA_NOTHING_VALUE = new UniqueSymbol("nothing (skip value)");
private final ConfigContainer<?> configContainer;

View File

@@ -53,12 +53,12 @@ public class CommentLoaderExtensionImpl implements CommentLoaderExtension, Comme
@Override
public Set<String> mustComeBefore() {
return Collections.singleton(Middleware.DEFAULT_START);
return Collections.emptySet();
}
@Override
public Set<String> mustComeAfter() {
return Collections.emptySet();
return Collections.singleton(Middleware.DEFAULT_END);
}
@Override

View File

@@ -112,7 +112,8 @@ public class DefaultMiddlewareContainer<M> implements MiddlewareContainer<M> {
throw new IllegalStateException("Middleware container has not been sealed");
}
M combined = inner;
for (Middleware<M> middleware : middlewares) {
for (int i = middlewares.size() - 1; i >= 0; i--) {
Middleware<M> middleware = middlewares.get(i);
combined = middleware.process(combined);
}
return combined;

View File

@@ -19,7 +19,7 @@ public class SimpleValidatorMiddleware implements Middleware<ConfigEntryValidato
return new ConfigEntryValidator() {
@Override
public <T extends @Nullable Object> ValidationResult<T> validate(ConfigEntry<T> configEntry, T value) {
return inner.validate(configEntry, value).andThen(v -> validator.validate(configEntry, v));
return validator.validate(configEntry, value).andThen(v -> inner.validate(configEntry, v));
}
@Override
@@ -28,7 +28,11 @@ public class SimpleValidatorMiddleware implements Middleware<ConfigEntryValidato
if (description.isEmpty()) {
return inner.description(configEntry);
}
return inner.description(configEntry) + "\n" + description;
String innerDescription = inner.description(configEntry);
if (innerDescription.isEmpty()) {
return description;
}
return description + "\n" + innerDescription;
}
};
}

View File

@@ -74,12 +74,12 @@ public class ValidationFallbackExtensionImpl implements ValidationFallbackExtens
@Override
public Set<String> mustComeBefore() {
return Collections.emptySet();
return Collections.singleton(Middleware.DEFAULT_START);
}
@Override
public Set<String> mustComeAfter() {
return Collections.singleton("$default.end");
return Collections.emptySet();
}
@Override