Skip to content

Commit

Permalink
fix: guard against null bodies in OpenAPI transformers
Browse files Browse the repository at this point in the history
  • Loading branch information
ascott18 committed Dec 12, 2024
1 parent 560652f commit 530e45c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private void AddOtherBodyTypes(OpenApiOperation operation, OperationFilterContex
.GetMethod("GenerateRequestBody", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.Invoke(generator, [otherDescription, context.SchemaRepository]) as OpenApiRequestBody;

if (otherBody is null) continue;

// To mirror legacy behavior before JSON-accepting endpoints were added to Coalesce,
// only add the "multipart/form-data" body, but not the urlencoded body.
foreach (var otherContent in otherBody.Content.Where(c =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ private async void AddOtherBodyTypes(OpenApiOperation operation, OpenApiOperatio
if (resultTask is null) continue;

var result = await resultTask;
if (result is null) continue;

foreach (var otherContent in result.Content)
{
operation.RequestBody.Content.Add(otherContent);
Expand Down

0 comments on commit 530e45c

Please sign in to comment.