From 921f0a9a296ef0dd462057bd97e7a3c1e818c642 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 14 Jul 2022 20:54:46 -0700 Subject: [PATCH] feat: add stringenum --- ...onStringEnumMemberConverterWithFallback.cs | 14 --- .../Converter/StringEnumConverter.cs | 18 +++ .../StringEnumEnumerableConverter.cs | 61 ++++++++++ src/Octokit.Webhooks/Events/CreateEvent.cs | 3 +- src/Octokit.Webhooks/Events/DeleteEvent.cs | 3 +- .../Events/InstallationRepositoriesEvent.cs | 3 +- .../Events/MembershipEvent.cs | 3 +- .../Events/RepositoryImportEvent.cs | 3 +- src/Octokit.Webhooks/Events/StatusEvent.cs | 3 +- src/Octokit.Webhooks/Extensions/StringEnum.cs | 104 +++++++++++++++++ .../Models/ActiveLockReason.cs | 2 - src/Octokit.Webhooks/Models/App.cs | 3 +- src/Octokit.Webhooks/Models/AppEvent.cs | 2 - src/Octokit.Webhooks/Models/AppPermissions.cs | 105 ++++++++++++------ .../Models/AppPermissionsLevel.cs | 2 - .../Models/AuthorAssociation.cs | 2 - .../Models/BranchProtectionRule.cs | 27 +++-- .../ChangesEnforcementLevel.cs | 3 +- .../Models/CheckRunEvent/CheckRun.cs | 6 +- .../CheckRunEvent/CheckRunConclusion.cs | 2 - .../Models/CheckRunEvent/CheckRunStatus.cs | 2 - .../Models/CheckRunEvent/CheckSuite.cs | 6 +- .../CheckRunEvent/CheckSuiteConclusion.cs | 2 - .../Models/CheckRunEvent/CheckSuiteStatus.cs | 2 - .../Models/CheckSuiteEvent/CheckSuite.cs | 6 +- .../CheckSuiteEvent/CheckSuiteConclusion.cs | 2 - .../CheckSuiteEvent/CheckSuiteStatus.cs | 2 - .../Models/CodeScanningAlertEvent/Alert.cs | 6 +- .../CodeScanningAlertEvent/AlertInstance.cs | 3 +- .../CodeScanningAlertEvent/AlertRule.cs | 3 +- .../AlertRuleSeverity.cs | 2 - .../CodeScanningAlertEvent/AlertState.cs | 2 - .../CodeScanningAlertEvent/DismissedReason.cs | 2 - .../Models/CommitCommentEvent/Comment.cs | 3 +- .../DeploymentEvent/DeploymentCheckRun.cs | 6 +- .../DeploymentCheckRunConclusion.cs | 2 - .../DeploymentCheckRunStatus.cs | 2 - .../DeploymentEvent/DeploymentWorkflowRun.cs | 6 +- .../DeploymentWorkflowRunConclusion.cs | 2 - .../DeploymentWorkflowRunStatus.cs | 2 - .../DeploymentStatusEvent/DeploymentStatus.cs | 3 +- .../DeploymentStatusState.cs | 2 - src/Octokit.Webhooks/Models/Discussion.cs | 6 +- .../Models/DiscussionAnswer.cs | 3 +- .../DiscussionComment.cs | 3 +- .../Models/DiscussionState.cs | 2 - .../Models/EnforcementLevel.cs | 2 - .../Models/GollumEvent/Page.cs | 3 +- .../Models/GollumEvent/PageAction.cs | 2 - src/Octokit.Webhooks/Models/Installation.cs | 9 +- .../Models/InstallationRepositorySelection.cs | 2 - .../Models/InstallationTargetType.cs | 2 - src/Octokit.Webhooks/Models/Issue.cs | 9 +- src/Octokit.Webhooks/Models/IssueComment.cs | 3 +- src/Octokit.Webhooks/Models/IssueState.cs | 2 - .../Models/MembershipAddedEvent/Scope.cs | 2 - src/Octokit.Webhooks/Models/MetaEvent/Hook.cs | 3 +- .../Models/MetaEvent/HookConfig.cs | 3 +- .../Models/MetaEvent/HookConfigContentType.cs | 2 - src/Octokit.Webhooks/Models/Milestone.cs | 3 +- src/Octokit.Webhooks/Models/MilestoneState.cs | 2 - src/Octokit.Webhooks/Models/PingEvent/Hook.cs | 6 +- .../Models/PingEvent/HookConfig.cs | 3 +- .../Models/PingEvent/HookConfigContentType.cs | 2 - .../Models/PingEvent/HookType.cs | 2 - src/Octokit.Webhooks/Models/Project.cs | 3 +- src/Octokit.Webhooks/Models/ProjectState.cs | 2 - src/Octokit.Webhooks/Models/ProjectsV2Item.cs | 3 +- .../Models/ProjectsV2ItemContentType.cs | 2 - .../ProjectsV2ItemEvent/ChangesContentType.cs | 6 +- .../ProjectsV2ItemEvent/ChangesFieldValue.cs | 3 +- .../Models/ProjectsV2ItemEvent/FieldType.cs | 2 - .../Models/PullRequestEvent/PullRequest.cs | 9 +- .../PullRequestEvent/PullRequestState.cs | 2 - .../Models/PullRequestReviewComment.cs | 9 +- .../Models/PullRequestReviewEvent/Review.cs | 6 +- .../PullRequestReviewEvent/ReviewState.cs | 2 - src/Octokit.Webhooks/Models/RefType.cs | 2 - src/Octokit.Webhooks/Models/ReleaseAsset.cs | 3 +- .../Models/ReleaseAssetState.cs | 2 - src/Octokit.Webhooks/Models/Repository.cs | 3 +- .../Models/RepositoryImportEvent/Status.cs | 2 - .../Models/RepositoryVisibility.cs | 2 - .../Models/SecretScanningAlertEvent/Alert.cs | 3 +- .../AlertResolution.cs | 2 - src/Octokit.Webhooks/Models/Side.cs | 2 - .../Models/SimplePullRequest.cs | 9 +- .../Models/SimplePullRequestState.cs | 2 - .../Models/StatusEvent/CommitVerification.cs | 3 +- .../StatusEvent/CommitVerificationReason.cs | 2 - .../Models/StatusEvent/StatusState.cs | 2 - src/Octokit.Webhooks/Models/Team.cs | 3 +- src/Octokit.Webhooks/Models/TeamParent.cs | 3 +- .../Models/TeamParentPrivacy.cs | 2 - src/Octokit.Webhooks/Models/TeamPrivacy.cs | 2 - src/Octokit.Webhooks/Models/User.cs | 3 +- src/Octokit.Webhooks/Models/UserType.cs | 2 - .../Models/WorkflowJobEvent/WorkflowJob.cs | 6 +- .../WorkflowJobEvent/WorkflowJobConclusion.cs | 2 - .../WorkflowJobEvent/WorkflowJobStatus.cs | 2 - .../WorkflowJobEvent/WorkflowJobStep.cs | 6 +- .../WorkflowJobStepConclusion.cs | 2 - .../WorkflowJobEvent/WorkflowJobStepStatus.cs | 2 - src/Octokit.Webhooks/Models/WorkflowRun.cs | 6 +- .../Models/WorkflowRunConclusion.cs | 2 - .../Models/WorkflowRunStatus.cs | 2 - src/Octokit.Webhooks/Properties/Usings.cs | 1 + ...ingEnumMemberConverterWithFallbackTests.cs | 65 ----------- .../Converter/StringEnumConverterTests.cs | 40 +++++++ .../StringEnumEnumerableConverterTests.cs | 37 ++++++ ...ngEnumEnumerableConverterTestsKnownData.cs | 15 +++ ...EnumEnumerableConverterTestsUnknownData.cs | 16 +++ .../Extensions/StringEnumTests.cs | 82 ++++++++++++++ test/Octokit.Webhooks.Test/StringEnumTests.cs | 25 +++++ 114 files changed, 629 insertions(+), 298 deletions(-) delete mode 100644 src/Octokit.Webhooks/Converter/JsonStringEnumMemberConverterWithFallback.cs create mode 100644 src/Octokit.Webhooks/Converter/StringEnumConverter.cs create mode 100644 src/Octokit.Webhooks/Converter/StringEnumEnumerableConverter.cs create mode 100644 src/Octokit.Webhooks/Extensions/StringEnum.cs delete mode 100644 test/Octokit.Webhooks.Test/Converter/JsonStringEnumMemberConverterWithFallbackTests.cs create mode 100644 test/Octokit.Webhooks.Test/Converter/StringEnumConverterTests.cs create mode 100644 test/Octokit.Webhooks.Test/Converter/StringEnumEnumerableConverterTests.cs create mode 100644 test/Octokit.Webhooks.Test/Converter/StringEnumEnumerableConverterTestsKnownData.cs create mode 100644 test/Octokit.Webhooks.Test/Converter/StringEnumEnumerableConverterTestsUnknownData.cs create mode 100644 test/Octokit.Webhooks.Test/Extensions/StringEnumTests.cs create mode 100644 test/Octokit.Webhooks.Test/StringEnumTests.cs diff --git a/src/Octokit.Webhooks/Converter/JsonStringEnumMemberConverterWithFallback.cs b/src/Octokit.Webhooks/Converter/JsonStringEnumMemberConverterWithFallback.cs deleted file mode 100644 index 64a47982..00000000 --- a/src/Octokit.Webhooks/Converter/JsonStringEnumMemberConverterWithFallback.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace System.Text.Json.Serialization; - -public sealed class JsonStringEnumMemberConverterWithFallback : JsonStringEnumMemberConverter -{ - private static readonly JsonStringEnumMemberConverterOptions Options = new() - { - DeserializationFailureFallbackValue = -1, // By convention, we use -1 to represent unknown values in all enums. - }; - - public JsonStringEnumMemberConverterWithFallback() - : base(Options) - { - } -} diff --git a/src/Octokit.Webhooks/Converter/StringEnumConverter.cs b/src/Octokit.Webhooks/Converter/StringEnumConverter.cs new file mode 100644 index 00000000..a3f97e41 --- /dev/null +++ b/src/Octokit.Webhooks/Converter/StringEnumConverter.cs @@ -0,0 +1,18 @@ +namespace Octokit.Webhooks.Converter; + +using System; +using System.Text.Json; +using System.Text.Json.Serialization; +using Octokit.Webhooks.Extensions; + +public sealed class StringEnumConverter : JsonConverter> + where TEnum : struct +{ + public override StringEnum Read( + ref Utf8JsonReader reader, + Type typeToConvert, + JsonSerializerOptions options) => new(reader.GetString()!); + + public override void Write(Utf8JsonWriter writer, StringEnum value, JsonSerializerOptions options) => + JsonSerializer.Serialize(writer, value.StringValue, options); +} diff --git a/src/Octokit.Webhooks/Converter/StringEnumEnumerableConverter.cs b/src/Octokit.Webhooks/Converter/StringEnumEnumerableConverter.cs new file mode 100644 index 00000000..fe91dc63 --- /dev/null +++ b/src/Octokit.Webhooks/Converter/StringEnumEnumerableConverter.cs @@ -0,0 +1,61 @@ +namespace Octokit.Webhooks.Converter; + +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization; +using Octokit.Webhooks.Extensions; + +public sealed class StringEnumEnumerableConverter : JsonConverter>> + where TEnum : struct +{ + private static readonly JsonSerializerOptions Options = new() + { + Converters = { Activator.CreateInstance>() }, + }; + + public override IEnumerable> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => + ReadInternal(ref reader); + + public override void Write(Utf8JsonWriter writer, IEnumerable> value, JsonSerializerOptions options) => + WriteInternal(writer, value); + + private static IEnumerable> ReadInternal(ref Utf8JsonReader reader) + { + if (reader.TokenType == JsonTokenType.Null) + { + throw new JsonException("Unexpected null value."); + } + + var returnValue = new List>(); + + while (reader.TokenType != JsonTokenType.EndArray) + { + if (reader.TokenType != JsonTokenType.StartArray) + { + returnValue.Add((StringEnum)JsonSerializer.Deserialize(ref reader, typeof(StringEnum), Options)!); + } + + reader.Read(); + } + + return returnValue!; + } + + private static void WriteInternal(Utf8JsonWriter writer, IEnumerable> value) + { + if (value == null) + { + throw new JsonException("Unexpected null value."); + } + + writer.WriteStartArray(); + + foreach (var data in value) + { + JsonSerializer.Serialize(writer, data, Options); + } + + writer.WriteEndArray(); + } +} diff --git a/src/Octokit.Webhooks/Events/CreateEvent.cs b/src/Octokit.Webhooks/Events/CreateEvent.cs index 9fa4f894..1a0f00c5 100644 --- a/src/Octokit.Webhooks/Events/CreateEvent.cs +++ b/src/Octokit.Webhooks/Events/CreateEvent.cs @@ -8,7 +8,8 @@ public sealed record CreateEvent : WebhookEvent public string Ref { get; init; } = null!; [JsonPropertyName("ref_type")] - public RefType RefType { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum RefType { get; init; } = null!; [JsonPropertyName("master_branch")] public string MasterBranch { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Events/DeleteEvent.cs b/src/Octokit.Webhooks/Events/DeleteEvent.cs index eeaec61d..4f90424b 100644 --- a/src/Octokit.Webhooks/Events/DeleteEvent.cs +++ b/src/Octokit.Webhooks/Events/DeleteEvent.cs @@ -8,7 +8,8 @@ public sealed record DeleteEvent : WebhookEvent public string Ref { get; init; } = null!; [JsonPropertyName("ref_type")] - public RefType RefType { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum RefType { get; init; } = null!; [JsonPropertyName("pusher_type")] public string PusherType { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Events/InstallationRepositoriesEvent.cs b/src/Octokit.Webhooks/Events/InstallationRepositoriesEvent.cs index 75e8a543..1955deeb 100644 --- a/src/Octokit.Webhooks/Events/InstallationRepositoriesEvent.cs +++ b/src/Octokit.Webhooks/Events/InstallationRepositoriesEvent.cs @@ -9,7 +9,8 @@ public abstract record InstallationRepositoriesEvent : WebhookEvent public new Models.Installation Installation { get; init; } = null!; [JsonPropertyName("repository_selection")] - public InstallationRepositorySelection RepositorySelection { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum RepositorySelection { get; init; } = null!; [JsonPropertyName("repositories_added")] public IEnumerable RepositoriesAdded { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Events/MembershipEvent.cs b/src/Octokit.Webhooks/Events/MembershipEvent.cs index f63442a3..9e726258 100644 --- a/src/Octokit.Webhooks/Events/MembershipEvent.cs +++ b/src/Octokit.Webhooks/Events/MembershipEvent.cs @@ -8,7 +8,8 @@ public abstract record MembershipEvent : WebhookEvent { [JsonPropertyName("scope")] - public Scope Scope { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum Scope { get; init; } = null!; [JsonPropertyName("member")] public User Member { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Events/RepositoryImportEvent.cs b/src/Octokit.Webhooks/Events/RepositoryImportEvent.cs index 46ba9591..27dfc7be 100644 --- a/src/Octokit.Webhooks/Events/RepositoryImportEvent.cs +++ b/src/Octokit.Webhooks/Events/RepositoryImportEvent.cs @@ -7,5 +7,6 @@ public sealed record RepositoryImportEvent : WebhookEvent { [JsonPropertyName("status")] - public Status Status { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum Status { get; init; } = null!; } diff --git a/src/Octokit.Webhooks/Events/StatusEvent.cs b/src/Octokit.Webhooks/Events/StatusEvent.cs index 1ec065e0..d9ae2442 100644 --- a/src/Octokit.Webhooks/Events/StatusEvent.cs +++ b/src/Octokit.Webhooks/Events/StatusEvent.cs @@ -28,7 +28,8 @@ public sealed record StatusEvent : WebhookEvent public string? Description { get; init; } [JsonPropertyName("state")] - public StatusState State { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum State { get; init; } = null!; [JsonPropertyName("commit")] public Commit Commit { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Extensions/StringEnum.cs b/src/Octokit.Webhooks/Extensions/StringEnum.cs new file mode 100644 index 00000000..02b1842d --- /dev/null +++ b/src/Octokit.Webhooks/Extensions/StringEnum.cs @@ -0,0 +1,104 @@ +namespace Octokit.Webhooks.Extensions; + +using System; +using System.Globalization; +using System.Linq; +using System.Runtime.Serialization; +using JetBrains.Annotations; + +[PublicAPI] +public sealed record StringEnum + where TEnum : struct +{ + private TEnum? parsedValue; + + public StringEnum(string stringValue) + { + this.StringValue = stringValue; + this.parsedValue = null; + } + + public StringEnum(TEnum parsedValue) + { + if (!Enum.IsDefined(typeof(TEnum), parsedValue)) + { + throw GetArgumentException(parsedValue.ToString()); + } + + this.StringValue = ToEnumString(parsedValue); + this.parsedValue = parsedValue; + } + + public string StringValue { get; } + + public TEnum Value => this.parsedValue ??= this.ParseValue(); + + public static implicit operator StringEnum(string value) => new(value); + + public static implicit operator StringEnum(TEnum parsedValue) => new(parsedValue); + + public bool TryParse(out TEnum value) + { + if (this.parsedValue is not null) + { + value = this.parsedValue.Value; + return true; + } + + try + { + value = ToEnum(this.StringValue); + this.parsedValue = value; + return true; + } + catch (ArgumentException) + { + value = default; + return false; + } + } + + private static ArgumentException GetArgumentException(string? value) => new(string.Format( + CultureInfo.InvariantCulture, + "Value '{0}' is not a valid '{1}' enum value.", + value, + typeof(TEnum).Name)); + + private TEnum ParseValue() + { + if (this.TryParse(out var value)) + { + return value; + } + + throw GetArgumentException(this.StringValue); + } + + private static string ToEnumString(TEnum type) + { + var enumType = typeof(TEnum); + var name = Enum.GetName(enumType, type); + if (name is not null) + { + var enumMemberAttribute = ((EnumMemberAttribute[])enumType.GetField(name)!.GetCustomAttributes(typeof(EnumMemberAttribute), true)).Single(); + return enumMemberAttribute.Value!; + } + + throw new ArgumentException(type.ToString()); + } + + private static TEnum ToEnum(string str) + { + var enumType = typeof(TEnum); + foreach (var name in Enum.GetNames(enumType)) + { + var enumMemberAttribute = ((EnumMemberAttribute[])enumType.GetField(name)!.GetCustomAttributes(typeof(EnumMemberAttribute), true)).Single(); + if (enumMemberAttribute.Value == str) + { + return (TEnum)Enum.Parse(enumType, name); + } + } + + throw new ArgumentException(str); + } +} diff --git a/src/Octokit.Webhooks/Models/ActiveLockReason.cs b/src/Octokit.Webhooks/Models/ActiveLockReason.cs index 59a5f7e1..b5489890 100644 --- a/src/Octokit.Webhooks/Models/ActiveLockReason.cs +++ b/src/Octokit.Webhooks/Models/ActiveLockReason.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum ActiveLockReason { - Unknown = -1, [EnumMember(Value = "resolved")] Resolved, [EnumMember(Value = "off-topic")] diff --git a/src/Octokit.Webhooks/Models/App.cs b/src/Octokit.Webhooks/Models/App.cs index c6094bf9..4f97267f 100644 --- a/src/Octokit.Webhooks/Models/App.cs +++ b/src/Octokit.Webhooks/Models/App.cs @@ -39,5 +39,6 @@ public sealed record App public AppPermissions? Permissions { get; init; } [JsonPropertyName("events")] - public IEnumerable? Events { get; init; } + [JsonConverter(typeof(StringEnumEnumerableConverter))] + public IEnumerable>? Events { get; init; } } diff --git a/src/Octokit.Webhooks/Models/AppEvent.cs b/src/Octokit.Webhooks/Models/AppEvent.cs index 855b3bb0..275f0056 100644 --- a/src/Octokit.Webhooks/Models/AppEvent.cs +++ b/src/Octokit.Webhooks/Models/AppEvent.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum AppEvent { - Unknown = -1, [EnumMember(Value = "*")] All, [EnumMember(Value = "branch_protection_rule")] diff --git a/src/Octokit.Webhooks/Models/AppPermissions.cs b/src/Octokit.Webhooks/Models/AppPermissions.cs index f83df382..a7b83449 100644 --- a/src/Octokit.Webhooks/Models/AppPermissions.cs +++ b/src/Octokit.Webhooks/Models/AppPermissions.cs @@ -4,110 +4,145 @@ public sealed record AppPermissions { [JsonPropertyName("actions")] - public AppPermissionsLevel? Actions { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Actions { get; init; } [JsonPropertyName("administration")] - public AppPermissionsLevel? Administration { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Administration { get; init; } [JsonPropertyName("blocking")] public AppPermissionsLevel? Blocking { get; init; } [JsonPropertyName("checks")] - public AppPermissionsLevel? Checks { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Checks { get; init; } [JsonPropertyName("content_references")] - public AppPermissionsLevel? ContentReferences { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? ContentReferences { get; init; } [JsonPropertyName("contents")] - public AppPermissionsLevel? Contents { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Contents { get; init; } [JsonPropertyName("deployments")] - public AppPermissionsLevel? Deployments { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Deployments { get; init; } [JsonPropertyName("discussions")] - public AppPermissionsLevel? Discussions { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Discussions { get; init; } [JsonPropertyName("emails")] - public AppPermissionsLevel? Emails { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Emails { get; init; } [JsonPropertyName("environments")] - public AppPermissionsLevel? Environments { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Environments { get; init; } [JsonPropertyName("issues")] - public AppPermissionsLevel? Issues { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Issues { get; init; } [JsonPropertyName("members")] - public AppPermissionsLevel? Members { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Members { get; init; } [JsonPropertyName("merge_queues")] - public AppPermissionsLevel? MergeQueues { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? MergeQueues { get; init; } [JsonPropertyName("metadata")] - public AppPermissionsLevel? Metadata { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Metadata { get; init; } [JsonPropertyName("organization_administration")] - public AppPermissionsLevel? OrganizationAdministration { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? OrganizationAdministration { get; init; } [JsonPropertyName("organization_hooks")] - public AppPermissionsLevel? OrganizationHooks { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? OrganizationHooks { get; init; } [JsonPropertyName("organization_packages")] - public AppPermissionsLevel? OrganizationPackages { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? OrganizationPackages { get; init; } [JsonPropertyName("organization_plan")] - public AppPermissionsLevel? OrganizationPlan { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? OrganizationPlan { get; init; } [JsonPropertyName("organization_projects")] - public AppPermissionsLevel? OrganizationProjects { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? OrganizationProjects { get; init; } [JsonPropertyName("organization_secrets")] - public AppPermissionsLevel? OrganizationSecrets { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? OrganizationSecrets { get; init; } [JsonPropertyName("organization_self_hosted_runners")] - public AppPermissionsLevel? OrganizationSelfHostedRunners { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? OrganizationSelfHostedRunners { get; init; } [JsonPropertyName("organization_user_blocking")] - public AppPermissionsLevel? OrganizationUserBlocking { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? OrganizationUserBlocking { get; init; } [JsonPropertyName("packages")] - public AppPermissionsLevel? Packages { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Packages { get; init; } [JsonPropertyName("pages")] - public AppPermissionsLevel? Pages { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Pages { get; init; } [JsonPropertyName("pull_requests")] - public AppPermissionsLevel? PullRequests { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? PullRequests { get; init; } [JsonPropertyName("repository_hooks")] - public AppPermissionsLevel? RepositoryHooks { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? RepositoryHooks { get; init; } [JsonPropertyName("repository_projects")] - public AppPermissionsLevel? RepositoryProjects { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? RepositoryProjects { get; init; } [JsonPropertyName("secret_scanning_alerts")] - public AppPermissionsLevel? SecretScanningAlerts { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? SecretScanningAlerts { get; init; } [JsonPropertyName("secrets")] - public AppPermissionsLevel? Secrets { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Secrets { get; init; } [JsonPropertyName("security_events")] - public AppPermissionsLevel? SecurityEvents { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? SecurityEvents { get; init; } [JsonPropertyName("security_scanning_alert")] - public AppPermissionsLevel? SecurityScanningAlert { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? SecurityScanningAlert { get; init; } [JsonPropertyName("single_file")] - public AppPermissionsLevel? SingleFile { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? SingleFile { get; init; } [JsonPropertyName("statuses")] - public AppPermissionsLevel? Statuses { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Statuses { get; init; } [JsonPropertyName("team_discussions")] - public AppPermissionsLevel? TeamDiscussions { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? TeamDiscussions { get; init; } [JsonPropertyName("vulnerability_alerts")] - public AppPermissionsLevel? VulnerabilityAlerts { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? VulnerabilityAlerts { get; init; } [JsonPropertyName("workflows")] - public AppPermissionsLevel? Workflows { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Workflows { get; init; } } diff --git a/src/Octokit.Webhooks/Models/AppPermissionsLevel.cs b/src/Octokit.Webhooks/Models/AppPermissionsLevel.cs index 263b707b..7ca3d1c4 100644 --- a/src/Octokit.Webhooks/Models/AppPermissionsLevel.cs +++ b/src/Octokit.Webhooks/Models/AppPermissionsLevel.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum AppPermissionsLevel { - Unknown = -1, [EnumMember(Value = "read")] Read, [EnumMember(Value = "write")] diff --git a/src/Octokit.Webhooks/Models/AuthorAssociation.cs b/src/Octokit.Webhooks/Models/AuthorAssociation.cs index f06abd3a..13567069 100644 --- a/src/Octokit.Webhooks/Models/AuthorAssociation.cs +++ b/src/Octokit.Webhooks/Models/AuthorAssociation.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum AuthorAssociation { - Unknown = -1, [EnumMember(Value = "COLLABORATOR")] Collaborator, [EnumMember(Value = "CONTRIBUTOR")] diff --git a/src/Octokit.Webhooks/Models/BranchProtectionRule.cs b/src/Octokit.Webhooks/Models/BranchProtectionRule.cs index 45406b78..5c4e41c1 100644 --- a/src/Octokit.Webhooks/Models/BranchProtectionRule.cs +++ b/src/Octokit.Webhooks/Models/BranchProtectionRule.cs @@ -27,10 +27,12 @@ public sealed record BranchProtectionRule public bool? CreateProtected { get; init; } [JsonPropertyName("allow_deletions_enforcement_level")] - public EnforcementLevel AllowDeletionsEnforcementLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum AllowDeletionsEnforcementLevel { get; init; } = null!; [JsonPropertyName("allow_force_pushes_enforcement_level")] - public EnforcementLevel AllowForcePushesEnforcementLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum AllowForcePushesEnforcementLevel { get; init; } = null!; [JsonPropertyName("authorized_actor_names")] public IEnumerable AuthorizedActorNames { get; init; } = null!; @@ -48,13 +50,16 @@ public sealed record BranchProtectionRule public bool IgnoreApprovalsFromContributors { get; init; } [JsonPropertyName("linear_history_requirement_enforcement_level")] - public EnforcementLevel LinearHistoryRequirementEnforcementLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum LinearHistoryRequirementEnforcementLevel { get; init; } = null!; [JsonPropertyName("merge_queue_enforcement_level")] - public EnforcementLevel MergeQueueEnforcementLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum MergeQueueEnforcementLevel { get; init; } = null!; [JsonPropertyName("pull_request_reviews_enforcement_level")] - public EnforcementLevel PullRequestReviewsEnforcementLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum PullRequestReviewsEnforcementLevel { get; init; } = null!; [JsonPropertyName("require_code_owner_review")] public bool RequireCodeOwnerReview { get; init; } @@ -63,19 +68,23 @@ public sealed record BranchProtectionRule public long RequiredApprovingReviewCount { get; init; } [JsonPropertyName("required_conversation_resolution_level")] - public EnforcementLevel RequiredConversationResolutionLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum RequiredConversationResolutionLevel { get; init; } = null!; [JsonPropertyName("required_deployments_enforcement_level")] - public EnforcementLevel RequiredDeploymentsEnforcementLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum RequiredDeploymentsEnforcementLevel { get; init; } = null!; [JsonPropertyName("required_status_checks")] public IEnumerable RequiredStatusChecks { get; init; } = null!; [JsonPropertyName("required_status_checks_enforcement_level")] - public EnforcementLevel RequiredStatusChecksEnforcementLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum RequiredStatusChecksEnforcementLevel { get; init; } = null!; [JsonPropertyName("signature_requirement_enforcement_level")] - public EnforcementLevel SignatureRequirementEnforcementLevel { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum SignatureRequirementEnforcementLevel { get; init; } = null!; [JsonPropertyName("strict_required_status_checks_policy")] public bool StrictRequiredStatusChecksPolicy { get; init; } diff --git a/src/Octokit.Webhooks/Models/BranchProtectionRuleEvent/ChangesEnforcementLevel.cs b/src/Octokit.Webhooks/Models/BranchProtectionRuleEvent/ChangesEnforcementLevel.cs index 1474f65b..a91228a9 100644 --- a/src/Octokit.Webhooks/Models/BranchProtectionRuleEvent/ChangesEnforcementLevel.cs +++ b/src/Octokit.Webhooks/Models/BranchProtectionRuleEvent/ChangesEnforcementLevel.cs @@ -4,5 +4,6 @@ namespace Octokit.Webhooks.Models.BranchProtectionRuleEvent; public sealed record ChangesEnforcementLevel { [JsonPropertyName("from")] - public EnforcementLevel? From { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? From { get; init; } } diff --git a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRun.cs b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRun.cs index 560cfaf3..76f4e12b 100644 --- a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRun.cs +++ b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRun.cs @@ -25,10 +25,12 @@ public sealed record CheckRun public string DetailsUrl { get; init; } = null!; [JsonPropertyName("status")] - public CheckRunStatus Status { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum Status { get; init; } = null!; [JsonPropertyName("conclusion")] - public CheckRunConclusion? Conclusion { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Conclusion { get; init; } [JsonPropertyName("started_at")] [JsonConverter(typeof(DateTimeOffsetConverter))] diff --git a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRunConclusion.cs b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRunConclusion.cs index a6e5098b..d9070f6a 100644 --- a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRunConclusion.cs +++ b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRunConclusion.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CheckRunEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum CheckRunConclusion { - Unknown = -1, [EnumMember(Value = "success")] Success, [EnumMember(Value = "failure")] diff --git a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRunStatus.cs b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRunStatus.cs index 19a37a7f..10004172 100644 --- a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRunStatus.cs +++ b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckRunStatus.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CheckRunEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum CheckRunStatus { - Unknown = -1, [EnumMember(Value = "requested")] Requested, [EnumMember(Value = "in_progress")] diff --git a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuite.cs b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuite.cs index 9bcebe1e..fc53cd79 100644 --- a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuite.cs +++ b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuite.cs @@ -16,10 +16,12 @@ public sealed record CheckSuite public string HeadSha { get; init; } = null!; [JsonPropertyName("status")] - public CheckSuiteStatus Status { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum Status { get; init; } = null!; [JsonPropertyName("conclusion")] - public CheckSuiteConclusion? Conclusion { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Conclusion { get; init; } [JsonPropertyName("url")] public string Url { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuiteConclusion.cs b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuiteConclusion.cs index 1e6b8fee..01c6c2b3 100644 --- a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuiteConclusion.cs +++ b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuiteConclusion.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CheckRunEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum CheckSuiteConclusion { - Unknown = -1, [EnumMember(Value = "success")] Success, [EnumMember(Value = "failure")] diff --git a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuiteStatus.cs b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuiteStatus.cs index f9be12dd..4b33e0b6 100644 --- a/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuiteStatus.cs +++ b/src/Octokit.Webhooks/Models/CheckRunEvent/CheckSuiteStatus.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CheckRunEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum CheckSuiteStatus { - Unknown = -1, [EnumMember(Value = "queued")] Queued, [EnumMember(Value = "in_progress")] diff --git a/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuite.cs b/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuite.cs index 81388401..e7653d92 100644 --- a/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuite.cs +++ b/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuite.cs @@ -18,10 +18,12 @@ public sealed record CheckSuite public string HeadSha { get; init; } = null!; [JsonPropertyName("status")] - public CheckSuiteStatus? Status { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Status { get; init; } [JsonPropertyName("conclusion")] - public CheckSuiteConclusion? Conclusion { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Conclusion { get; init; } [JsonPropertyName("url")] public string Url { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuiteConclusion.cs b/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuiteConclusion.cs index 891da78f..973d1c10 100644 --- a/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuiteConclusion.cs +++ b/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuiteConclusion.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CheckSuiteEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum CheckSuiteConclusion { - Unknown = -1, [EnumMember(Value = "success")] Success, [EnumMember(Value = "failure")] diff --git a/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuiteStatus.cs b/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuiteStatus.cs index 161b1405..2c4d0338 100644 --- a/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuiteStatus.cs +++ b/src/Octokit.Webhooks/Models/CheckSuiteEvent/CheckSuiteStatus.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CheckSuiteEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum CheckSuiteStatus { - Unknown = -1, [EnumMember(Value = "requested")] Requested, [EnumMember(Value = "in_progress")] diff --git a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/Alert.cs b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/Alert.cs index 15776227..d4a0ff9b 100644 --- a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/Alert.cs +++ b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/Alert.cs @@ -23,7 +23,8 @@ public sealed record Alert public AlertInstance AlertInstance { get; init; } = null!; [JsonPropertyName("state")] - public AlertState State { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum State { get; init; } = null!; [JsonPropertyName("dismissed_by")] public User? DismissedBy { get; init; } @@ -33,7 +34,8 @@ public sealed record Alert public DateTimeOffset? DismissedAt { get; init; } [JsonPropertyName("dismissed_reason")] - public DismissedReason? DismissedReason { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? DismissedReason { get; init; } [JsonPropertyName("rule")] public AlertRule? Rule { get; init; } diff --git a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertInstance.cs b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertInstance.cs index 00058665..a8e97422 100644 --- a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertInstance.cs +++ b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertInstance.cs @@ -13,7 +13,8 @@ public sealed record AlertInstance public string Environment { get; init; } = null!; [JsonPropertyName("state")] - public AlertState State { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum State { get; init; } = null!; [JsonPropertyName("commit_sha")] public string? CommitSha { get; init; } diff --git a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRule.cs b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRule.cs index 30128e1c..2f7728d0 100644 --- a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRule.cs +++ b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRule.cs @@ -7,7 +7,8 @@ public sealed record AlertRule public string Id { get; init; } = null!; [JsonPropertyName("severity")] - public AlertRuleSeverity? Severity { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Severity { get; init; } [JsonPropertyName("description")] public string Description { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRuleSeverity.cs b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRuleSeverity.cs index efd57991..e8fc1fae 100644 --- a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRuleSeverity.cs +++ b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertRuleSeverity.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CodeScanningAlertEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum AlertRuleSeverity { - Unknown = -1, [EnumMember(Value = "none")] Open, [EnumMember(Value = "note")] diff --git a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertState.cs b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertState.cs index 5f69364b..be523b9d 100644 --- a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertState.cs +++ b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/AlertState.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CodeScanningAlertEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum AlertState { - Unknown = -1, [EnumMember(Value = "open")] Open, [EnumMember(Value = "dismissed")] diff --git a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/DismissedReason.cs b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/DismissedReason.cs index caefc700..345b9d7f 100644 --- a/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/DismissedReason.cs +++ b/src/Octokit.Webhooks/Models/CodeScanningAlertEvent/DismissedReason.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.CodeScanningAlertEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum DismissedReason { - Unknown = -1, [EnumMember(Value = "false positive")] FalsePositive, [EnumMember(Value = "won't fix")] diff --git a/src/Octokit.Webhooks/Models/CommitCommentEvent/Comment.cs b/src/Octokit.Webhooks/Models/CommitCommentEvent/Comment.cs index 279801fa..9bea256d 100644 --- a/src/Octokit.Webhooks/Models/CommitCommentEvent/Comment.cs +++ b/src/Octokit.Webhooks/Models/CommitCommentEvent/Comment.cs @@ -39,7 +39,8 @@ public sealed record Comment public DateTimeOffset UpdatedAt { get; init; } [JsonPropertyName("author_association")] - public AuthorAssociation AuthorAssociation { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum AuthorAssociation { get; init; } = null!; [JsonPropertyName("body")] public string Body { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRun.cs b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRun.cs index e3d29ee7..3b3985e3 100644 --- a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRun.cs +++ b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRun.cs @@ -28,10 +28,12 @@ public sealed record DeploymentCheckRun public string DetailsUrl { get; init; } = null!; [JsonPropertyName("status")] - public DeploymentCheckRunStatus Status { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum Status { get; init; } = null!; [JsonPropertyName("conclusion")] - public DeploymentCheckRunConclusion? Conclusion { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Conclusion { get; init; } [JsonPropertyName("started_at")] [JsonConverter(typeof(DateTimeOffsetConverter))] diff --git a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRunConclusion.cs b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRunConclusion.cs index bc2cc5e8..c85be1d5 100644 --- a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRunConclusion.cs +++ b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRunConclusion.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.DeploymentEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum DeploymentCheckRunConclusion { - Unknown = -1, [EnumMember(Value = "success")] Success, [EnumMember(Value = "failure")] diff --git a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRunStatus.cs b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRunStatus.cs index 73274b62..c29b59fa 100644 --- a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRunStatus.cs +++ b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentCheckRunStatus.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.DeploymentEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum DeploymentCheckRunStatus { - Unknown = -1, [EnumMember(Value = "requested")] Requested, [EnumMember(Value = "in_progress")] diff --git a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRun.cs b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRun.cs index 9ffc20ff..af3958ed 100644 --- a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRun.cs +++ b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRun.cs @@ -30,10 +30,12 @@ public sealed record DeploymentWorkflowRun public string Event { get; init; } = null!; [JsonPropertyName("status")] - public DeploymentWorkflowRunStatus? Status { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Status { get; init; } [JsonPropertyName("conclusion")] - public DeploymentWorkflowRunConclusion? Conclusion { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum? Conclusion { get; init; } [JsonPropertyName("workflow_id")] public long WorkflowId { get; init; } diff --git a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRunConclusion.cs b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRunConclusion.cs index 1484e5dd..cf9d0791 100644 --- a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRunConclusion.cs +++ b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRunConclusion.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.DeploymentEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum DeploymentWorkflowRunConclusion { - Unknown = -1, [EnumMember(Value = "success")] Success, [EnumMember(Value = "failure")] diff --git a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRunStatus.cs b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRunStatus.cs index 70070cfb..b6340967 100644 --- a/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRunStatus.cs +++ b/src/Octokit.Webhooks/Models/DeploymentEvent/DeploymentWorkflowRunStatus.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.DeploymentEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum DeploymentWorkflowRunStatus { - Unknown = -1, [EnumMember(Value = "requested")] Requested, [EnumMember(Value = "in_progress")] diff --git a/src/Octokit.Webhooks/Models/DeploymentStatusEvent/DeploymentStatus.cs b/src/Octokit.Webhooks/Models/DeploymentStatusEvent/DeploymentStatus.cs index 8866d0ac..9aafd192 100644 --- a/src/Octokit.Webhooks/Models/DeploymentStatusEvent/DeploymentStatus.cs +++ b/src/Octokit.Webhooks/Models/DeploymentStatusEvent/DeploymentStatus.cs @@ -13,7 +13,8 @@ public sealed record DeploymentStatus public string NodeId { get; init; } = null!; [JsonPropertyName("state")] - public DeploymentStatusState State { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum State { get; init; } = null!; [JsonPropertyName("creator")] public User Creator { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Models/DeploymentStatusEvent/DeploymentStatusState.cs b/src/Octokit.Webhooks/Models/DeploymentStatusEvent/DeploymentStatusState.cs index c65d3aee..38aa1de1 100644 --- a/src/Octokit.Webhooks/Models/DeploymentStatusEvent/DeploymentStatusState.cs +++ b/src/Octokit.Webhooks/Models/DeploymentStatusEvent/DeploymentStatusState.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.DeploymentStatusEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum DeploymentStatusState { - Unknown = -1, [EnumMember(Value = "pending")] Pending, [EnumMember(Value = "in_progress")] diff --git a/src/Octokit.Webhooks/Models/Discussion.cs b/src/Octokit.Webhooks/Models/Discussion.cs index 65ac9ff9..58813c31 100644 --- a/src/Octokit.Webhooks/Models/Discussion.cs +++ b/src/Octokit.Webhooks/Models/Discussion.cs @@ -38,7 +38,8 @@ public sealed record Discussion public User User { get; init; } = null!; [JsonPropertyName("state")] - public DiscussionState State { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum State { get; init; } = null!; [JsonPropertyName("locked")] public bool Locked { get; init; } @@ -55,7 +56,8 @@ public sealed record Discussion public DateTimeOffset UpdatedAt { get; init; } [JsonPropertyName("author_association")] - public AuthorAssociation AuthorAssociation { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum AuthorAssociation { get; init; } = null!; [JsonPropertyName("active_lock_reason")] public string? ActiveLockReason { get; init; } diff --git a/src/Octokit.Webhooks/Models/DiscussionAnswer.cs b/src/Octokit.Webhooks/Models/DiscussionAnswer.cs index 01190858..485a2b24 100644 --- a/src/Octokit.Webhooks/Models/DiscussionAnswer.cs +++ b/src/Octokit.Webhooks/Models/DiscussionAnswer.cs @@ -25,7 +25,8 @@ public sealed record DiscussionAnswer public long DiscussionId { get; init; } [JsonPropertyName("author_association")] - public AuthorAssociation AuthorAssociation { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum AuthorAssociation { get; init; } = null!; [JsonPropertyName("user")] public User User { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Models/DiscussionCommentEvent/DiscussionComment.cs b/src/Octokit.Webhooks/Models/DiscussionCommentEvent/DiscussionComment.cs index fd787a50..7bfb0bf3 100644 --- a/src/Octokit.Webhooks/Models/DiscussionCommentEvent/DiscussionComment.cs +++ b/src/Octokit.Webhooks/Models/DiscussionCommentEvent/DiscussionComment.cs @@ -25,7 +25,8 @@ public sealed record DiscussionComment public long DiscussionId { get; init; } [JsonPropertyName("author_association")] - public AuthorAssociation AuthorAssociation { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum AuthorAssociation { get; init; } = null!; [JsonPropertyName("user")] public User User { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Models/DiscussionState.cs b/src/Octokit.Webhooks/Models/DiscussionState.cs index 56d53b12..646e00ab 100644 --- a/src/Octokit.Webhooks/Models/DiscussionState.cs +++ b/src/Octokit.Webhooks/Models/DiscussionState.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum DiscussionState { - Unknown = -1, [EnumMember(Value = "open")] Open, [EnumMember(Value = "locked")] diff --git a/src/Octokit.Webhooks/Models/EnforcementLevel.cs b/src/Octokit.Webhooks/Models/EnforcementLevel.cs index 48ef2dd8..7c686fcd 100644 --- a/src/Octokit.Webhooks/Models/EnforcementLevel.cs +++ b/src/Octokit.Webhooks/Models/EnforcementLevel.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum EnforcementLevel { - Unknown = -1, [EnumMember(Value = "off")] Off, [EnumMember(Value = "non_admins")] diff --git a/src/Octokit.Webhooks/Models/GollumEvent/Page.cs b/src/Octokit.Webhooks/Models/GollumEvent/Page.cs index 3c65feb0..125da2e7 100644 --- a/src/Octokit.Webhooks/Models/GollumEvent/Page.cs +++ b/src/Octokit.Webhooks/Models/GollumEvent/Page.cs @@ -13,7 +13,8 @@ public sealed record Page public string? Summary { get; init; } [JsonPropertyName("action")] - public PageAction Action { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum Action { get; init; } = null!; [JsonPropertyName("sha")] public string Sha { get; init; } = null!; diff --git a/src/Octokit.Webhooks/Models/GollumEvent/PageAction.cs b/src/Octokit.Webhooks/Models/GollumEvent/PageAction.cs index d216da77..4174f454 100644 --- a/src/Octokit.Webhooks/Models/GollumEvent/PageAction.cs +++ b/src/Octokit.Webhooks/Models/GollumEvent/PageAction.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models.GollumEvent; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum PageAction { - Unknown = -1, [EnumMember(Value = "created")] Created, [EnumMember(Value = "edited")] diff --git a/src/Octokit.Webhooks/Models/Installation.cs b/src/Octokit.Webhooks/Models/Installation.cs index 4f69b169..4bd11ab5 100644 --- a/src/Octokit.Webhooks/Models/Installation.cs +++ b/src/Octokit.Webhooks/Models/Installation.cs @@ -10,7 +10,8 @@ public sealed record Installation public User Account { get; init; } = null!; [JsonPropertyName("repository_selection")] - public InstallationRepositorySelection RepositorySelection { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum RepositorySelection { get; init; } = null!; [JsonPropertyName("access_tokens_url")] public string AccessTokensUrl { get; init; } = null!; @@ -31,13 +32,15 @@ public sealed record Installation public long TargetId { get; init; } [JsonPropertyName("target_type")] - public InstallationTargetType TargetType { get; init; } + [JsonConverter(typeof(StringEnumConverter))] + public StringEnum TargetType { get; init; } = null!; [JsonPropertyName("permissions")] public AppPermissions? Permissions { get; init; } [JsonPropertyName("events")] - public IEnumerable? Events { get; init; } + [JsonConverter(typeof(StringEnumEnumerableConverter))] + public IEnumerable>? Events { get; init; } [JsonPropertyName("created_at")] [JsonConverter(typeof(NullableDateTimeOffsetConverter))] diff --git a/src/Octokit.Webhooks/Models/InstallationRepositorySelection.cs b/src/Octokit.Webhooks/Models/InstallationRepositorySelection.cs index 640b0194..e53039a9 100644 --- a/src/Octokit.Webhooks/Models/InstallationRepositorySelection.cs +++ b/src/Octokit.Webhooks/Models/InstallationRepositorySelection.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum InstallationRepositorySelection { - Unknown = -1, [EnumMember(Value = "all")] All, [EnumMember(Value = "selected")] diff --git a/src/Octokit.Webhooks/Models/InstallationTargetType.cs b/src/Octokit.Webhooks/Models/InstallationTargetType.cs index ccd43888..670160ee 100644 --- a/src/Octokit.Webhooks/Models/InstallationTargetType.cs +++ b/src/Octokit.Webhooks/Models/InstallationTargetType.cs @@ -1,10 +1,8 @@ namespace Octokit.Webhooks.Models; [PublicAPI] -[JsonConverter(typeof(JsonStringEnumMemberConverterWithFallback))] public enum InstallationTargetType { - Unknown = -1, [EnumMember(Value = "User")] User, [EnumMember(Value = "Organization")] diff --git a/src/Octokit.Webhooks/Models/Issue.cs b/src/Octokit.Webhooks/Models/Issue.cs index 6edba2e9..1ce40ccf 100644 --- a/src/Octokit.Webhooks/Models/Issue.cs +++ b/src/Octokit.Webhooks/Models/Issue.cs @@ -40,7 +40,8 @@ public sealed record Issue public IEnumerable