summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/ViewModels
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-12 19:15:39 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-04-12 19:15:39 -0400
commit0b48c1748b354458059c7607415288de072b01e9 (patch)
treef63fd950f565d363414eb692be9024895cdea174 /src/SMAPI.Web/ViewModels
parent9fbed0fa1f28a9b0fe0b952a78b10e2d475adb03 (diff)
downloadSMAPI-0b48c1748b354458059c7607415288de072b01e9.tar.gz
SMAPI-0b48c1748b354458059c7607415288de072b01e9.tar.bz2
SMAPI-0b48c1748b354458059c7607415288de072b01e9.zip
enable nullable annotations in the web project & related code (#837)
Diffstat (limited to 'src/SMAPI.Web/ViewModels')
-rw-r--r--src/SMAPI.Web/ViewModels/IndexModel.cs13
-rw-r--r--src/SMAPI.Web/ViewModels/IndexVersionModel.cs15
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorErrorModel.cs15
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorModel.cs29
-rw-r--r--src/SMAPI.Web/ViewModels/JsonValidator/JsonValidatorRequestModel.cs19
-rw-r--r--src/SMAPI.Web/ViewModels/LogParserModel.cs2
-rw-r--r--src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs27
-rw-r--r--src/SMAPI.Web/ViewModels/ModLinkModel.cs6
-rw-r--r--src/SMAPI.Web/ViewModels/ModListModel.cs19
-rw-r--r--src/SMAPI.Web/ViewModels/ModModel.cs65
10 files changed, 119 insertions, 91 deletions
diff --git a/src/SMAPI.Web/ViewModels/IndexModel.cs b/src/SMAPI.Web/ViewModels/IndexModel.cs
index 2283acd9..098f18cc 100644
--- a/src/SMAPI.Web/ViewModels/IndexModel.cs
+++ b/src/SMAPI.Web/ViewModels/IndexModel.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
namespace StardewModdingAPI.Web.ViewModels
{
/// <summary>The view model for the index page.</summary>
@@ -9,26 +7,23 @@ namespace StardewModdingAPI.Web.ViewModels
** Accessors
*********/
/// <summary>The latest stable SMAPI version.</summary>
- public IndexVersionModel StableVersion { get; set; }
+ public IndexVersionModel StableVersion { get; }
/// <summary>A message to show below the download button (e.g. for details on downloading a beta version), in Markdown format.</summary>
- public string OtherBlurb { get; set; }
+ public string? OtherBlurb { get; }
/// <summary>A list of supports to credit on the main page, in Markdown format.</summary>
- public string SupporterList { get; set; }
+ public string? SupporterList { get; }
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- public IndexModel() { }
-
- /// <summary>Construct an instance.</summary>
/// <param name="stableVersion">The latest stable SMAPI version.</param>
/// <param name="otherBlurb">A message to show below the download button (e.g. for details on downloading a beta version), in Markdown format.</param>
/// <param name="supporterList">A list of supports to credit on the main page, in Markdown format.</param>
- internal IndexModel(IndexVersionModel stableVersion, string otherBlurb, string supporterList)
+ internal IndexModel(IndexVersionModel stableVersion, string? otherBlurb, string? supporterList)
{
this.StableVersion = stableVersion;
this.OtherBlurb = otherBlurb;
diff --git a/src/SMAPI.Web/ViewModels/IndexVersionModel.cs b/src/SMAPI.Web/ViewModels/IndexVersionModel.cs
index 1f5d4ec0..a76a5924 100644
--- a/src/SMAPI.Web/ViewModels/IndexVersionModel.cs
+++ b/src/SMAPI.Web/ViewModels/IndexVersionModel.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
namespace StardewModdingAPI.Web.ViewModels
{
/// <summary>The fields for a SMAPI version.</summary>
@@ -9,30 +7,27 @@ namespace StardewModdingAPI.Web.ViewModels
** Accessors
*********/
/// <summary>The release version.</summary>
- public string Version { get; set; }
+ public string Version { get; }
/// <summary>The Markdown description for the release.</summary>
- public string Description { get; set; }
+ public string Description { get; }
/// <summary>The main download URL.</summary>
- public string DownloadUrl { get; set; }
+ public string DownloadUrl { get; }
/// <summary>The for-developers download URL (not applicable for prerelease versions).</summary>
- public string DevDownloadUrl { get; set; }
+ public string? DevDownloadUrl { get; }
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- public IndexVersionModel() { }
-
- /// <summary>Construct an instance.</summary>
/// <param name="version">The release number.</param>
/// <param name="description">The Markdown description for the release.</param>
/// <param name="downloadUrl">The main download URL.</param>
/// <param name="devDownloadUrl">The for-developers download URL (not applicable for prerelease versions).</param>
- internal IndexVersionModel(string version, string description, string downloadUrl, string devDownloadUrl)
+ internal IndexVersionModel(string version, string description, string downloadUrl, string? devDownloadUrl)
{
this.Version = version;
this.Description = description;
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
*********/
/// <summary>The line number on which the error occurred.</summary>
- public int Line { get; set; }
+ public int Line { get; }
/// <summary>The field path in the JSON file where the error occurred.</summary>
- public string Path { get; set; }
+ public string? Path { get; }
/// <summary>A human-readable description of the error.</summary>
- public string Message { get; set; }
+ public string Message { get; }
/// <summary>The schema error type.</summary>
- public ErrorType SchemaErrorType { get; set; }
+ public ErrorType SchemaErrorType { get; }
/*********
** 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>
/// <param name="schemaErrorType">The schema error type.</param>
- 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
*********/
/// <summary>Whether to show the edit view.</summary>
- public bool IsEditView { get; set; }
+ public bool IsEditView { get; }
/// <summary>The paste ID.</summary>
- public string PasteID { get; set; }
+ public string? PasteID { get; }
/// <summary>The schema name with which the JSON was validated.</summary>
- public string SchemaName { get; set; }
+ public string? SchemaName { get; }
/// <summary>The supported JSON schemas (names indexed by ID).</summary>
- public readonly IDictionary<string, string> SchemaFormats;
+ public IDictionary<string, string> SchemaFormats { get; }
/// <summary>The validated content.</summary>
- public string Content { get; set; }
+ public string? Content { get; set; }
/// <summary>The schema validation errors, if any.</summary>
public JsonValidatorErrorModel[] Errors { get; set; } = Array.Empty<JsonValidatorErrorModel>();
/// <summary>A non-blocking warning while uploading the file.</summary>
- public string UploadWarning { get; set; }
+ public string? UploadWarning { get; set; }
/// <summary>When the uploaded file will no longer be available.</summary>
- public DateTime? Expiry { get; set; }
+ public DateTimeOffset? Expiry { get; set; }
/// <summary>An error which occurred while uploading the JSON.</summary>
- public string UploadError { get; set; }
+ public string? UploadError { get; set; }
/// <summary>An error which occurred while parsing the JSON.</summary>
- public string ParseError { get; set; }
+ public string? ParseError { get; set; }
/// <summary>A web URL to the user-facing format documentation.</summary>
- public string FormatUrl { get; set; }
+ public string? FormatUrl { get; set; }
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
- public JsonValidatorModel() { }
-
- /// <summary>Construct an instance.</summary>
/// <param name="pasteID">The stored file 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>
/// <param name="isEditView">Whether to show the edit view.</param>
- public JsonValidatorModel(string pasteID, string schemaName, IDictionary<string, string> schemaFormats, bool isEditView)
+ public JsonValidatorModel(string? pasteID, string? schemaName, IDictionary<string, string> schemaFormats, bool isEditView)
{
this.PasteID = pasteID;
this.SchemaName = schemaName;
@@ -69,7 +64,7 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator
/// <param name="content">The validated content.</param>
/// <param name="expiry">When the uploaded file will no longer be available.</param>
/// <param name="uploadWarning">A non-blocking warning while uploading the log.</param>
- 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
{
/// <summary>The view model for a JSON validation request.</summary>
@@ -9,9 +7,22 @@ namespace StardewModdingAPI.Web.ViewModels.JsonValidator
** Accessors
*********/
/// <summary>The schema name with which to validate the JSON.</summary>
- public string SchemaName { get; set; }
+ public string SchemaName { get; }
/// <summary>The raw content to validate.</summary>
- public string Content { get; set; }
+ public string Content { get; }
+
+
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="schemaName">The schema name with which to validate the JSON.</param>
+ /// <param name="content">The raw content to validate.</param>
+ public JsonValidatorRequestModel(string schemaName, string content)
+ {
+ this.SchemaName = schemaName;
+ this.Content = content;
+ }
}
}
diff --git a/src/SMAPI.Web/ViewModels/LogParserModel.cs b/src/SMAPI.Web/ViewModels/LogParserModel.cs
index d7e4d810..c39a9b0a 100644
--- a/src/SMAPI.Web/ViewModels/LogParserModel.cs
+++ b/src/SMAPI.Web/ViewModels/LogParserModel.cs
@@ -44,7 +44,7 @@ namespace StardewModdingAPI.Web.ViewModels
public string? ParseError => this.ParsedLog?.Error;
/// <summary>When the uploaded file will no longer be available.</summary>
- public DateTime? Expiry { get; set; }
+ public DateTimeOffset? Expiry { get; set; }
/// <summary>Whether parsed log data is available.</summary>
[MemberNotNullWhen(true, nameof(LogParserModel.PasteID), nameof(LogParserModel.ParsedLog))]
diff --git a/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs b/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs
index 2af30cc3..36ea891d 100644
--- a/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs
+++ b/src/SMAPI.Web/ViewModels/ModCompatibilityModel.cs
@@ -1,5 +1,4 @@
-#nullable disable
-
+using Newtonsoft.Json;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;
namespace StardewModdingAPI.Web.ViewModels
@@ -11,22 +10,36 @@ namespace StardewModdingAPI.Web.ViewModels
** Accessors
*********/
/// <summary>The compatibility status, as a string like <c>"Broken"</c>.</summary>
- public string Status { get; set; }
+ public string Status { get; }
/// <summary>The human-readable summary, as an HTML block.</summary>
- public string Summary { get; set; }
+ public string? Summary { get; }
/// <summary>The game or SMAPI version which broke this mod (if applicable).</summary>
- public string BrokeIn { get; set; }
+ public string? BrokeIn { get; }
/// <summary>A link to the unofficial version which fixes compatibility, if any.</summary>
- public ModLinkModel UnofficialVersion { get; set; }
+ public ModLinkModel? UnofficialVersion { get; }
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <param name="status">The compatibility status, as a string like <c>"Broken"</c>.</param>
+ /// <param name="summary">The human-readable summary, as an HTML block.</param>
+ /// <param name="brokeIn">The game or SMAPI version which broke this mod (if applicable).</param>
+ /// <param name="unofficialVersion">A link to the unofficial version which fixes compatibility, if any.</param>
+ [JsonConstructor]
+ public ModCompatibilityModel(string status, string? summary, string? brokeIn, ModLinkModel? unofficialVersion)
+ {
+ this.Status = status;
+ this.Summary = summary;
+ this.BrokeIn = brokeIn;
+ this.UnofficialVersion = unofficialVersion;
+ }
+
+ /// <summary>Construct an instance.</summary>
/// <param name="info">The mod metadata.</param>
public ModCompatibilityModel(WikiCompatibilityInfo info)
{
@@ -36,7 +49,7 @@ namespace StardewModdingAPI.Web.ViewModels
this.Summary = info.Summary;
this.BrokeIn = info.BrokeIn;
if (info.UnofficialVersion != null)
- this.UnofficialVersion = new ModLinkModel(info.UnofficialUrl, info.UnofficialVersion.ToString());
+ this.UnofficialVersion = new ModLinkModel(info.UnofficialUrl!, info.UnofficialVersion.ToString());
}
}
}
diff --git a/src/SMAPI.Web/ViewModels/ModLinkModel.cs b/src/SMAPI.Web/ViewModels/ModLinkModel.cs
index 3039702e..96f14d48 100644
--- a/src/SMAPI.Web/ViewModels/ModLinkModel.cs
+++ b/src/SMAPI.Web/ViewModels/ModLinkModel.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
namespace StardewModdingAPI.Web.ViewModels
{
/// <summary>Metadata about a link.</summary>
@@ -9,10 +7,10 @@ namespace StardewModdingAPI.Web.ViewModels
** Accessors
*********/
/// <summary>The URL of the linked page.</summary>
- public string Url { get; set; }
+ public string Url { get; }
/// <summary>The suggested link text.</summary>
- public string Text { get; set; }
+ public string Text { get; }
/*********
diff --git a/src/SMAPI.Web/ViewModels/ModListModel.cs b/src/SMAPI.Web/ViewModels/ModListModel.cs
index f0cf0c3a..be9f973a 100644
--- a/src/SMAPI.Web/ViewModels/ModListModel.cs
+++ b/src/SMAPI.Web/ViewModels/ModListModel.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
using System;
using System.Collections.Generic;
using System.Linq;
@@ -13,37 +11,34 @@ namespace StardewModdingAPI.Web.ViewModels
** Accessors
*********/
/// <summary>The current stable version of the game.</summary>
- public string StableVersion { get; set; }
+ public string? StableVersion { get; }
/// <summary>The current beta version of the game (if any).</summary>
- public string BetaVersion { get; set; }
+ public string? BetaVersion { get; }
/// <summary>The mods to display.</summary>
- public ModModel[] Mods { get; set; }
+ public ModModel[] Mods { get; }
/// <summary>When the data was last updated.</summary>
- public DateTimeOffset LastUpdated { get; set; }
+ public DateTimeOffset LastUpdated { get; }
/// <summary>Whether the data hasn't been updated in a while.</summary>
- public bool IsStale { get; set; }
+ public bool IsStale { get; }
/// <summary>Whether the mod metadata is available.</summary>
- public bool HasData => this.Mods?.Any() == true;
+ public bool HasData => this.Mods.Any();
/*********
** Public methods
*********/
- /// <summary>Construct an empty instance.</summary>
- public ModListModel() { }
-
/// <summary>Construct an instance.</summary>
/// <param name="stableVersion">The current stable version of the game.</param>
/// <param name="betaVersion">The current beta version of the game (if any).</param>
/// <param name="mods">The mods to display.</param>
/// <param name="lastUpdated">When the data was last updated.</param>
/// <param name="isStale">Whether the data hasn't been updated in a while.</param>
- public ModListModel(string stableVersion, string betaVersion, IEnumerable<ModModel> mods, DateTimeOffset lastUpdated, bool isStale)
+ public ModListModel(string? stableVersion, string? betaVersion, IEnumerable<ModModel> mods, DateTimeOffset lastUpdated, bool isStale)
{
this.StableVersion = stableVersion;
this.BetaVersion = betaVersion;
diff --git a/src/SMAPI.Web/ViewModels/ModModel.cs b/src/SMAPI.Web/ViewModels/ModModel.cs
index d0d7373b..929bf682 100644
--- a/src/SMAPI.Web/ViewModels/ModModel.cs
+++ b/src/SMAPI.Web/ViewModels/ModModel.cs
@@ -1,7 +1,6 @@
-#nullable disable
-
using System.Collections.Generic;
using System.Linq;
+using Newtonsoft.Json;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;
namespace StardewModdingAPI.Web.ViewModels
@@ -13,43 +12,43 @@ namespace StardewModdingAPI.Web.ViewModels
** Accessors
*********/
/// <summary>The mod name.</summary>
- public string Name { get; set; }
+ public string? Name { get; }
/// <summary>The mod's alternative names, if any.</summary>
- public string AlternateNames { get; set; }
+ public string AlternateNames { get; }
/// <summary>The mod author's name.</summary>
- public string Author { get; set; }
+ public string? Author { get; }
/// <summary>The mod author's alternative names, if any.</summary>
- public string AlternateAuthors { get; set; }
+ public string AlternateAuthors { get; }
/// <summary>The GitHub repo, if any.</summary>
- public string GitHubRepo { get; set; }
+ public string? GitHubRepo { get; }
/// <summary>The URL to the mod's source code, if any.</summary>
- public string SourceUrl { get; set; }
+ public string? SourceUrl { get; }
/// <summary>The compatibility status for the stable version of the game.</summary>
- public ModCompatibilityModel Compatibility { get; set; }
+ public ModCompatibilityModel Compatibility { get; }
/// <summary>The compatibility status for the beta version of the game.</summary>
- public ModCompatibilityModel BetaCompatibility { get; set; }
+ public ModCompatibilityModel? BetaCompatibility { get; }
/// <summary>Links to the available mod pages.</summary>
- public ModLinkModel[] ModPages { get; set; }
+ public ModLinkModel[] ModPages { get; }
/// <summary>The human-readable warnings for players about this mod.</summary>
- public string[] Warnings { get; set; }
+ public string[] Warnings { get; }
/// <summary>The URL of the pull request which submits changes for an unofficial update to the author, if any.</summary>
- public string PullRequestUrl { get; set; }
+ public string? PullRequestUrl { get; }
- /// <summary>Special notes intended for developers who maintain unofficial updates or submit pull requests. </summary>
- public string DevNote { get; set; }
+ /// <summary>Special notes intended for developers who maintain unofficial updates or submit pull requests.</summary>
+ public string? DevNote { get; }
/// <summary>A unique identifier for the mod that can be used in an anchor URL.</summary>
- public string Slug { get; set; }
+ public string? Slug { get; }
/// <summary>The sites where the mod can be downloaded.</summary>
public string[] ModPageSites => this.ModPages.Select(p => p.Text).ToArray();
@@ -59,6 +58,38 @@ namespace StardewModdingAPI.Web.ViewModels
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <param name="name">The mod name.</param>
+ /// <param name="alternateNames">The mod's alternative names, if any.</param>
+ /// <param name="author">The mod author's name.</param>
+ /// <param name="alternateAuthors">The mod author's alternative names, if any.</param>
+ /// <param name="gitHubRepo">The GitHub repo, if any.</param>
+ /// <param name="sourceUrl">The URL to the mod's source code, if any.</param>
+ /// <param name="compatibility">The compatibility status for the stable version of the game.</param>
+ /// <param name="betaCompatibility">The compatibility status for the beta version of the game.</param>
+ /// <param name="modPages">Links to the available mod pages.</param>
+ /// <param name="warnings">The human-readable warnings for players about this mod.</param>
+ /// <param name="pullRequestUrl">The URL of the pull request which submits changes for an unofficial update to the author, if any.</param>
+ /// <param name="devNote">Special notes intended for developers who maintain unofficial updates or submit pull requests.</param>
+ /// <param name="slug">A unique identifier for the mod that can be used in an anchor URL.</param>
+ [JsonConstructor]
+ public ModModel(string? name, string alternateNames, string author, string alternateAuthors, string gitHubRepo, string sourceUrl, ModCompatibilityModel compatibility, ModCompatibilityModel betaCompatibility, ModLinkModel[] modPages, string[] warnings, string pullRequestUrl, string devNote, string slug)
+ {
+ this.Name = name;
+ this.AlternateNames = alternateNames;
+ this.Author = author;
+ this.AlternateAuthors = alternateAuthors;
+ this.GitHubRepo = gitHubRepo;
+ this.SourceUrl = sourceUrl;
+ this.Compatibility = compatibility;
+ this.BetaCompatibility = betaCompatibility;
+ this.ModPages = modPages;
+ this.Warnings = warnings;
+ this.PullRequestUrl = pullRequestUrl;
+ this.DevNote = devNote;
+ this.Slug = slug;
+ }
+
+ /// <summary>Construct an instance.</summary>
/// <param name="entry">The mod metadata.</param>
public ModModel(WikiModEntry entry)
{
@@ -84,7 +115,7 @@ namespace StardewModdingAPI.Web.ViewModels
*********/
/// <summary>Get the web URL for the mod's source code repository, if any.</summary>
/// <param name="entry">The mod metadata.</param>
- private string GetSourceUrl(WikiModEntry entry)
+ private string? GetSourceUrl(WikiModEntry entry)
{
if (!string.IsNullOrWhiteSpace(entry.GitHubRepo))
return $"https://github.com/{entry.GitHubRepo}";