diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-08-06 05:14:02 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-09-14 19:06:29 -0400 |
commit | 6036fbf0500795109b1c5dcf53162cb55834d35a (patch) | |
tree | 994a23fd23efd0bb47fda0d5441a004b35fef9de /src | |
parent | 5679df8d66c7ec5f5894761a4f9950a0d2ee9287 (diff) | |
download | SMAPI-6036fbf0500795109b1c5dcf53162cb55834d35a.tar.gz SMAPI-6036fbf0500795109b1c5dcf53162cb55834d35a.tar.bz2 SMAPI-6036fbf0500795109b1c5dcf53162cb55834d35a.zip |
make 'then' blocks transparent by default (#654)
Diffstat (limited to 'src')
-rw-r--r-- | src/SMAPI.Web/Controllers/JsonValidatorController.cs | 17 | ||||
-rw-r--r-- | src/SMAPI.Web/wwwroot/schemas/content-patcher.json | 9 |
2 files changed, 15 insertions, 11 deletions
diff --git a/src/SMAPI.Web/Controllers/JsonValidatorController.cs b/src/SMAPI.Web/Controllers/JsonValidatorController.cs index 4f234449..d82765e7 100644 --- a/src/SMAPI.Web/Controllers/JsonValidatorController.cs +++ b/src/SMAPI.Web/Controllers/JsonValidatorController.cs @@ -213,7 +213,7 @@ namespace StardewModdingAPI.Web.Controllers private IEnumerable<JsonValidatorErrorModel> GetErrorModels(ValidationError error) { // skip through transparent errors - if (this.GetOverrideError(error) == this.TransparentToken && error.ChildErrors.Any()) + if (this.IsTransparentError(error)) { foreach (var model in error.ChildErrors.SelectMany(this.GetErrorModels)) yield return model; @@ -240,7 +240,7 @@ namespace StardewModdingAPI.Web.Controllers return message; // skip through transparent errors - while (this.GetOverrideError(error) == this.TransparentToken && error.ChildErrors.Count == 1) + if (this.IsTransparentError(error)) error = error.ChildErrors[0]; // get friendly representation of main error @@ -266,6 +266,19 @@ namespace StardewModdingAPI.Web.Controllers return message; } + /// <summary>Get whether a validation error should be omitted in favor of its child errors in user-facing error messages.</summary> + /// <param name="error">The error to check.</param> + private bool IsTransparentError(ValidationError error) + { + if (!error.ChildErrors.Any()) + return false; + + string @override = this.GetOverrideError(error); + return + @override == this.TransparentToken + || (error.ErrorType == ErrorType.Then && @override == null); + } + /// <summary>Get an override error from the JSON schema, if any.</summary> /// <param name="error">The schema validation error.</param> private string GetOverrideError(ValidationError error) diff --git a/src/SMAPI.Web/wwwroot/schemas/content-patcher.json b/src/SMAPI.Web/wwwroot/schemas/content-patcher.json index c7f882bc..315a1fb2 100644 --- a/src/SMAPI.Web/wwwroot/schemas/content-patcher.json +++ b/src/SMAPI.Web/wwwroot/schemas/content-patcher.json @@ -273,9 +273,6 @@ "required": [ "FromFile" ], "propertyNames": { "enum": [ "Action", "Target", "LogName", "Enabled", "When", "FromFile" ] - }, - "@errorMessages": { - "then": "$transparent" } } }, @@ -289,9 +286,6 @@ "required": [ "FromFile" ], "propertyNames": { "enum": [ "Action", "Target", "LogName", "Enabled", "When", "FromFile", "FromArea", "ToArea", "PatchMode" ] - }, - "@errorMessages": { - "then": "$transparent" } } }, @@ -304,9 +298,6 @@ "then": { "propertyNames": { "enum": [ "Action", "Target", "LogName", "Enabled", "When", "Fields", "Entries", "MoveEntries" ] - }, - "@errorMessages": { - "then": "$transparent" } } }, |