Skip to content

Commit

Permalink
Remove schema from Service API (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored May 19, 2023
1 parent 25b976a commit 5fbf641
Show file tree
Hide file tree
Showing 11 changed files with 11 additions and 449 deletions.
18 changes: 0 additions & 18 deletions src/NATS.Client/Service/Discovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,6 @@ public InfoResponse InfoForNameAndId(string serviceName, string serviceId) {
return json == null ? null : new InfoResponse(json);
}

// ----------------------------------------------------------------------------------------------------
// schema
// ----------------------------------------------------------------------------------------------------
public IList<SchemaResponse> Schema(string serviceName = null)
{
IList<SchemaResponse> list = new List<SchemaResponse>();
DiscoverMany(Service.SrvSchema, serviceName, json => {
list.Add(new SchemaResponse(json));
});
return list;
}

public SchemaResponse SchemaForNameAndId(string serviceName, string serviceId)
{
string json = DiscoverOne(Service.SrvSchema, serviceName, serviceId);
return json == null ? null : new SchemaResponse(json);
}

// ----------------------------------------------------------------------------------------------------
// stats
// ----------------------------------------------------------------------------------------------------
Expand Down
53 changes: 6 additions & 47 deletions src/NATS.Client/Service/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ public class Endpoint : JsonSerializable
{
public string Name { get; }
public string Subject { get; }
public Schema Schema { get; }
public Dictionary<string, string> Metadata { get; }

public Endpoint(string name, string subject, Schema schema) : this(name, subject, schema, null, true) {}
public Endpoint(string name) : this(name, null, null, true) {}

public Endpoint(string name) : this(name, null, null, null, true) {}

public Endpoint(string name, string subject) : this(name, subject, null, null, true) {}

public Endpoint(string name, string subject, string schemaRequest, string schemaResponse)
: this(name, subject, Schema.OptionalInstance(schemaRequest, schemaResponse), null, true) {}
public Endpoint(string name, string subject) : this(name, subject, null, true) {}

// internal use constructors
internal Endpoint(string name, string subject, Schema schema, Dictionary<string, string> metadata, bool validate) {
internal Endpoint(string name, string subject, Dictionary<string, string> metadata, bool validate) {
if (validate) {
Name = Validator.ValidateIsRestrictedTerm(name, "Endpoint Name", true);
if (subject == null) {
Expand All @@ -39,27 +33,24 @@ internal Endpoint(string name, string subject, Schema schema, Dictionary<string,
Name = name;
Subject = subject;
}
Schema = schema;
Metadata = metadata == null || metadata.Count == 0 ? null : metadata;
}

internal Endpoint(JSONNode node)
{
Name = node[ApiConstants.Name];
Subject = node[ApiConstants.Subject];
Schema = Schema.OptionalInstance(node[ApiConstants.Schema]);
Metadata = JsonUtils.StringStringDictionary(node, ApiConstants.Metadata);
}

private Endpoint(EndpointBuilder b)
: this(b.Name, b.Subject, Schema.OptionalInstance(b.SchemaRequest, b.SchemaResponse), b.Metadata, true) {}
: this(b.Name, b.Subject, b.Metadata, true) {}

public override JSONNode ToJsonNode()
{
JSONObject jso = new JSONObject();
JsonUtils.AddField(jso, ApiConstants.Name, Name);
JsonUtils.AddField(jso, ApiConstants.Subject, Subject);
JsonUtils.AddField(jso, ApiConstants.Schema, Schema);
JsonUtils.AddField(jso, ApiConstants.Metadata, Metadata);
return jso;
}
Expand All @@ -70,21 +61,11 @@ public sealed class EndpointBuilder
{
internal string Name;
internal string Subject;
internal string SchemaRequest;
internal string SchemaResponse;
internal Dictionary<string, string> Metadata;

public EndpointBuilder WithEndpoint(Endpoint endpoint) {
Name = endpoint.Name;
Subject = endpoint.Subject;
if (endpoint.Schema == null) {
SchemaRequest = null;
SchemaResponse = null;
}
else {
SchemaRequest = endpoint.Schema.Request;
SchemaResponse = endpoint.Schema.Response;
}
return this;
}

Expand All @@ -98,28 +79,6 @@ public EndpointBuilder WithSubject(string subject) {
return this;
}

public EndpointBuilder WithSchemaRequest(string schemaRequest) {
SchemaRequest = schemaRequest;
return this;
}

public EndpointBuilder WithSchemaResponse(string schemaResponse) {
SchemaResponse = schemaResponse;
return this;
}

public EndpointBuilder WithSchema(Schema schema) {
if (schema == null) {
SchemaRequest = null;
SchemaResponse = null;
}
else {
SchemaRequest = schema.Request;
SchemaResponse = schema.Response;
}
return this;
}

public EndpointBuilder WithMetadata(Dictionary<string, string> metadata)
{
Metadata = metadata;
Expand All @@ -138,7 +97,7 @@ public override string ToString()

protected bool Equals(Endpoint other)
{
return Name == other.Name && Subject == other.Subject && Equals(Schema, other.Schema);
return Name == other.Name && Subject == other.Subject && Validator.DictionariesEqual(Metadata, other.Metadata);
}

public override bool Equals(object obj)
Expand All @@ -155,7 +114,7 @@ public override int GetHashCode()
{
var hashCode = (Name != null ? Name.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Subject != null ? Subject.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Schema != null ? Schema.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Metadata != null ? Metadata.GetHashCode() : 0);
return hashCode;
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/NATS.Client/Service/EndpointResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class EndpointResponse : JsonSerializable
{
public string Name { get; }
public string Subject { get; }
public Schema Schema { get; }
public long NumRequests { get; }
public long NumErrors { get; }
public long ProcessingTime { get; }
Expand All @@ -38,7 +37,6 @@ public class EndpointResponse : JsonSerializable
internal EndpointResponse(string name, string subject, long numRequests, long numErrors, long processingTime, string lastError, JSONNode data, DateTime started) {
Name = name;
Subject = subject;
Schema = null;
NumRequests = numRequests;
NumErrors = numErrors;
ProcessingTime = processingTime;
Expand All @@ -48,10 +46,9 @@ internal EndpointResponse(string name, string subject, long numRequests, long nu
Started = started;
}

internal EndpointResponse(string name, string subject, Schema schema) {
internal EndpointResponse(string name, string subject) {
Name = name;
Subject = subject;
Schema = schema;
NumRequests = 0;
NumErrors = 0;
ProcessingTime = 0;
Expand All @@ -65,7 +62,6 @@ internal EndpointResponse(JSONNode node)
{
Name = node[ApiConstants.Name];
Subject = node[ApiConstants.Subject];
Schema = Schema.OptionalInstance(node[ApiConstants.Schema]);
NumRequests = JsonUtils.AsLongOrZero(node, ApiConstants.NumRequests);
NumErrors = JsonUtils.AsLongOrZero(node, ApiConstants.NumErrors);
ProcessingTime = JsonUtils.AsLongOrZero(node, ApiConstants.ProcessingTime);
Expand Down Expand Up @@ -93,7 +89,6 @@ public override JSONNode ToJsonNode()
JSONObject jso = new JSONObject();
JsonUtils.AddField(jso, ApiConstants.Name, Name);
JsonUtils.AddField(jso, ApiConstants.Subject, Subject);
JsonUtils.AddField(jso, ApiConstants.Schema, Schema);
JsonUtils.AddFieldWhenGtZero(jso, ApiConstants.NumRequests, NumRequests);
JsonUtils.AddFieldWhenGtZero(jso, ApiConstants.NumErrors, NumErrors);
JsonUtils.AddFieldWhenGtZero(jso, ApiConstants.ProcessingTime, ProcessingTime);
Expand All @@ -113,7 +108,6 @@ protected bool Equals(EndpointResponse other)
{
return Name == other.Name
&& Subject == other.Subject
&& Equals(Schema, other.Schema)
&& NumRequests == other.NumRequests
&& NumErrors == other.NumErrors
&& ProcessingTime == other.ProcessingTime
Expand All @@ -137,7 +131,6 @@ public override int GetHashCode()
{
var hashCode = (Name != null ? Name.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Subject != null ? Subject.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Schema != null ? Schema.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ NumRequests.GetHashCode();
hashCode = (hashCode * 397) ^ NumErrors.GetHashCode();
hashCode = (hashCode * 397) ^ ProcessingTime.GetHashCode();
Expand Down
86 changes: 0 additions & 86 deletions src/NATS.Client/Service/Schema.cs

This file was deleted.

83 changes: 0 additions & 83 deletions src/NATS.Client/Service/SchemaResponse.cs

This file was deleted.

Loading

0 comments on commit 5fbf641

Please sign in to comment.