diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-09-14 19:01:53 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-09-14 19:01:53 -0400 |
commit | 0c5fa1180949a28ec0c5e2e17df669c1b7c4dbef (patch) | |
tree | 113b44f267630804d0b0c3408800733290b5331f /src/SMAPI.Web/ViewModels | |
parent | 8e0ddd1d00e3d0d11fbaa0ffce804b3e7186c254 (diff) | |
parent | ee0ff5687d4002aab20cd91fd28d007d916af36c (diff) | |
download | SMAPI-0c5fa1180949a28ec0c5e2e17df669c1b7c4dbef.tar.gz SMAPI-0c5fa1180949a28ec0c5e2e17df669c1b7c4dbef.tar.bz2 SMAPI-0c5fa1180949a28ec0c5e2e17df669c1b7c4dbef.zip |
Merge branch 'json-validator' into develop
Diffstat (limited to 'src/SMAPI.Web/ViewModels')
3 files changed, 146 insertions, 0 deletions
diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs new file mode 100644 index 00000000..f9497a38 --- /dev/null +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs @@ -0,0 +1,36 @@ +namespace StardewModdingAPI.Web.ViewModels.JsonValidator +{ + /// <summary>The view model for a JSON validator error.</summary> + public class JsonValidatorErrorModel + { + /********* + ** Accessors + *********/ + /// <summary>The line number on which the error occurred.</summary> + public int Line { get; set; } + + /// <summary>The field path in the JSON file where the error occurred.</summary> + public string Path { get; set; } + + /// <summary>A human-readable description of the error.</summary> + public string Message { get; set; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + public JsonValidatorErrorModel() { } + + /// <summary>Construct an instance.</summary> + /// <param name="line">The line number on which the error occurred.</param> + /// <param name="path">The field path in the JSON file where the error occurred.</param> + /// <param name="message">A human-readable description of the error.</param> + public JsonValidatorErrorModel(int line, string path, string message) + { + this.Line = line; + this.Path = path; + this.Message = message; + } + } +} diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs new file mode 100644 index 00000000..2d13bf23 --- /dev/null +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs @@ -0,0 +1,95 @@ +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; } + + /// <summary>A web URL to the user-facing format documentation.</summary> + public string FormatUrl { 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; + } + } +} diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs new file mode 100644 index 00000000..c8e851bf --- /dev/null +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs @@ -0,0 +1,15 @@ +namespace StardewModdingAPI.Web.ViewModels.JsonValidator +{ + /// <summary>The view model for a JSON validation request.</summary> + public class JsonValidatorRequestModel + { + /********* + ** Accessors + *********/ + /// <summary>The schema name with which to validate the JSON.</summary> + public string SchemaName { get; set; } + + /// <summary>The raw content to validate.</summary> + public string Content { get; set; } + } +} |