@@ -322,7 +322,8 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
322
322
/// <summary>
323
323
/// Implementation of the validate command
324
324
/// </summary>
325
- public static async Task ValidateOpenApiDocument (
325
+ /// <returns><see langword="true"/> when valid, <see langword="false"/> when invalid and <see langword="null"/> when cancelled</returns>
326
+ public static async Task < bool ? > ValidateOpenApiDocument (
326
327
string openApi ,
327
328
ILogger logger ,
328
329
CancellationToken cancellationToken = default )
@@ -332,11 +333,13 @@ public static async Task ValidateOpenApiDocument(
332
333
throw new ArgumentNullException ( nameof ( openApi ) ) ;
333
334
}
334
335
336
+ ReadResult ? result = null ;
337
+
335
338
try
336
339
{
337
340
using var stream = await GetStream ( openApi , logger , cancellationToken ) . ConfigureAwait ( false ) ;
338
341
339
- var result = await ParseOpenApi ( openApi , false , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
342
+ result = await ParseOpenApi ( openApi , false , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
340
343
341
344
using ( logger . BeginScope ( "Calculating statistics" ) )
342
345
{
@@ -358,6 +361,10 @@ public static async Task ValidateOpenApiDocument(
358
361
{
359
362
throw new InvalidOperationException ( $ "Could not validate the document, reason: { ex . Message } ", ex ) ;
360
363
}
364
+
365
+ if ( result is null ) return null ;
366
+
367
+ return result . OpenApiDiagnostic . Errors . Count == 0 ;
361
368
}
362
369
363
370
private static async Task < ReadResult > ParseOpenApi ( string openApiFile , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken = default )
0 commit comments