Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate JetStream models with NJsonSchema #90

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions NATS.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NATS.Client.JetStream.Tests
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NATS.Client.TestUtilities", "tests\NATS.Client.TestUtilities\NATS.Client.TestUtilities.csproj", "{90E5BF38-70C1-460A-9177-CE42815BDBF5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{BD234E2E-F51A-4B18-B8BE-8AF6D546BF87}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Schema.Generation", "tools\Schema.Generation\Schema.Generation.csproj", "{B7DD4A9C-2D24-4772-951E-86A665C59ADF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -145,6 +149,10 @@ Global
{90E5BF38-70C1-460A-9177-CE42815BDBF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90E5BF38-70C1-460A-9177-CE42815BDBF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90E5BF38-70C1-460A-9177-CE42815BDBF5}.Release|Any CPU.Build.0 = Release|Any CPU
{B7DD4A9C-2D24-4772-951E-86A665C59ADF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7DD4A9C-2D24-4772-951E-86A665C59ADF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7DD4A9C-2D24-4772-951E-86A665C59ADF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7DD4A9C-2D24-4772-951E-86A665C59ADF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -171,6 +179,7 @@ Global
{56A9B885-6B7E-4BC6-AED0-ADC67C9A68DB} = {4827B3EC-73D8-436D-AE2A-5E29AC95FD0C}
{2D39F649-C512-4EE5-9DFA-7BD4D9E4F145} = {C526E8AB-739A-48D7-8FC4-048978C9B650}
{90E5BF38-70C1-460A-9177-CE42815BDBF5} = {C526E8AB-739A-48D7-8FC4-048978C9B650}
{B7DD4A9C-2D24-4772-951E-86A665C59ADF} = {BD234E2E-F51A-4B18-B8BE-8AF6D546BF87}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8CBB7278-D093-448E-B3DE-B5991209A1AA}
Expand Down
4 changes: 2 additions & 2 deletions src/NATS.Client.JetStream/JSContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public record JSOptions

public class JSStream
{
public StreamCreateResponse Response { get; }

public JSStream(StreamCreateResponse response)
{
Response = response;
}

public StreamCreateResponse Response { get; }
}
9 changes: 9 additions & 0 deletions src/NATS.Client.JetStream/Models/AccountInfoResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NATS.Client.JetStream.Models;

/// <summary>
/// A response from the JetStream $JS.API.INFO API
/// </summary>

public record AccountInfoResponse : AccountStats
{
}
85 changes: 54 additions & 31 deletions src/NATS.Client.JetStream/Models/AccountLimits.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,66 @@
// Copyright 2023 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Text.Json.Serialization;

namespace NATS.Client.JetStream.Models;

public record AccountLimits
{
[JsonPropertyName("max_memory")]
public long MaxMemory { get; set; }
/// <summary>
/// The maximum amount of Memory storage Stream Messages may consume
/// </summary>
[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!;

[JsonPropertyName("max_storage")]
public long MaxStorage { 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!;

[JsonPropertyName("max_streams")]
public long MaxStreams { 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!;

[JsonPropertyName("max_consumers")]
public long MaxConsumers { 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!;

[JsonPropertyName("max_ack_pending")]
public long MaxAckPending { 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;

[JsonPropertyName("memory_max_stream_bytes")]
public long MemoryMaxStreamBytes { 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!;

[JsonPropertyName("storage_max_stream_bytes")]
public long StorageMaxStreamBytes { get; set; }
/// <summary>
/// The maximum size any single memory stream may be
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("memory_max_stream_bytes")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)]
public int MemoryMaxStreamBytes { get; set; } = -1;

[JsonPropertyName("max_bytes_required")]
public bool MaxBytesRequired { get; set; }
/// <summary>
/// The maximum size any single storage based stream may be
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("storage_max_stream_bytes")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)]
public int StorageMaxStreamBytes { get; set; } = -1;
}
15 changes: 15 additions & 0 deletions src/NATS.Client.JetStream/Models/AccountPurgeResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace NATS.Client.JetStream.Models;

/// <summary>
/// A response from the JetStream $JS.API.ACCOUNT.PURGE API
/// </summary>

public record AccountPurgeResponse
{
/// <summary>
/// If the purge operation was succesfully 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;
}
28 changes: 0 additions & 28 deletions src/NATS.Client.JetStream/Models/AccountStatistics.cs

This file was deleted.

57 changes: 57 additions & 0 deletions src/NATS.Client.JetStream/Models/AccountStats.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace NATS.Client.JetStream.Models;

public record AccountStats
{
/// <summary>
/// Memory Storage being used for Stream Message storage
/// </summary>
[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!;

/// <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!;

/// <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!;

/// <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!;

/// <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!;

[System.Text.Json.Serialization.JsonPropertyName("limits")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Required]
public AccountLimits Limits { get; set; } = new AccountLimits();

[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!;

[System.Text.Json.Serialization.JsonPropertyName("api")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)]
[System.ComponentModel.DataAnnotations.Required]
public ApiStats Api { get; set; } = new ApiStats();
}
34 changes: 0 additions & 34 deletions src/NATS.Client.JetStream/Models/AccountTier.cs

This file was deleted.

27 changes: 27 additions & 0 deletions src/NATS.Client.JetStream/Models/ApiError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace NATS.Client.JetStream.Models;

public record ApiError
{
/// <summary>
/// HTTP like error code in the 300 to 500 range
/// </summary>
[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!;

/// <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!;

/// <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!;
}
25 changes: 0 additions & 25 deletions src/NATS.Client.JetStream/Models/ApiResponse.cs

This file was deleted.

33 changes: 14 additions & 19 deletions src/NATS.Client.JetStream/Models/ApiStats.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
// Copyright 2023 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Text.Json.Serialization;

namespace NATS.Client.JetStream.Models;

public record ApiStats
{
[JsonPropertyName("total")]
public long Total { get; set; }
/// <summary>
/// Total number of API requests received for this account
/// </summary>
[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!;

[JsonPropertyName("errors")]
public long Errors { 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!;
}
9 changes: 0 additions & 9 deletions src/NATS.Client.JetStream/Models/Cluster.cs

This file was deleted.

Loading
Loading