Skip to content

Commit

Permalink
Support $ref in request-bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
Eruzo committed Nov 26, 2024
1 parent 29eef8f commit f16bd20
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/NSwag.Core/OpenApiOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ private OpenApiParameter CreateBodyParameter()
private void UpdateBodyParameter(OpenApiParameter parameter)
{
parameter.Kind = OpenApiParameterKind.Body;
parameter.Name = RequestBody.ActualName;
parameter.Position = RequestBody.Position;
parameter.Description = RequestBody.Description;
parameter.IsRequired = RequestBody.IsRequired;
parameter.Example = RequestBody.Content.FirstOrDefault().Value?.Example;
parameter.Schema = RequestBody.Content.FirstOrDefault().Value?.Schema;
parameter.Name = RequestBody.ActualRequestBody.ActualName;
parameter.Position = RequestBody.ActualRequestBody.Position;
parameter.Description = RequestBody.ActualRequestBody.Description;
parameter.IsRequired = RequestBody.ActualRequestBody.IsRequired;
parameter.Example = RequestBody.ActualRequestBody.Content.FirstOrDefault().Value?.Example;
parameter.Schema = RequestBody.ActualRequestBody.Content.FirstOrDefault().Value?.Schema;
}

private void UpdateRequestBody(NotifyCollectionChangedEventArgs args)
Expand Down
13 changes: 13 additions & 0 deletions src/NSwag.Core/OpenApiRequestBody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,18 @@ public int? Position
object IJsonReference.PossibleRoot => ParentOperation?.Parent?.Parent;

#endregion

public override OpenApiRequestBody Reference
{
get
{
return base.Reference;
}
set
{
base.Reference = value;
(Parent as OpenApiOperation)?.UpdateBodyParameter();
}
}
}
}

0 comments on commit f16bd20

Please sign in to comment.