Skip to content

Commit

Permalink
Fix log return disposed obj (#705)
Browse files Browse the repository at this point in the history
* generator not to dispose stream

* new generated code

* test to cover log stream
  • Loading branch information
tg123 committed Sep 17, 2021
1 parent 4e29dff commit 07ab21b
Show file tree
Hide file tree
Showing 5 changed files with 308 additions and 221 deletions.
2 changes: 1 addition & 1 deletion gen/KubernetesGenerator/Kubernetes.cs.template
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ namespace k8s
}
throw new SerializationException("Unable to deserialize the response.", _responseContent, ex);
}
{{/IfReturnType operation "stream"}}
{{/IfReturnType operation "obj"}}
}
{{/IfReturnType operation "any"}}
if (_shouldTrace)
Expand Down
22 changes: 22 additions & 0 deletions gen/KubernetesGenerator/KubernetesExtensions.cs.template
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ namespace k8s
{{/operation.parameters}}
CancellationToken cancellationToken = default(CancellationToken))
{
{{#IfReturnType operation "stream"}}
var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
null,
cancellationToken);
_result.Request.Dispose();
{{GetReturnType operation "_result.Body"}};
{{/IfReturnType operation "stream"}}
{{#IfReturnType operation "obj"}}
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
Expand All @@ -73,6 +84,17 @@ namespace k8s
{
{{GetReturnType operation "_result.Body"}};
}
{{/IfReturnType operation "obj"}}
{{#IfReturnType operation "void"}}
using (var _result = await operations.{{GetMethodName operation "WithHttpMessagesAsync"}}(
{{#operation.parameters}}
{{GetDotNetName .}},
{{/operation.parameters}}
null,
cancellationToken).ConfigureAwait(false))
{
}
{{/IfReturnType operation "void"}}
}

{{/.}}
Expand Down
2 changes: 1 addition & 1 deletion gen/KubernetesGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ private static string GetApiVersion(JsonSchema4 definition)
{
fn(null);
}
else if (type == "stream" && rt == "Stream")
else if (type.ToLower() == rt.ToLower())
{
fn(null);
}
Expand Down
Loading

0 comments on commit 07ab21b

Please sign in to comment.