From f5c2bdd7c84a7382fbb24b979f70d891921564dc Mon Sep 17 00:00:00 2001 From: Owen Nelson Date: Fri, 11 Oct 2024 14:37:18 -0700 Subject: [PATCH] Libs(CSharp): fixup manual edits to -Patch models We had some ignore patterns in place for a subset of -Patch models so they weren't updated along with the rest of the models after the generator was updated to 7.x. For this diff I commented out the ignores, re-ran codegen, uncommented the ignores again, then carefully restored the local edits. Mostly the changes here are to set `EmitDefaultValue = false` for everything. This should prevent model instances from supplying the default when a given field isn't set (basically the same as `"omitempty"` on the Go side or `skip_serializing_if = "Option::is_none"` in rust). Looks like the generator will automatically assume this option should be true for any container type, but does the thing we want (leave it false) for scalars. --- csharp/.openapi-generator-ignore | 4 + .../OpenApi/Svix/Model/ApplicationPatch.cs | 92 ++--------- .../OpenApi/Svix/Model/EndpointPatch.cs | 153 ++++-------------- .../OpenApi/Svix/Model/EventTypePatch.cs | 126 +++++++-------- 4 files changed, 105 insertions(+), 270 deletions(-) diff --git a/csharp/.openapi-generator-ignore b/csharp/.openapi-generator-ignore index 078f20243..09b23e6fa 100644 --- a/csharp/.openapi-generator-ignore +++ b/csharp/.openapi-generator-ignore @@ -37,6 +37,10 @@ Svix.sln docs/ src/ +# When bumping generator versions: +# - Comment these out to "re-up" the generator source. +# - Roll back any of our local changes that got wiped out in the process. +# - Uncomment them again to prevent the generator from wiping out the manual edits. Svix/Generated/OpenApi/Svix/Model/ApplicationPatch.cs Svix/Generated/OpenApi/Svix/Model/EndpointPatch.cs Svix/Generated/OpenApi/Svix/Model/EventTypePatch.cs diff --git a/csharp/Svix/Generated/OpenApi/Svix/Model/ApplicationPatch.cs b/csharp/Svix/Generated/OpenApi/Svix/Model/ApplicationPatch.cs index 8c6517d05..dfa89a2f4 100644 --- a/csharp/Svix/Generated/OpenApi/Svix/Model/ApplicationPatch.cs +++ b/csharp/Svix/Generated/OpenApi/Svix/Model/ApplicationPatch.cs @@ -32,7 +32,7 @@ namespace Svix.Model /// ApplicationPatch /// [DataContract(Name = "ApplicationPatch")] - public partial class ApplicationPatch : IEquatable, IValidatableObject + public partial class ApplicationPatch : IValidatableObject { /// /// Initializes a new instance of the class. @@ -71,6 +71,9 @@ public partial class ApplicationPatch : IEquatable, IValidatab /// The app's UID /// /// The app's UID + /* + unique-app-identifier + */ [DataMember(Name = "uid", EmitDefaultValue = false)] public string Uid { get; set; } @@ -80,7 +83,7 @@ public partial class ApplicationPatch : IEquatable, IValidatab /// String presentation of the object public override string ToString() { - var sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.Append("class ApplicationPatch {\n"); sb.Append(" Metadata: ").Append(Metadata).Append("\n"); sb.Append(" Name: ").Append(Name).Append("\n"); @@ -99,101 +102,38 @@ public virtual string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); } - /// - /// Returns true if objects are equal - /// - /// Object to be compared - /// Boolean - public override bool Equals(object input) - { - return this.Equals(input as ApplicationPatch); - } - - /// - /// Returns true if ApplicationPatch instances are equal - /// - /// Instance of ApplicationPatch to be compared - /// Boolean - public bool Equals(ApplicationPatch input) - { - if (input == null) - return false; - - return - ( - this.Metadata == input.Metadata || - this.Metadata != null && - input.Metadata != null && - this.Metadata.SequenceEqual(input.Metadata) - ) && - ( - this.Name == input.Name || - (this.Name != null && - this.Name.Equals(input.Name)) - ) && - ( - this.RateLimit == input.RateLimit || - (this.RateLimit != null && - this.RateLimit.Equals(input.RateLimit)) - ) && - ( - this.Uid == input.Uid || - (this.Uid != null && - this.Uid.Equals(input.Uid)) - ); - } - - /// - /// Gets the hash code - /// - /// Hash code - public override int GetHashCode() - { - unchecked // Overflow is fine, just wrap - { - int hashCode = 41; - if (this.Metadata != null) - hashCode = hashCode * 59 + this.Metadata.GetHashCode(); - if (this.Name != null) - hashCode = hashCode * 59 + this.Name.GetHashCode(); - if (this.RateLimit != null) - hashCode = hashCode * 59 + this.RateLimit.GetHashCode(); - if (this.Uid != null) - hashCode = hashCode * 59 + this.Uid.GetHashCode(); - return hashCode; - } - } - /// /// To validate all properties of the instance /// /// Validation context /// Validation Result - IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) { // RateLimit (int?) minimum if (this.RateLimit < (int?)0) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for RateLimit, must be a value greater than or equal to 0.", new[] { "RateLimit" }); + yield return new ValidationResult("Invalid value for RateLimit, must be a value greater than or equal to 0.", new [] { "RateLimit" }); } // Uid (string) maxLength if (this.Uid != null && this.Uid.Length > 256) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Uid, length must be less than 256.", new[] { "Uid" }); + yield return new ValidationResult("Invalid value for Uid, length must be less than 256.", new [] { "Uid" }); } // Uid (string) minLength if (this.Uid != null && this.Uid.Length < 1) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Uid, length must be greater than 1.", new[] { "Uid" }); + yield return new ValidationResult("Invalid value for Uid, length must be greater than 1.", new [] { "Uid" }); } - // Uid (string) pattern - Regex regexUid = new Regex(@"^[a-zA-Z0-9\\-_.]+$", RegexOptions.CultureInvariant); - if (false == regexUid.Match(this.Uid).Success) - { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Uid, must match a pattern of " + regexUid, new[] { "Uid" }); + if (this.Uid != null) { + // Uid (string) pattern + Regex regexUid = new Regex(@"^[a-zA-Z0-9\-_.]+$", RegexOptions.CultureInvariant); + if (!regexUid.Match(this.Uid).Success) + { + yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Uid, must match a pattern of " + regexUid, new [] { "Uid" }); + } } yield break; diff --git a/csharp/Svix/Generated/OpenApi/Svix/Model/EndpointPatch.cs b/csharp/Svix/Generated/OpenApi/Svix/Model/EndpointPatch.cs index 5396f4a08..7f8b481dd 100644 --- a/csharp/Svix/Generated/OpenApi/Svix/Model/EndpointPatch.cs +++ b/csharp/Svix/Generated/OpenApi/Svix/Model/EndpointPatch.cs @@ -32,7 +32,7 @@ namespace Svix.Model /// EndpointPatch /// [DataContract(Name = "EndpointPatch")] - public partial class EndpointPatch : IEquatable, IValidatableObject + public partial class EndpointPatch : IValidatableObject { /// /// Initializes a new instance of the class. @@ -101,6 +101,9 @@ public partial class EndpointPatch : IEquatable, IValidatableObje /// The endpoint's verification secret. If `null` is passed, a secret is automatically generated. Format: `base64` encoded random bytes optionally prefixed with `whsec_`. Recommended size: 24. /// /// The endpoint's verification secret. If `null` is passed, a secret is automatically generated. Format: `base64` encoded random bytes optionally prefixed with `whsec_`. Recommended size: 24. + /* + whsec_C2FVsBQIhrscChlQIMV+b5sSYspob7oD + */ [DataMember(Name = "secret", EmitDefaultValue = false)] public string Secret { get; set; } @@ -108,6 +111,9 @@ public partial class EndpointPatch : IEquatable, IValidatableObje /// The ep's UID /// /// The ep's UID + /* + unique-ep-identifier + */ [DataMember(Name = "uid", EmitDefaultValue = false)] public string Uid { get; set; } @@ -120,7 +126,11 @@ public partial class EndpointPatch : IEquatable, IValidatableObje /// /// Gets or Sets Version /// + /* + 1 + */ [DataMember(Name = "version", EmitDefaultValue = false)] + [Obsolete] public int Version { get; set; } /// @@ -129,7 +139,7 @@ public partial class EndpointPatch : IEquatable, IValidatableObje /// String presentation of the object public override string ToString() { - var sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.Append("class EndpointPatch {\n"); sb.Append(" Channels: ").Append(Channels).Append("\n"); sb.Append(" Description: ").Append(Description).Append("\n"); @@ -154,154 +164,53 @@ public virtual string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); } - /// - /// Returns true if objects are equal - /// - /// Object to be compared - /// Boolean - public override bool Equals(object input) - { - return this.Equals(input as EndpointPatch); - } - - /// - /// Returns true if EndpointPatch instances are equal - /// - /// Instance of EndpointPatch to be compared - /// Boolean - public bool Equals(EndpointPatch input) - { - if (input == null) - return false; - - return - ( - this.Channels == input.Channels || - this.Channels != null && - input.Channels != null && - this.Channels.SequenceEqual(input.Channels) - ) && - ( - this.Description == input.Description || - (this.Description != null && - this.Description.Equals(input.Description)) - ) && - ( - this.Disabled == input.Disabled || - this.Disabled.Equals(input.Disabled) - ) && - ( - this.FilterTypes == input.FilterTypes || - this.FilterTypes != null && - input.FilterTypes != null && - this.FilterTypes.SequenceEqual(input.FilterTypes) - ) && - ( - this.Metadata == input.Metadata || - this.Metadata != null && - input.Metadata != null && - this.Metadata.SequenceEqual(input.Metadata) - ) && - ( - this.RateLimit == input.RateLimit || - (this.RateLimit != null && - this.RateLimit.Equals(input.RateLimit)) - ) && - ( - this.Secret == input.Secret || - (this.Secret != null && - this.Secret.Equals(input.Secret)) - ) && - ( - this.Uid == input.Uid || - (this.Uid != null && - this.Uid.Equals(input.Uid)) - ) && - ( - this.Url == input.Url || - (this.Url != null && - this.Url.Equals(input.Url)) - ) && - ( - this.Version == input.Version || - this.Version.Equals(input.Version) - ); - } - - /// - /// Gets the hash code - /// - /// Hash code - public override int GetHashCode() - { - unchecked // Overflow is fine, just wrap - { - int hashCode = 41; - if (this.Channels != null) - hashCode = hashCode * 59 + this.Channels.GetHashCode(); - if (this.Description != null) - hashCode = hashCode * 59 + this.Description.GetHashCode(); - hashCode = hashCode * 59 + this.Disabled.GetHashCode(); - if (this.FilterTypes != null) - hashCode = hashCode * 59 + this.FilterTypes.GetHashCode(); - if (this.Metadata != null) - hashCode = hashCode * 59 + this.Metadata.GetHashCode(); - if (this.RateLimit != null) - hashCode = hashCode * 59 + this.RateLimit.GetHashCode(); - if (this.Secret != null) - hashCode = hashCode * 59 + this.Secret.GetHashCode(); - if (this.Uid != null) - hashCode = hashCode * 59 + this.Uid.GetHashCode(); - if (this.Url != null) - hashCode = hashCode * 59 + this.Url.GetHashCode(); - hashCode = hashCode * 59 + this.Version.GetHashCode(); - return hashCode; - } - } - /// /// To validate all properties of the instance /// /// Validation context /// Validation Result - IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) { // RateLimit (int?) minimum if (this.RateLimit < (int?)0) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for RateLimit, must be a value greater than or equal to 0.", new[] { "RateLimit" }); + yield return new ValidationResult("Invalid value for RateLimit, must be a value greater than or equal to 0.", new [] { "RateLimit" }); } - // Secret (string) pattern - Regex regexSecret = new Regex(@"^(whsec_)?[a-zA-Z0-9+\/=]{32,100}$", RegexOptions.CultureInvariant); - if (false == regexSecret.Match(this.Secret).Success) - { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Secret, must match a pattern of " + regexSecret, new[] { "Secret" }); + if (this.Secret != null) { + // Secret (string) pattern + Regex regexSecret = new Regex(@"^(whsec_)?[a-zA-Z0-9+/=]{32,100}$", RegexOptions.CultureInvariant); + if (!regexSecret.Match(this.Secret).Success) + { + yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Secret, must match a pattern of " + regexSecret, new [] { "Secret" }); + } } // Uid (string) maxLength if (this.Uid != null && this.Uid.Length > 256) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Uid, length must be less than 256.", new[] { "Uid" }); + yield return new ValidationResult("Invalid value for Uid, length must be less than 256.", new [] { "Uid" }); } // Uid (string) minLength if (this.Uid != null && this.Uid.Length < 1) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Uid, length must be greater than 1.", new[] { "Uid" }); + yield return new ValidationResult("Invalid value for Uid, length must be greater than 1.", new [] { "Uid" }); } - // Uid (string) pattern - Regex regexUid = new Regex(@"^[a-zA-Z0-9\\-_.]+$", RegexOptions.CultureInvariant); - if (false == regexUid.Match(this.Uid).Success) - { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Uid, must match a pattern of " + regexUid, new[] { "Uid" }); + if (this.Uid != null) { + // Uid (string) pattern + Regex regexUid = new Regex(@"^[a-zA-Z0-9\-_.]+$", RegexOptions.CultureInvariant); + if (!regexUid.Match(this.Uid).Success) + { + yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Uid, must match a pattern of " + regexUid, new [] { "Uid" }); + } } // Version (int) minimum if (this.Version < (int)1) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for Version, must be a value greater than or equal to 1.", new[] { "Version" }); + yield return new ValidationResult("Invalid value for Version, must be a value greater than or equal to 1.", new [] { "Version" }); } yield break; diff --git a/csharp/Svix/Generated/OpenApi/Svix/Model/EventTypePatch.cs b/csharp/Svix/Generated/OpenApi/Svix/Model/EventTypePatch.cs index 285f7cfa4..3a40d30ed 100644 --- a/csharp/Svix/Generated/OpenApi/Svix/Model/EventTypePatch.cs +++ b/csharp/Svix/Generated/OpenApi/Svix/Model/EventTypePatch.cs @@ -32,20 +32,24 @@ namespace Svix.Model /// EventTypePatch /// [DataContract(Name = "EventTypePatch")] - public partial class EventTypePatch : IEquatable, IValidatableObject + public partial class EventTypePatch : IValidatableObject { /// /// Initializes a new instance of the class. /// /// archived. + /// deprecated. /// description. /// featureFlag. + /// The event type group's name. /// schemas. - public EventTypePatch(bool archived = default(bool), string description = default(string), string featureFlag = default(string), Dictionary schemas = default(Dictionary)) + public EventTypePatch(bool archived = default(bool), bool deprecated = default(bool), string description = default(string), string featureFlag = default(string), string groupName = default(string), Dictionary schemas = default(Dictionary)) { this.Archived = archived; + this.Deprecated = deprecated; this.Description = description; this.FeatureFlag = featureFlag; + this.GroupName = groupName; this.Schemas = schemas; } @@ -55,6 +59,12 @@ public partial class EventTypePatch : IEquatable, IValidatableOb [DataMember(Name = "archived", EmitDefaultValue = false)] public bool Archived { get; set; } + /// + /// Gets or Sets Deprecated + /// + [DataMember(Name = "deprecated", EmitDefaultValue = false)] + public bool Deprecated { get; set; } + /// /// Gets or Sets Description /// @@ -64,12 +74,28 @@ public partial class EventTypePatch : IEquatable, IValidatableOb /// /// Gets or Sets FeatureFlag /// + /* + cool-new-feature + */ [DataMember(Name = "featureFlag", EmitDefaultValue = false)] public string FeatureFlag { get; set; } + /// + /// The event type group's name + /// + /// The event type group's name + /* + user + */ + [DataMember(Name = "groupName", EmitDefaultValue = false)] + public string GroupName { get; set; } + /// /// Gets or Sets Schemas /// + /* + {"description":"An invoice was paid by a user","properties":{"invoiceId":{"description":"The invoice id","type":"string"},"userId":{"description":"The user id","type":"string"}},"required":["invoiceId","userId"],"title":"Invoice Paid Event","type":"object"} + */ [DataMember(Name = "schemas", EmitDefaultValue = false)] public Dictionary Schemas { get; set; } @@ -79,11 +105,13 @@ public partial class EventTypePatch : IEquatable, IValidatableOb /// String presentation of the object public override string ToString() { - var sb = new StringBuilder(); + StringBuilder sb = new StringBuilder(); sb.Append("class EventTypePatch {\n"); sb.Append(" Archived: ").Append(Archived).Append("\n"); + sb.Append(" Deprecated: ").Append(Deprecated).Append("\n"); sb.Append(" Description: ").Append(Description).Append("\n"); sb.Append(" FeatureFlag: ").Append(FeatureFlag).Append("\n"); + sb.Append(" GroupName: ").Append(GroupName).Append("\n"); sb.Append(" Schemas: ").Append(Schemas).Append("\n"); sb.Append("}\n"); return sb.ToString(); @@ -98,87 +126,41 @@ public virtual string ToJson() return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented); } - /// - /// Returns true if objects are equal - /// - /// Object to be compared - /// Boolean - public override bool Equals(object input) - { - return this.Equals(input as EventTypePatch); - } - - /// - /// Returns true if EventTypePatch instances are equal - /// - /// Instance of EventTypePatch to be compared - /// Boolean - public bool Equals(EventTypePatch input) - { - if (input == null) - return false; - - return - ( - this.Archived == input.Archived || - this.Archived.Equals(input.Archived) - ) && - ( - this.Description == input.Description || - (this.Description != null && - this.Description.Equals(input.Description)) - ) && - ( - this.FeatureFlag == input.FeatureFlag || - (this.FeatureFlag != null && - this.FeatureFlag.Equals(input.FeatureFlag)) - ) && - ( - this.Schemas == input.Schemas || - this.Schemas != null && - input.Schemas != null && - this.Schemas.SequenceEqual(input.Schemas) - ); - } - - /// - /// Gets the hash code - /// - /// Hash code - public override int GetHashCode() - { - unchecked // Overflow is fine, just wrap - { - int hashCode = 41; - hashCode = hashCode * 59 + this.Archived.GetHashCode(); - if (this.Description != null) - hashCode = hashCode * 59 + this.Description.GetHashCode(); - if (this.FeatureFlag != null) - hashCode = hashCode * 59 + this.FeatureFlag.GetHashCode(); - if (this.Schemas != null) - hashCode = hashCode * 59 + this.Schemas.GetHashCode(); - return hashCode; - } - } - /// /// To validate all properties of the instance /// /// Validation context /// Validation Result - IEnumerable IValidatableObject.Validate(ValidationContext validationContext) + IEnumerable IValidatableObject.Validate(ValidationContext validationContext) { // FeatureFlag (string) maxLength if (this.FeatureFlag != null && this.FeatureFlag.Length > 256) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for FeatureFlag, length must be less than 256.", new[] { "FeatureFlag" }); + yield return new ValidationResult("Invalid value for FeatureFlag, length must be less than 256.", new [] { "FeatureFlag" }); + } + + if (this.FeatureFlag != null) { + // FeatureFlag (string) pattern + Regex regexFeatureFlag = new Regex(@"^[a-zA-Z0-9\-_.]+$", RegexOptions.CultureInvariant); + if (!regexFeatureFlag.Match(this.FeatureFlag).Success) + { + yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for FeatureFlag, must match a pattern of " + regexFeatureFlag, new [] { "FeatureFlag" }); + } } - // FeatureFlag (string) pattern - Regex regexFeatureFlag = new Regex(@"^[a-zA-Z0-9\\-_.]+$", RegexOptions.CultureInvariant); - if (false == regexFeatureFlag.Match(this.FeatureFlag).Success) + // GroupName (string) maxLength + if (this.GroupName != null && this.GroupName.Length > 256) { - yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for FeatureFlag, must match a pattern of " + regexFeatureFlag, new[] { "FeatureFlag" }); + yield return new ValidationResult("Invalid value for GroupName, length must be less than 256.", new [] { "GroupName" }); + } + + if (this.GroupName != null) { + // GroupName (string) pattern + Regex regexGroupName = new Regex(@"^[a-zA-Z0-9\-_.]+$", RegexOptions.CultureInvariant); + if (!regexGroupName.Match(this.GroupName).Success) + { + yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for GroupName, must match a pattern of " + regexGroupName, new [] { "GroupName" }); + } } yield break;