mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-28 08:44:50 +00:00
Skip the unknown field warning for removed keys that pack validation reports
This commit is contained in:
1 parent
c10341af2b
commit
f4f2c15731
4 files changed
+75
-2
No files matched your search
@@ -19,6 +19,7 @@
|
||||
package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.iris.generation.cave.CaveBounds;
|
||||
import art.arcane.iris.pack.loading.RemovedPackKeys;
|
||||
import art.arcane.volmlib.util.json.JSONArray;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
@@ -42,7 +43,7 @@ import java.util.Set;
|
||||
final class PackCaveValidator {
|
||||
static final String CAVES_FOLDER = "caves";
|
||||
static final String CAVES_KEY = "caves";
|
||||
static final String REMOVED_PROFILE_KEY = "caveProfile";
|
||||
static final String REMOVED_PROFILE_KEY = RemovedPackKeys.CAVE_PROFILE;
|
||||
static final String REMOVED_PROFILE_SNIPPET_FOLDER = "snippet/cave-profile";
|
||||
private static final String REMOVED_PROFILE_ADVICE = "was removed and carves no caves; list caves under \"" + CAVES_KEY + "\" instead";
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ final class JsonSchemaValidator {
|
||||
}
|
||||
Set<String> known = FIELD_CACHE.computeIfAbsent(objectClass, JsonSchemaValidator::collectFieldNames);
|
||||
for (String key : parsed.keySet()) {
|
||||
if (known.contains(key)) {
|
||||
if (known.contains(key) || RemovedPackKeys.isReportedByPackValidation(key)) {
|
||||
continue;
|
||||
}
|
||||
reportUnknownKey(key, rawText, file, resourceTypeName, known);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package art.arcane.iris.pack.loading;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Keys that packs may still carry although no field reads them any more, and that pack validation already reports
|
||||
* once per file with advice on what to use instead.
|
||||
*/
|
||||
public final class RemovedPackKeys {
|
||||
public static final String CAVE_PROFILE = "caveProfile";
|
||||
private static final Set<String> REPORTED_BY_PACK_VALIDATION = Set.of(CAVE_PROFILE);
|
||||
|
||||
private RemovedPackKeys() {
|
||||
}
|
||||
|
||||
public static boolean isReportedByPackValidation(String key) {
|
||||
return REPORTED_BY_PACK_VALIDATION.contains(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package art.arcane.iris.pack.loading;
|
||||
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
|
||||
public class JsonSchemaValidatorTest {
|
||||
private static class Resource {
|
||||
int known;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownKeyIsWarnedAbout() {
|
||||
List<String> warnings = warningsFor("{\"known\":1,\"mystery\":2}");
|
||||
|
||||
assertEquals(warnings.toString(), 1, warnings.size());
|
||||
assertTrue(warnings.get(0).contains("\"mystery\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removedKeyThatPackValidationReportsIsNotWarnedAboutAgain() {
|
||||
List<String> warnings = warningsFor("{\"known\":1,\"" + RemovedPackKeys.CAVE_PROFILE + "\":{}}");
|
||||
|
||||
assertTrue(warnings.toString(), warnings.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removedKeyDoesNotHideOtherUnknownKeys() {
|
||||
List<String> warnings = warningsFor("{\"" + RemovedPackKeys.CAVE_PROFILE + "\":{},\"mystery\":2}");
|
||||
|
||||
assertEquals(warnings.toString(), 1, warnings.size());
|
||||
assertTrue(warnings.get(0).contains("\"mystery\""));
|
||||
}
|
||||
|
||||
private List<String> warningsFor(String rawText) {
|
||||
try (MockedStatic<IrisLogging> logging = mockStatic(IrisLogging.class)) {
|
||||
JsonSchemaValidator.validateTopLevelKeys(new JSONObject(rawText), rawText, new File("dimensions/main.json"), "Dimension", Resource.class);
|
||||
ArgumentCaptor<String> message = ArgumentCaptor.forClass(String.class);
|
||||
logging.verify(() -> IrisLogging.warn(message.capture(), any(Object[].class)), org.mockito.Mockito.atLeast(0));
|
||||
return message.getAllValues();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user