Skip to content

Commit c689639

Browse files
committed
fix: compare unresolved references by $ref and resolve bindings Extensions
Unresolved references compared their null targets, so every unresolved reference equalled every other one and equalled null. They now compare by their $ref string, and comparing with a null element returns false. Resolved references compare as before. AsyncApiReference overrode Equals without GetHashCode; it now hashes its $ref string. AsyncApiBindingsReference.Extensions read the backing field, so it threw until another member had resolved the reference.
1 parent b0c91c5 commit c689639

17 files changed

Lines changed: 195 additions & 15 deletions

‎src/ByteBard.AsyncAPI/Models/AsyncApiReference.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ public override bool Equals(object obj)
151151
return this.Equals(reference);
152152
}
153153

154+
public override int GetHashCode()
155+
{
156+
return this.Reference?.GetHashCode() ?? 0;
157+
}
158+
154159
/// <summary>
155160
/// Serialize <see cref="AsyncApiReference"/> to Async Api.
156161
/// </summary>

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiBindingsReference{TBinding}.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override void Add(TBinding binding)
3434

3535
public override ICollection<TBinding> Values => this.Target.Values;
3636

37-
public override IDictionary<string, IAsyncApiExtension> Extensions => this.target.Extensions;
37+
public override IDictionary<string, IAsyncApiExtension> Extensions => this.Target.Extensions;
3838

3939
public override int Count => this.Target.Count;
4040

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiChannelReference.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public bool Equals(AsyncApiChannelReference other)
9898
return this.Equals(reference);
9999
}
100100

101+
if (this.Target is null && other.Target is null)
102+
{
103+
return this.Reference == other.Reference;
104+
}
105+
101106
return this.Target == other.Target;
102107
}
103108

@@ -118,7 +123,7 @@ public override bool Equals(object obj)
118123

119124
public bool Equals(AsyncApiChannel other)
120125
{
121-
return this.Target == other;
126+
return other is not null && this.Target == other;
122127
}
123128
}
124129
}

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiCorrelationIdReference.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public bool Equals(AsyncApiCorrelationIdReference other)
5858
return this.Equals(reference);
5959
}
6060

61+
if (this.Target is null && other.Target is null)
62+
{
63+
return this.Reference == other.Reference;
64+
}
65+
6166
return this.Target == other.Target;
6267
}
6368

@@ -78,7 +83,7 @@ public override bool Equals(object obj)
7883

7984
public bool Equals(AsyncApiCorrelationId other)
8085
{
81-
return this.Target == other;
86+
return other is not null && this.Target == other;
8287
}
8388

8489
public override void SerializeV2(IAsyncApiWriter writer)

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiExternalDocumentationReference.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public bool Equals(AsyncApiExternalDocumentationReference other)
5454
return this.Equals(reference);
5555
}
5656

57+
if (this.Target is null && other.Target is null)
58+
{
59+
return this.Reference == other.Reference;
60+
}
61+
5762
return this.Target == other.Target;
5863
}
5964

@@ -74,7 +79,7 @@ public override bool Equals(object obj)
7479

7580
public bool Equals(AsyncApiExternalDocumentation other)
7681
{
77-
return this.Target == other;
82+
return other is not null && this.Target == other;
7883
}
7984

8085
/// <summary>

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiJsonSchemaReference.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ public bool Equals(AsyncApiJsonSchemaReference other)
309309
return this.Equals(reference);
310310
}
311311

312+
if (this.Target is null && other.Target is null)
313+
{
314+
return this.Reference == other.Reference;
315+
}
316+
312317
return this.Target == other.Target;
313318
}
314319

@@ -329,7 +334,7 @@ public override bool Equals(object obj)
329334

330335
public bool Equals(AsyncApiJsonSchema other)
331336
{
332-
return this.Target == other;
337+
return other is not null && this.Target == other;
333338
}
334339

335340
public override void SerializeV2(IAsyncApiWriter writer)

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiMessageReference.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public bool Equals(AsyncApiMessageReference other)
7979
return this.Equals(reference);
8080
}
8181

82+
if (this.Target is null && other.Target is null)
83+
{
84+
return this.Reference == other.Reference;
85+
}
86+
8287
return this.Target == other.Target;
8388
}
8489

@@ -99,7 +104,7 @@ public override bool Equals(object obj)
99104

100105
public bool Equals(AsyncApiMessage other)
101106
{
102-
return this.Target == other;
107+
return other is not null && this.Target == other;
103108
}
104109

105110
public override void SerializeV2(IAsyncApiWriter writer)

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiMessageTraitReference.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public bool Equals(AsyncApiMessageTraitReference other)
7676
return this.Equals(reference);
7777
}
7878

79+
if (this.Target is null && other.Target is null)
80+
{
81+
return this.Reference == other.Reference;
82+
}
83+
7984
return this.Target == other.Target;
8085
}
8186

@@ -96,7 +101,7 @@ public override bool Equals(object obj)
96101

97102
public bool Equals(AsyncApiMessageTrait other)
98103
{
99-
return this.Target == other;
104+
return other is not null && this.Target == other;
100105
}
101106

102107
public override void SerializeV2(IAsyncApiWriter writer)

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiOperationReference.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public bool Equals(AsyncApiOperationReference other)
7878
return this.Equals(reference);
7979
}
8080

81+
if (this.Target is null && other.Target is null)
82+
{
83+
return this.Reference == other.Reference;
84+
}
85+
8186
return this.Target == other.Target;
8287
}
8388

@@ -98,7 +103,7 @@ public override bool Equals(object obj)
98103

99104
public bool Equals(AsyncApiOperation other)
100105
{
101-
return this.Target == other;
106+
return other is not null && this.Target == other;
102107
}
103108

104109
public override void SerializeV2(IAsyncApiWriter writer)

‎src/ByteBard.AsyncAPI/Models/References/AsyncApiOperationReplyAddressReference.cs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public bool Equals(AsyncApiOperationReplyAddressReference other)
5454
return this.Equals(reference);
5555
}
5656

57+
if (this.Target is null && other.Target is null)
58+
{
59+
return this.Reference == other.Reference;
60+
}
61+
5762
return this.Target == other.Target;
5863
}
5964

@@ -74,7 +79,7 @@ public override bool Equals(object obj)
7479

7580
public bool Equals(AsyncApiOperationReplyAddress other)
7681
{
77-
return this.Target == other;
82+
return other is not null && this.Target == other;
7883
}
7984

8085
public override void SerializeV3(IAsyncApiWriter writer)

0 commit comments

Comments
 (0)