Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions DevProxy.Plugins/Generation/TypeSpecGeneratorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,25 +399,32 @@ private async Task ProcessResponseAsync(Response? httpResponse, TypeSpecFile doc
.ToDictionary(h => h.Name.ToCamelCase(), h => h.Value.GetType().Name)
};

var models = await GetModelsFromStringAsync(httpResponse.BodyString, lastSegment.ToPascalCase(), httpResponse.StatusCode >= 400);
if (models.Length > 0)
if (httpResponse.HasBody)
{
foreach (var model in models)
var models = await GetModelsFromStringAsync(httpResponse.BodyString, lastSegment.ToPascalCase(), httpResponse.StatusCode >= 400);
if (models.Length > 0)
{
_ = doc.Service.Namespace.MergeModel(model);
}
foreach (var model in models)
{
_ = doc.Service.Namespace.MergeModel(model);
}

var rootModel = models.Last();
if (rootModel.IsArray)
{
res.BodyType = $"{rootModel.Name}[]";
op.Name = await GetOperationNameAsync("list", url);
}
else
{
res.BodyType = rootModel.Name;
var rootModel = models.Last();
if (rootModel.IsArray)
{
res.BodyType = $"{rootModel.Name}[]";
op.Name = await GetOperationNameAsync("list", url);
}
else
{
res.BodyType = rootModel.Name;
}
}
}
else
{
Logger.LogDebug("Response has no body");
}
}

op.MergeResponse(res);
Expand Down