@@ -155,7 +155,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
155155 return apiDependency ;
156156 }
157157
158- private static OpenApiDocument ApplyFilters ( HidiOptions options , ILogger logger , ApiDependency ? apiDependency , JsonDocument ? postmanCollection , OpenApiDocument document )
158+ private static OpenApiDocument ? ApplyFilters ( HidiOptions options , ILogger logger , ApiDependency ? apiDependency , JsonDocument ? postmanCollection , OpenApiDocument ? document )
159159 {
160160 Dictionary < string , List < string > > requestUrls ;
161161 if ( apiDependency != null )
@@ -191,7 +191,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
191191 return document ;
192192 }
193193
194- private static async Task WriteOpenApiAsync ( HidiOptions options , OpenApiFormat openApiFormat , OpenApiSpecVersion openApiVersion , OpenApiDocument document , ILogger logger , CancellationToken cancellationToken )
194+ private static async Task WriteOpenApiAsync ( HidiOptions options , OpenApiFormat openApiFormat , OpenApiSpecVersion openApiVersion , OpenApiDocument ? document , ILogger logger , CancellationToken cancellationToken )
195195 {
196196 using ( logger . BeginScope ( "Output" ) )
197197 {
@@ -225,9 +225,9 @@ private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat o
225225 }
226226
227227 // Get OpenAPI document either from OpenAPI or CSDL
228- private static async Task < OpenApiDocument > GetOpenApiAsync ( HidiOptions options , string format , ILogger logger , string ? metadataVersion = null , CancellationToken cancellationToken = default )
228+ private static async Task < OpenApiDocument ? > GetOpenApiAsync ( HidiOptions options , string format , ILogger logger , string ? metadataVersion = null , CancellationToken cancellationToken = default )
229229 {
230- OpenApiDocument document ;
230+ OpenApiDocument ? document ;
231231 Stream stream ;
232232
233233 if ( ! string . IsNullOrEmpty ( options . Csdl ) )
@@ -248,7 +248,7 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
248248
249249 document = await ConvertCsdlToOpenApiAsync ( filteredStream ?? stream , format , metadataVersion , options . SettingsConfig , cancellationToken ) . ConfigureAwait ( false ) ;
250250 stopwatch . Stop ( ) ;
251- logger . LogTrace ( "{Timestamp}ms: Generated OpenAPI with {Paths} paths." , stopwatch . ElapsedMilliseconds , document . Paths . Count ) ;
251+ logger . LogTrace ( "{Timestamp}ms: Generated OpenAPI with {Paths} paths." , stopwatch . ElapsedMilliseconds , document ? . Paths . Count ) ;
252252 }
253253 }
254254 else if ( ! string . IsNullOrEmpty ( options . OpenApi ) )
@@ -262,7 +262,7 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
262262 return document ;
263263 }
264264
265- private static Func < string , OperationType ? , OpenApiOperation , bool > ? FilterOpenApiDocument ( string ? filterByOperationIds , string ? filterByTags , Dictionary < string , List < string > > requestUrls , OpenApiDocument document , ILogger logger )
265+ private static Func < string , OperationType ? , OpenApiOperation , bool > ? FilterOpenApiDocument ( string ? filterByOperationIds , string ? filterByTags , Dictionary < string , List < string > > requestUrls , OpenApiDocument ? document , ILogger logger )
266266 {
267267 Func < string , OperationType ? , OpenApiOperation , bool > ? predicate = null ;
268268
@@ -376,7 +376,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
376376
377377 if ( result is null ) return null ;
378378
379- return result . Diagnostic . Errors . Count == 0 ;
379+ return result . Diagnostic ? . Errors . Count == 0 ;
380380 }
381381
382382 private static async Task < ReadResult > ParseOpenApiAsync ( string openApiFile , bool inlineExternal , ILogger logger , Stream stream , CancellationToken cancellationToken = default )
@@ -411,7 +411,7 @@ private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool
411411 /// </summary>
412412 /// <param name="csdl">The CSDL stream.</param>
413413 /// <returns>An OpenAPI document.</returns>
414- public static async Task < OpenApiDocument > ConvertCsdlToOpenApiAsync ( Stream csdl , string format , string ? metadataVersion = null , IConfiguration ? settings = null , CancellationToken token = default )
414+ public static async Task < OpenApiDocument ? > ConvertCsdlToOpenApiAsync ( Stream csdl , string format , string ? metadataVersion = null , IConfiguration ? settings = null , CancellationToken token = default )
415415 {
416416 using var reader = new StreamReader ( csdl ) ;
417417 var csdlText = await reader . ReadToEndAsync ( token ) . ConfigureAwait ( false ) ;
@@ -429,7 +429,7 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApiAsync(Stream csdl,
429429 /// </summary>
430430 /// <param name="document"> The converted OpenApiDocument.</param>
431431 /// <returns> A valid OpenApiDocument instance.</returns>
432- public static OpenApiDocument FixReferences ( OpenApiDocument document , string format )
432+ public static OpenApiDocument ? FixReferences ( OpenApiDocument document , string format )
433433 {
434434 // This method is only needed because the output of ConvertToOpenApi isn't quite a valid OpenApiDocument instance.
435435 // So we write it out, and read it back in again to fix it up.
@@ -648,7 +648,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
648648 private static void LogErrors ( ILogger logger , ReadResult result )
649649 {
650650 var context = result . Diagnostic ;
651- if ( context . Errors . Count != 0 )
651+ if ( context is not null && context . Errors . Count != 0 )
652652 {
653653 using ( logger . BeginScope ( "Detected errors" ) )
654654 {
@@ -660,11 +660,11 @@ private static void LogErrors(ILogger logger, ReadResult result)
660660 }
661661 }
662662
663- internal static void WriteTreeDocumentAsMarkdown ( string openapiUrl , OpenApiDocument document , StreamWriter writer )
663+ internal static void WriteTreeDocumentAsMarkdown ( string openapiUrl , OpenApiDocument ? document , StreamWriter writer )
664664 {
665665 var rootNode = OpenApiUrlTreeNode . Create ( document , "main" ) ;
666666
667- writer . WriteLine ( "# " + document . Info . Title ) ;
667+ writer . WriteLine ( "# " + document ? . Info . Title ) ;
668668 writer . WriteLine ( ) ;
669669 writer . WriteLine ( "API Description: " + openapiUrl ) ;
670670
@@ -681,7 +681,7 @@ internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocum
681681 writer . WriteLine ( "```" ) ;
682682 }
683683
684- internal static void WriteTreeDocumentAsHtml ( string sourceUrl , OpenApiDocument document , StreamWriter writer , bool asHtmlFile = false )
684+ internal static void WriteTreeDocumentAsHtml ( string sourceUrl , OpenApiDocument ? document , StreamWriter writer , bool asHtmlFile = false )
685685 {
686686 var rootNode = OpenApiUrlTreeNode . Create ( document , "main" ) ;
687687
@@ -700,7 +700,7 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
700700 </style>
701701 <body>
702702 """ ) ;
703- writer . WriteLine ( "<h1>" + document . Info . Title + "</h1>" ) ;
703+ writer . WriteLine ( "<h1>" + document ? . Info . Title + "</h1>" ) ;
704704 writer . WriteLine ( ) ;
705705 writer . WriteLine ( $ "<h3> API Description: <a href='{ sourceUrl } '>{ sourceUrl } </a></h3>") ;
706706
@@ -771,9 +771,13 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
771771 await WriteOpenApiAsync ( options , OpenApiFormat . Json , OpenApiSpecVersion . OpenApi3_1 , document , logger , cancellationToken ) . ConfigureAwait ( false ) ;
772772
773773 // Create OpenAIPluginManifest from ApiDependency and OpenAPI document
774- var manifest = new OpenAIPluginManifest ( document . Info ? . Title ?? "Title" , document . Info ? . Title ?? "Title" , "https://go.microsoft.com/fwlink/?LinkID=288890" , document . Info ? . Contact ? . Email ?? "placeholder@contoso.com" , document . Info ? . License ? . Url . ToString ( ) ?? "https://placeholderlicenseurl.com" )
774+ var manifest = new OpenAIPluginManifest ( document ? . Info . Title ?? "Title" ,
775+ document ? . Info . Title ?? "Title" ,
776+ "https://go.microsoft.com/fwlink/?LinkID=288890" ,
777+ document ? . Info ? . Contact ? . Email ?? "placeholder@contoso.com" ,
778+ document ? . Info ? . License ? . Url ? . ToString ( ) ?? "https://placeholderlicenseurl.com" )
775779 {
776- DescriptionForHuman = document . Info ? . Description ?? "Description placeholder" ,
780+ DescriptionForHuman = document ? . Info . Description ?? "Description placeholder" ,
777781 Api = new ( "openapi" , "./openapi.json" ) ,
778782 Auth = new ManifestNoAuth ( ) ,
779783 } ;
0 commit comments