@@ -28,34 +28,27 @@ internal async Task<JsonElement> GetSwaggerDocumentAsync()
28
28
29
29
private async Task < JsonElement > CreateSwaggerDocumentAsync ( )
30
30
{
31
- string absoluteOutputPath = GetSwaggerDocumentAbsoluteOutputPath ( SwaggerDocumentOutputPath ) ;
32
-
33
31
string content = await GetAsync ( "swagger/v1/swagger.json" ) ;
34
32
35
33
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
+ }
37
40
38
41
return rootElement ;
39
42
}
40
43
41
- private static string GetSwaggerDocumentAbsoluteOutputPath ( string ? relativePath )
44
+ private static string GetSwaggerDocumentAbsoluteOutputPath ( string relativePath )
42
45
{
43
- AssertHasSwaggerDocumentOutputPath ( relativePath ) ;
44
-
45
46
string solutionRoot = Path . Combine ( Assembly . GetExecutingAssembly ( ) . Location , "../../../../../../" ) ;
46
47
string outputPath = Path . Combine ( solutionRoot , relativePath , "swagger.g.json" ) ;
47
48
48
49
return Path . GetFullPath ( outputPath ) ;
49
50
}
50
51
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
-
59
52
private async Task < string > GetAsync ( string requestUrl )
60
53
{
61
54
using var request = new HttpRequestMessage ( HttpMethod . Get , requestUrl ) ;
0 commit comments