Skip to content

Commit 7085d23

Browse files
fix: nullref on walking optional reply property refs (#23)
* Fix: Try read relative uri's as files. Signed-off-by: Alex Wichmann <VisualBean@users.noreply.github.com> * Update src/ByteBard.AsyncAPI.Readers/Services/DefaultStreamLoader.cs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Signed-off-by: Alex Wichmann <VisualBean@users.noreply.github.com> * Apply suggestion from @VisualBean Signed-off-by: Alex Wichmann <VisualBean@users.noreply.github.com> * Apply suggestion from @VisualBean Signed-off-by: Alex Wichmann <VisualBean@users.noreply.github.com> * Apply suggestion from @VisualBean Signed-off-by: Alex Wichmann <VisualBean@users.noreply.github.com> * Apply suggestion from @VisualBean Signed-off-by: Alex Wichmann <VisualBean@users.noreply.github.com> * Refactor method signatures to include `baseUri` parameter Updated all methods in `IStreamLoader`, `DefaultStreamLoader`, and related tests to accept both `baseUri` and `uri`. Added a new property `BaseUri` to `AsyncApiReaderSettings` for resolving relative references. Adjusted the implementation of external reference loading in `AsyncApiJsonDocumentReader`. * Refactor `AsyncApiWalker` to ensure null checks before walking references Added explicit null checks for `reply.Address` and `reply.Channel`. This prevents potential NullReferenceException when these properties are not initialized. This change ensures that the walker safely handles cases where optional fields might be missing, improving robustness of the code. --------- Signed-off-by: Alex Wichmann <VisualBean@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 07d912d commit 7085d23

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/ByteBard.AsyncAPI/Services/AsyncApiWalker.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,8 +587,15 @@ private void Walk(AsyncApiOperationReply reply)
587587

588588
this.visitor.Visit(reply);
589589

590-
this.Walk(reply.Address);
591-
this.Walk(reply.Channel as IAsyncApiReferenceable);
590+
if (reply.Address != null)
591+
{
592+
this.Walk(reply.Address);
593+
}
594+
595+
if (reply.Channel != null)
596+
{
597+
this.Walk(reply.Channel as IAsyncApiReferenceable);
598+
}
592599

593600
foreach (var message in reply.Messages)
594601
{
@@ -1211,4 +1218,4 @@ public void Walk(IAsyncApiElement element)
12111218
}
12121219
}
12131220
}
1214-
}
1221+
}

0 commit comments

Comments
 (0)