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:
@@ -31,11 +31,11 @@ import java.util.*;
|
|||||||
|
|
||||||
public class AttributesReadWriteFilterExtensionImpl
|
public class AttributesReadWriteFilterExtensionImpl
|
||||||
implements AttributesReadWriteFilterExtension, AttributesRelatedExtension, ReadWriteRelatedExtension {
|
implements AttributesReadWriteFilterExtension, AttributesRelatedExtension, ReadWriteRelatedExtension {
|
||||||
private static final Set<String> MIDDLEWARES_MUST_COME_BEFORE = Collections.emptySet();
|
private static final Set<String> MIDDLEWARES_MUST_COME_BEFORE = new HashSet<>(Arrays.asList(
|
||||||
private static final Set<String> MIDDLEWARES_MUST_COME_AFTER = new HashSet<>(Arrays.asList(
|
Middleware.DEFAULT_START,
|
||||||
Middleware.DEFAULT_END,
|
|
||||||
"validation"
|
"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 static final UniqueSymbol TWEED_DATA_NOTHING_VALUE = new UniqueSymbol("nothing (skip value)");
|
||||||
|
|
||||||
private final ConfigContainer<?> configContainer;
|
private final ConfigContainer<?> configContainer;
|
||||||
|
|||||||
@@ -53,12 +53,12 @@ public class CommentLoaderExtensionImpl implements CommentLoaderExtension, Comme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> mustComeBefore() {
|
public Set<String> mustComeBefore() {
|
||||||
return Collections.singleton(Middleware.DEFAULT_START);
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> mustComeAfter() {
|
public Set<String> mustComeAfter() {
|
||||||
return Collections.emptySet();
|
return Collections.singleton(Middleware.DEFAULT_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -112,7 +112,8 @@ public class DefaultMiddlewareContainer<M> implements MiddlewareContainer<M> {
|
|||||||
throw new IllegalStateException("Middleware container has not been sealed");
|
throw new IllegalStateException("Middleware container has not been sealed");
|
||||||
}
|
}
|
||||||
M combined = inner;
|
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);
|
combined = middleware.process(combined);
|
||||||
}
|
}
|
||||||
return combined;
|
return combined;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class SimpleValidatorMiddleware implements Middleware<ConfigEntryValidato
|
|||||||
return new ConfigEntryValidator() {
|
return new ConfigEntryValidator() {
|
||||||
@Override
|
@Override
|
||||||
public <T extends @Nullable Object> ValidationResult<T> validate(ConfigEntry<T> configEntry, T value) {
|
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
|
@Override
|
||||||
@@ -28,7 +28,11 @@ public class SimpleValidatorMiddleware implements Middleware<ConfigEntryValidato
|
|||||||
if (description.isEmpty()) {
|
if (description.isEmpty()) {
|
||||||
return inner.description(configEntry);
|
return inner.description(configEntry);
|
||||||
}
|
}
|
||||||
return inner.description(configEntry) + "\n" + description;
|
String innerDescription = inner.description(configEntry);
|
||||||
|
if (innerDescription.isEmpty()) {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
return description + "\n" + innerDescription;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,12 +74,12 @@ public class ValidationFallbackExtensionImpl implements ValidationFallbackExtens
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> mustComeBefore() {
|
public Set<String> mustComeBefore() {
|
||||||
return Collections.emptySet();
|
return Collections.singleton(Middleware.DEFAULT_START);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<String> mustComeAfter() {
|
public Set<String> mustComeAfter() {
|
||||||
return Collections.singleton("$default.end");
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user