@@ -322,7 +322,8 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
322322 /// <summary>
323323 /// Implementation of the validate command
324324 /// </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 (
326327 string openApi ,
327328 ILogger logger ,
328329 CancellationToken cancellationToken = default )
@@ -332,11 +333,13 @@ public static async Task ValidateOpenApiDocument(
332333 throw new ArgumentNullException ( nameof ( openApi ) ) ;
333334 }
334335
336+ ReadResult ? result = null ;
337+
335338 try
336339 {
337340 using var stream = await GetStream ( openApi , logger , cancellationToken ) . ConfigureAwait ( false ) ;
338341
339- var result = await ParseOpenApi ( openApi , false , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
342+ result = await ParseOpenApi ( openApi , false , logger , stream , cancellationToken ) . ConfigureAwait ( false ) ;
340343
341344 using ( logger . BeginScope ( "Calculating statistics" ) )
342345 {
@@ -358,6 +361,10 @@ public static async Task ValidateOpenApiDocument(
358361 {
359362 throw new InvalidOperationException ( $ "Could not validate the document, reason: { ex . Message } ", ex ) ;
360363 }
364+
365+ if ( result is null ) return null ;
366+
367+ return result . OpenApiDiagnostic . Errors . Count == 0 ;
361368 }
362369
363370 private static async Task < ReadResult > ParseOpenApi ( string openApiFile , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken = default )
0 commit comments