Skip to content

Commit

Permalink
Libs(CSharp): fixup manual edits to -Patch models
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
svix-onelson committed Oct 11, 2024
1 parent 2efc3d0 commit f5c2bdd
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 270 deletions.
4 changes: 4 additions & 0 deletions csharp/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
92 changes: 16 additions & 76 deletions csharp/Svix/Generated/OpenApi/Svix/Model/ApplicationPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Svix.Model
/// ApplicationPatch
/// </summary>
[DataContract(Name = "ApplicationPatch")]
public partial class ApplicationPatch : IEquatable<ApplicationPatch>, IValidatableObject
public partial class ApplicationPatch : IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationPatch" /> class.
Expand Down Expand Up @@ -71,6 +71,9 @@ public partial class ApplicationPatch : IEquatable<ApplicationPatch>, IValidatab
/// The app&#39;s UID
/// </summary>
/// <value>The app&#39;s UID</value>
/*
<example>unique-app-identifier</example>
*/
[DataMember(Name = "uid", EmitDefaultValue = false)]
public string Uid { get; set; }

Expand All @@ -80,7 +83,7 @@ public partial class ApplicationPatch : IEquatable<ApplicationPatch>, IValidatab
/// <returns>String presentation of the object</returns>
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");
Expand All @@ -99,101 +102,38 @@ public virtual string ToJson()
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input)
{
return this.Equals(input as ApplicationPatch);
}

/// <summary>
/// Returns true if ApplicationPatch instances are equal
/// </summary>
/// <param name="input">Instance of ApplicationPatch to be compared</param>
/// <returns>Boolean</returns>
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))
);
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
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;
}
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
IEnumerable<ValidationResult> 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;
Expand Down
153 changes: 31 additions & 122 deletions csharp/Svix/Generated/OpenApi/Svix/Model/EndpointPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace Svix.Model
/// EndpointPatch
/// </summary>
[DataContract(Name = "EndpointPatch")]
public partial class EndpointPatch : IEquatable<EndpointPatch>, IValidatableObject
public partial class EndpointPatch : IValidatableObject
{
/// <summary>
/// Initializes a new instance of the <see cref="EndpointPatch" /> class.
Expand Down Expand Up @@ -101,13 +101,19 @@ public partial class EndpointPatch : IEquatable<EndpointPatch>, IValidatableObje
/// The endpoint&#39;s verification secret. If &#x60;null&#x60; is passed, a secret is automatically generated. Format: &#x60;base64&#x60; encoded random bytes optionally prefixed with &#x60;whsec_&#x60;. Recommended size: 24.
/// </summary>
/// <value>The endpoint&#39;s verification secret. If &#x60;null&#x60; is passed, a secret is automatically generated. Format: &#x60;base64&#x60; encoded random bytes optionally prefixed with &#x60;whsec_&#x60;. Recommended size: 24.</value>
/*
<example>whsec_C2FVsBQIhrscChlQIMV+b5sSYspob7oD</example>
*/
[DataMember(Name = "secret", EmitDefaultValue = false)]
public string Secret { get; set; }

/// <summary>
/// The ep&#39;s UID
/// </summary>
/// <value>The ep&#39;s UID</value>
/*
<example>unique-ep-identifier</example>
*/
[DataMember(Name = "uid", EmitDefaultValue = false)]
public string Uid { get; set; }

Expand All @@ -120,7 +126,11 @@ public partial class EndpointPatch : IEquatable<EndpointPatch>, IValidatableObje
/// <summary>
/// Gets or Sets Version
/// </summary>
/*
<example>1</example>
*/
[DataMember(Name = "version", EmitDefaultValue = false)]
[Obsolete]
public int Version { get; set; }

/// <summary>
Expand All @@ -129,7 +139,7 @@ public partial class EndpointPatch : IEquatable<EndpointPatch>, IValidatableObje
/// <returns>String presentation of the object</returns>
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");
Expand All @@ -154,154 +164,53 @@ public virtual string ToJson()
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input)
{
return this.Equals(input as EndpointPatch);
}

/// <summary>
/// Returns true if EndpointPatch instances are equal
/// </summary>
/// <param name="input">Instance of EndpointPatch to be compared</param>
/// <returns>Boolean</returns>
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)
);
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
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;
}
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
IEnumerable<ValidationResult> 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;
Expand Down
Loading

0 comments on commit f5c2bdd

Please sign in to comment.