summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-08-04 03:28:34 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-14 19:00:41 -0400
commit3ba567eaddeaa0bb2bdd749b56e0601d1cf65a25 (patch)
tree61d5bc41560246da5ce727f47287b6730b525fad /src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs
parentc86db64880d52630c372aa24f7aadf0036fb3fcf (diff)
downloadSMAPI-3ba567eaddeaa0bb2bdd749b56e0601d1cf65a25.tar.gz
SMAPI-3ba567eaddeaa0bb2bdd749b56e0601d1cf65a25.tar.bz2
SMAPI-3ba567eaddeaa0bb2bdd749b56e0601d1cf65a25.zip
add JSON validator with initial support for manifest format (#654)
Diffstat (limited to 'src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs')
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs
new file mode 100644
index 00000000..4c122d4f
--- /dev/null
+++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs
@@ -0,0 +1,92 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace StardewModdingAPI.Web.ViewModels.JsonValidator
+{
+ /// <summary>The view model for the JSON validator page.</summary>
+ public class JsonValidatorModel
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The root URL for the log parser controller.</summary>
+ public string SectionUrl { get; set; }
+
+ /// <summary>The paste ID.</summary>
+ public string PasteID { get; set; }
+
+ /// <summary>The schema name with which the JSON was validated.</summary>
+ public string SchemaName { get; set; }
+
+ /// <summary>The supported JSON schemas (names indexed by ID).</summary>
+ public readonly IDictionary<string, string> SchemaFormats;
+
+ /// <summary>The validated content.</summary>
+ public string Content { get; set; }
+
+ /// <summary>The schema validation errors, if any.</summary>
+ public JsonValidatorErrorModel[] Errors { get; set; } = new JsonValidatorErrorModel[0];
+
+ /// <summary>An error which occurred while uploading the JSON to Pastebin.</summary>
+ public string UploadError { get; set; }
+
+ /// <summary>An error which occurred while parsing the JSON.</summary>
+ public string ParseError { get; set; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ public JsonValidatorModel() { }
+
+ /// <summary>Construct an instance.</summary>
+ /// <param name="sectionUrl">The root URL for the log parser controller.</param>
+ /// <param name="pasteID">The paste ID.</param>
+ /// <param name="schemaName">The schema name with which the JSON was validated.</param>
+ /// <param name="schemaFormats">The supported JSON schemas (names indexed by ID).</param>
+ public JsonValidatorModel(string sectionUrl, string pasteID, string schemaName, IDictionary<string, string> schemaFormats)
+ {
+ this.SectionUrl = sectionUrl;
+ this.PasteID = pasteID;
+ this.SchemaName = schemaName;
+ this.SchemaFormats = schemaFormats;
+ }
+
+ /// <summary>Set the validated content.</summary>
+ /// <param name="content">The validated content.</param>
+ public JsonValidatorModel SetContent(string content)
+ {
+ this.Content = content;
+
+ return this;
+ }
+
+ /// <summary>Set the error which occurred while uploading the log to Pastebin.</summary>
+ /// <param name="error">The error message.</param>
+ public JsonValidatorModel SetUploadError(string error)
+ {
+ this.UploadError = error;
+
+ return this;
+ }
+
+ /// <summary>Set the error which occurred while parsing the JSON.</summary>
+ /// <param name="error">The error message.</param>
+ public JsonValidatorModel SetParseError(string error)
+ {
+ this.ParseError = error;
+
+ return this;
+ }
+
+ /// <summary>Add validation errors to the response.</summary>
+ /// <param name="errors">The schema validation errors.</param>
+ public JsonValidatorModel AddErrors(params JsonValidatorErrorModel[] errors)
+ {
+ this.Errors = this.Errors.Concat(errors).ToArray();
+
+ return this;
+ }
+ }
+}