From 4da9e954df3846d01aa0536f4e8143466a1d62f3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 11 Feb 2022 00:49:49 -0500 Subject: use Array.Empty to avoid unneeded array allocations --- src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI.Web/ViewModels/JsonValidator') diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs index 0ea69911..e659b389 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs @@ -26,7 +26,7 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator public string Content { get; set; } /// The schema validation errors, if any. - public JsonValidatorErrorModel[] Errors { get; set; } = new JsonValidatorErrorModel[0]; + public JsonValidatorErrorModel[] Errors { get; set; } = Array.Empty(); /// A non-blocking warning while uploading the file. public string UploadWarning { get; set; } -- cgit From 2e7c233f6c9bf6430672b39f970a3324deba79dd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Apr 2022 21:48:55 -0400 Subject: enable nullable annotations by default (#837) This adds `#nullable disable` to all existing code (except where null is impossible like enum files), so it can be migrated incrementally. --- src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs | 2 ++ src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs | 2 ++ src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs | 2 ++ 3 files changed, 6 insertions(+) (limited to 'src/SMAPI.Web/ViewModels/JsonValidator') diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs index 62b95501..3c63b730 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs @@ -1,3 +1,5 @@ +#nullable disable + using Newtonsoft.Json.Schema; namespace StardewModdingAPI.Web.ViewModels.JsonValidator diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs index e659b389..2543807f 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs @@ -1,3 +1,5 @@ +#nullable disable + using System; using System.Collections.Generic; using System.Linq; diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs index c8e851bf..43114d94 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs @@ -1,3 +1,5 @@ +#nullable disable + namespace StardewModdingAPI.Web.ViewModels.JsonValidator { /// The view model for a JSON validation request. -- cgit From 0b48c1748b354458059c7607415288de072b01e9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 12 Apr 2022 19:15:39 -0400 Subject: enable nullable annotations in the web project & related code (#837) --- .../JsonValidator/JsonValidatorErrorModel.cs | 15 ++++------- .../ViewModels/JsonValidator/JsonValidatorModel.cs | 29 +++++++++------------- .../JsonValidator/JsonValidatorRequestModel.cs | 19 +++++++++++--- 3 files changed, 32 insertions(+), 31 deletions(-) (limited to 'src/SMAPI.Web/ViewModels/JsonValidator') diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs index 3c63b730..4d37d449 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs @@ -1,5 +1,3 @@ -#nullable disable - using Newtonsoft.Json.Schema; namespace StardewModdingAPI.Web.ViewModels.JsonValidator @@ -11,30 +9,27 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator ** Accessors *********/ /// The line number on which the error occurred. - public int Line { get; set; } + public int Line { get; } /// The field path in the JSON file where the error occurred. - public string Path { get; set; } + public string? Path { get; } /// A human-readable description of the error. - public string Message { get; set; } + public string Message { get; } /// The schema error type. - public ErrorType SchemaErrorType { get; set; } + public ErrorType SchemaErrorType { get; } /********* ** Public methods *********/ - /// Construct an instance. - public JsonValidatorErrorModel() { } - /// Construct an instance. /// The line number on which the error occurred. /// The field path in the JSON file where the error occurred. /// A human-readable description of the error. /// The schema error type. - public JsonValidatorErrorModel(int line, string path, string message, ErrorType schemaErrorType) + public JsonValidatorErrorModel(int line, string? path, string message, ErrorType schemaErrorType) { this.Line = line; this.Path = path; diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs index 2543807f..85c2f44d 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Collections.Generic; using System.Linq; @@ -13,51 +11,48 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator ** Accessors *********/ /// Whether to show the edit view. - public bool IsEditView { get; set; } + public bool IsEditView { get; } /// The paste ID. - public string PasteID { get; set; } + public string? PasteID { get; } /// The schema name with which the JSON was validated. - public string SchemaName { get; set; } + public string? SchemaName { get; } /// The supported JSON schemas (names indexed by ID). - public readonly IDictionary SchemaFormats; + public IDictionary SchemaFormats { get; } /// The validated content. - public string Content { get; set; } + public string? Content { get; set; } /// The schema validation errors, if any. public JsonValidatorErrorModel[] Errors { get; set; } = Array.Empty(); /// A non-blocking warning while uploading the file. - public string UploadWarning { get; set; } + public string? UploadWarning { get; set; } /// When the uploaded file will no longer be available. - public DateTime? Expiry { get; set; } + public DateTimeOffset? Expiry { get; set; } /// An error which occurred while uploading the JSON. - public string UploadError { get; set; } + public string? UploadError { get; set; } /// An error which occurred while parsing the JSON. - public string ParseError { get; set; } + public string? ParseError { get; set; } /// A web URL to the user-facing format documentation. - public string FormatUrl { get; set; } + public string? FormatUrl { get; set; } /********* ** Public methods *********/ - /// Construct an instance. - public JsonValidatorModel() { } - /// Construct an instance. /// The stored file ID. /// The schema name with which the JSON was validated. /// The supported JSON schemas (names indexed by ID). /// Whether to show the edit view. - public JsonValidatorModel(string pasteID, string schemaName, IDictionary schemaFormats, bool isEditView) + public JsonValidatorModel(string? pasteID, string? schemaName, IDictionary schemaFormats, bool isEditView) { this.PasteID = pasteID; this.SchemaName = schemaName; @@ -69,7 +64,7 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator /// The validated content. /// When the uploaded file will no longer be available. /// A non-blocking warning while uploading the log. - public JsonValidatorModel SetContent(string content, DateTime? expiry, string uploadWarning = null) + public JsonValidatorModel SetContent(string content, DateTimeOffset? expiry, string? uploadWarning = null) { this.Content = content; this.Expiry = expiry; diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs index 43114d94..3edb58db 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs @@ -1,5 +1,3 @@ -#nullable disable - namespace StardewModdingAPI.Web.ViewModels.JsonValidator { /// The view model for a JSON validation request. @@ -9,9 +7,22 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator ** Accessors *********/ /// The schema name with which to validate the JSON. - public string SchemaName { get; set; } + public string SchemaName { get; } /// The raw content to validate. - public string Content { get; set; } + public string Content { get; } + + + /********* + ** Accessors + *********/ + /// Construct an instance. + /// The schema name with which to validate the JSON. + /// The raw content to validate. + public JsonValidatorRequestModel(string schemaName, string content) + { + this.SchemaName = schemaName; + this.Content = content; + } } } -- cgit From b25e30a896cd7ed65d02db7d8639cd28a11981f0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 17 Apr 2022 01:07:18 -0400 Subject: fix model binding error --- .../JsonValidator/JsonValidatorRequestModel.cs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'src/SMAPI.Web/ViewModels/JsonValidator') diff --git a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs index 3edb58db..1313264f 100644 --- a/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs +++ b/src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs @@ -7,22 +7,9 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator ** Accessors *********/ /// The schema name with which to validate the JSON. - public string SchemaName { get; } + public string? SchemaName { get; set; } /// The raw content to validate. - public string Content { get; } - - - /********* - ** Accessors - *********/ - /// Construct an instance. - /// The schema name with which to validate the JSON. - /// The raw content to validate. - public JsonValidatorRequestModel(string schemaName, string content) - { - this.SchemaName = schemaName; - this.Content = content; - } + public string? Content { get; set; } } } -- cgit