diff --git a/templates/vs/csharp/custom-copilot-rag-custom-api/OpenAPIClient/OpenAPIClient.cs b/templates/vs/csharp/custom-copilot-rag-custom-api/OpenAPIClient/OpenAPIClient.cs index bf35d72f218..de95a9f3dd5 100644 --- a/templates/vs/csharp/custom-copilot-rag-custom-api/OpenAPIClient/OpenAPIClient.cs +++ b/templates/vs/csharp/custom-copilot-rag-custom-api/OpenAPIClient/OpenAPIClient.cs @@ -71,7 +71,7 @@ public async Task CallAsync(string path, Method httpMethod, Reques ProcessParameters(param.HeaderObject, operationObj, ParameterStyle.Simple, false, (key, value) => request.AddHeader(key, value)); - if (param.RequestBody != null) + if (param.RequestBody != null && !IsEmptyJsonObject(param.RequestBody)) { request.AddJsonBody(param.RequestBody, ContentType.Json); } @@ -86,7 +86,17 @@ public async Task CallAsync(string path, Method httpMethod, Reques throw new RequestFailedException(response); } - private KeyValuePair GetParameterKeyValuePair(JsonProperty property, OpenApiOperation operationObj , ParameterStyle defaultStyle, bool defaultExplode) + private bool IsEmptyJsonObject(object requestBody) + { + if (requestBody is JsonElement jsonElement) + { + return jsonElement.ValueKind == JsonValueKind.Object && !jsonElement.EnumerateObject().Any(); + } + + return false; + } + + private KeyValuePair GetParameterKeyValuePair(JsonProperty property, OpenApiOperation operationObj, ParameterStyle defaultStyle, bool defaultExplode) { var key = property.Name; var value = property.Value;