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