@@ -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