Skip to content

Commit 360b228

Browse files
Fix Copilot suggestions
Apply code review suggestions from #3686.
1 parent ed88a1b commit 360b228

1 file changed

Lines changed: 45 additions & 29 deletions

File tree

test/Swashbuckle.AspNetCore.IntegrationTests/ClientGenerator.cs

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,45 +73,61 @@ public async Task CompileAsync(string location)
7373

7474
public async Task<TemporaryDirectory> GenerateFromStringAsync(ClientGeneratorTool generator, string openApiDocument)
7575
{
76-
TemporaryDirectory project;
76+
TemporaryDirectory project = null;
7777

78-
switch (generator)
78+
try
79+
{
80+
switch (generator)
81+
{
82+
case ClientGeneratorTool.Kiota:
83+
project = await GenerateProjectAsync(["Microsoft.Kiota.Bundle"]);
84+
await GenerateClientFromStringWithKiotaAsync(project.Path, openApiDocument, outputHelper);
85+
break;
86+
87+
case ClientGeneratorTool.NSwag:
88+
project = await GenerateProjectAsync(["Newtonsoft.Json"]);
89+
await GenerateClientFromStringWithNSwagAsync(project.Path, openApiDocument);
90+
break;
91+
92+
default:
93+
throw new ArgumentOutOfRangeException(nameof(generator), generator, $"The client generator tool '{generator}' is not supported.");
94+
}
95+
}
96+
catch (Exception)
7997
{
80-
case ClientGeneratorTool.Kiota:
81-
project = await GenerateProjectAsync(["Microsoft.Kiota.Bundle"]);
82-
await GenerateClientFromStringWithKiotaAsync(project.Path, openApiDocument, outputHelper);
83-
break;
84-
85-
case ClientGeneratorTool.NSwag:
86-
project = await GenerateProjectAsync(["Newtonsoft.Json"]);
87-
await GenerateClientFromStringWithNSwagAsync(project.Path, openApiDocument);
88-
break;
89-
90-
default:
91-
throw new ArgumentOutOfRangeException(nameof(generator), generator, $"The client generator tool '{generator}' is not supported.");
98+
project?.Dispose();
99+
throw;
92100
}
93101

94102
return project;
95103
}
96104

97105
public async Task<TemporaryDirectory> GenerateFromUrlAsync(ClientGeneratorTool generator, string openApiDocumentUrl)
98106
{
99-
TemporaryDirectory project;
107+
TemporaryDirectory project = null;
100108

101-
switch (generator)
109+
try
110+
{
111+
switch (generator)
112+
{
113+
case ClientGeneratorTool.Kiota:
114+
project = await GenerateProjectAsync(["Microsoft.Kiota.Bundle"]);
115+
await GenerateClientFromUrlWithKiotaAsync(project.Path, openApiDocumentUrl, outputHelper);
116+
break;
117+
118+
case ClientGeneratorTool.NSwag:
119+
project = await GenerateProjectAsync(["Newtonsoft.Json"]);
120+
await GenerateClientFromUrlWithNSwagAsync(project.Path, openApiDocumentUrl);
121+
break;
122+
123+
default:
124+
throw new ArgumentOutOfRangeException(nameof(generator), generator, $"The client generator tool '{generator}' is not supported.");
125+
}
126+
}
127+
catch (Exception)
102128
{
103-
case ClientGeneratorTool.Kiota:
104-
project = await GenerateProjectAsync(["Microsoft.Kiota.Bundle"]);
105-
await GenerateClientFromUrlWithKiotaAsync(project.Path, openApiDocumentUrl, outputHelper);
106-
break;
107-
108-
case ClientGeneratorTool.NSwag:
109-
project = await GenerateProjectAsync(["Newtonsoft.Json"]);
110-
await GenerateClientFromUrlWithNSwagAsync(project.Path, openApiDocumentUrl);
111-
break;
112-
113-
default:
114-
throw new ArgumentOutOfRangeException(nameof(generator), generator, $"The client generator tool '{generator}' is not supported.");
129+
project?.Dispose();
130+
throw;
115131
}
116132

117133
return project;
@@ -283,7 +299,7 @@ private static string GetNuGetPackageVersion(string name)
283299
var ns = project.Root.GetDefaultNamespace();
284300

285301
var version = project
286-
.Root?
302+
.Root
287303
.Elements(ns + "ItemGroup")
288304
.Elements(ns + "PackageVersion")
289305
.Select((p) =>

0 commit comments

Comments
 (0)