Skip to content

Commit f7194d9

Browse files
committed
Not all swagger documents need to be saved to disk; changes in OpenApiTestContext to allow for this
1 parent 2604f84 commit f7194d9

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

test/OpenApiTests/OpenApiTestContext.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,27 @@ internal async Task<JsonElement> GetSwaggerDocumentAsync()
2828

2929
private async Task<JsonElement> CreateSwaggerDocumentAsync()
3030
{
31-
string absoluteOutputPath = GetSwaggerDocumentAbsoluteOutputPath(SwaggerDocumentOutputPath);
32-
3331
string content = await GetAsync("swagger/v1/swagger.json");
3432

3533
JsonElement rootElement = ParseSwaggerDocument(content);
36-
await WriteToDiskAsync(absoluteOutputPath, rootElement);
34+
35+
if (SwaggerDocumentOutputPath != null)
36+
{
37+
string absoluteOutputPath = GetSwaggerDocumentAbsoluteOutputPath(SwaggerDocumentOutputPath);
38+
await WriteToDiskAsync(absoluteOutputPath, rootElement);
39+
}
3740

3841
return rootElement;
3942
}
4043

41-
private static string GetSwaggerDocumentAbsoluteOutputPath(string? relativePath)
44+
private static string GetSwaggerDocumentAbsoluteOutputPath(string relativePath)
4245
{
43-
AssertHasSwaggerDocumentOutputPath(relativePath);
44-
4546
string solutionRoot = Path.Combine(Assembly.GetExecutingAssembly().Location, "../../../../../../");
4647
string outputPath = Path.Combine(solutionRoot, relativePath, "swagger.g.json");
4748

4849
return Path.GetFullPath(outputPath);
4950
}
5051

51-
private static void AssertHasSwaggerDocumentOutputPath([SysNotNull] string? relativePath)
52-
{
53-
if (relativePath is null)
54-
{
55-
throw new Exception($"Property '{nameof(OpenApiTestContext<object, DbContext>)}.{nameof(SwaggerDocumentOutputPath)}' must be set.");
56-
}
57-
}
58-
5952
private async Task<string> GetAsync(string requestUrl)
6053
{
6154
using var request = new HttpRequestMessage(HttpMethod.Get, requestUrl);

0 commit comments

Comments
 (0)