Skip to content

Commit

Permalink
Nullability review for models (#332)
Browse files Browse the repository at this point in the history
* Nullability review for models. Mark required properties (derived from attribute annotations and code inspection) and avoid assigning default values to required props.
Excluded SC1206 warnings (couldn't manage to use the required keywork with it enabled).

* Correct invalid uses of ThrowIfNull helper
  • Loading branch information
mnmr authored Jan 14, 2024
1 parent dc6301f commit b47095a
Show file tree
Hide file tree
Showing 72 changed files with 357 additions and 240 deletions.
24 changes: 12 additions & 12 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ dotnet_diagnostic.SA1202.severity = warning # Elements should be ordered by acc
dotnet_diagnostic.SA1203.severity = warning # Constants should appear before fields
dotnet_diagnostic.SA1204.severity = warning # Static elements should appear before instance elements
dotnet_diagnostic.SA1205.severity = warning # Partial elements should declare access
dotnet_diagnostic.SA1206.severity = warning # Declaration keywords should follow order
dotnet_diagnostic.SA1206.severity = none # Declaration keywords should follow order
dotnet_diagnostic.SA1207.severity = warning # Protected should come before internal
dotnet_diagnostic.SA1208.severity = warning # System using directives should be placed before other using directives
dotnet_diagnostic.SA1209.severity = warning # Using alias directives should be placed after other using directives
Expand Down Expand Up @@ -311,31 +311,31 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case
dotnet_style_coalesce_expression = true:warning
dotnet_style_null_propagation = true:suggestion
Expand Down
12 changes: 6 additions & 6 deletions src/NATS.Client.JetStream/Models/AccountLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,45 @@ public record AccountLimits
[System.Text.Json.Serialization.JsonPropertyName("max_memory")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)]
public int MaxMemory { get; set; } = default!;
public int MaxMemory { get; set; }

/// <summary>
/// The maximum amount of File storage Stream Messages may consume
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("max_storage")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)]
public int MaxStorage { get; set; } = default!;
public int MaxStorage { get; set; }

/// <summary>
/// The maximum number of Streams an account can create
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("max_streams")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)]
public int MaxStreams { get; set; } = default!;
public int MaxStreams { get; set; }

/// <summary>
/// The maximum number of Consumer an account can create
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("max_consumers")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)]
public int MaxConsumers { get; set; } = default!;
public int MaxConsumers { get; set; }

/// <summary>
/// Indicates if Streams created in this account requires the max_bytes property set
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("max_bytes_required")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public bool MaxBytesRequired { get; set; } = false;
public bool MaxBytesRequired { get; set; }

/// <summary>
/// The maximum number of outstanding ACKs any consumer may configure
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("max_ack_pending")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public int MaxAckPending { get; set; } = default!;
public int MaxAckPending { get; set; }

/// <summary>
/// The maximum size any single memory stream may be
Expand Down
4 changes: 2 additions & 2 deletions src/NATS.Client.JetStream/Models/AccountPurgeResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace NATS.Client.JetStream.Models;
public record AccountPurgeResponse
{
/// <summary>
/// If the purge operation was succesfully started
/// If the purge operation was successfully started
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("initiated")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public bool Initiated { get; set; } = false;
public bool Initiated { get; set; }
}
12 changes: 6 additions & 6 deletions src/NATS.Client.JetStream/Models/AccountStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,38 @@ public record AccountStats
[System.Text.Json.Serialization.JsonPropertyName("memory")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)]
public int Memory { get; set; } = default!;
public int Memory { get; set; }

/// <summary>
/// File Storage being used for Stream Message storage
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("storage")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)]
public int Storage { get; set; } = default!;
public int Storage { get; set; }

/// <summary>
/// Number of active Streams
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("streams")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)]
public int Streams { get; set; } = default!;
public int Streams { get; set; }

/// <summary>
/// Number of active Consumers
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("consumers")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)]
public int Consumers { get; set; } = default!;
public int Consumers { get; set; }

/// <summary>
/// The JetStream domain this account is in
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("domain")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public string Domain { get; set; } = default!;
public string? Domain { get; set; }

[System.Text.Json.Serialization.JsonPropertyName("limits")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
Expand All @@ -48,7 +48,7 @@ public record AccountStats

[System.Text.Json.Serialization.JsonPropertyName("tiers")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public System.Collections.Generic.IDictionary<string, object> Tiers { get; set; } = default!;
public IDictionary<string, object>? Tiers { get; set; }

[System.Text.Json.Serialization.JsonPropertyName("api")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
Expand Down
6 changes: 3 additions & 3 deletions src/NATS.Client.JetStream/Models/ApiError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ public record ApiError
[System.Text.Json.Serialization.JsonPropertyName("code")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(300, 699)]
public int Code { get; set; } = default!;
public int Code { get; set; }

/// <summary>
/// A human friendly description of the error
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("description")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public string Description { get; set; } = default!;
public string? Description { get; set; }

/// <summary>
/// The NATS error code unique to each kind of error
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("err_code")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
[System.ComponentModel.DataAnnotations.Range(0, 65535)]
public int ErrCode { get; set; } = default!;
public int ErrCode { get; set; }
}
4 changes: 2 additions & 2 deletions src/NATS.Client.JetStream/Models/ApiStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ public record ApiStats
[System.Text.Json.Serialization.JsonPropertyName("total")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)]
public int Total { get; set; } = default!;
public int Total { get; set; }

/// <summary>
/// API requests that resulted in an error response
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("errors")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Range(0, int.MaxValue)]
public int Errors { get; set; } = default!;
public int Errors { get; set; }
}
6 changes: 3 additions & 3 deletions src/NATS.Client.JetStream/Models/ClusterInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ public record ClusterInfo
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("name")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public string Name { get; set; } = default!;
public string? Name { get; set; }

/// <summary>
/// The server name of the RAFT leader
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("leader")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public string Leader { get; set; } = default!;
public string? Leader { get; set; }

/// <summary>
/// The members of the RAFT cluster
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("replicas")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public System.Collections.Generic.ICollection<PeerInfo> Replicas { get; set; } = default!;
public ICollection<PeerInfo>? Replicas { get; set; }
}
Loading

0 comments on commit b47095a

Please sign in to comment.