-
Notifications
You must be signed in to change notification settings - Fork 271
feat: enable null reference type support #2146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
56bb532
feat: enable NRT
MaggieKimani1 b3b5663
fix: dereference of a possible null reference
MaggieKimani1 c99dfc3
Merge branch 'main' into feat/enable-NRT
MaggieKimani1 489fa4d
chore: code cleanup
MaggieKimani1 0b6b07d
chore: convert to conditional expression
MaggieKimani1 f13a9e4
Update src/Microsoft.OpenApi/Models/OpenApiOperation.cs
MaggieKimani1 b7b845c
Update src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs
MaggieKimani1 ea5c389
chore: PR feedback
MaggieKimani1 78b8d88
Merge branch 'main' into feat/enable-NRT
MaggieKimani1 1b793a4
fix: resolve merge conflict errors
MaggieKimani1 3df5c98
chore: remove deprecated code and tests; make param required
MaggieKimani1 69a2b9b
chore: code refactor and cleanup
MaggieKimani1 2133509
chore: update public API
MaggieKimani1 d990121
chore: address PR comments
MaggieKimani1 80edd66
fix: remove nullable Json node params
MaggieKimani1 2749a3e
chore: use conditional compilation to make reference a required field
MaggieKimani1 fa012ac
Merge branch 'main' into feat/enable-NRT
MaggieKimani1 d016afd
chore: resolve merge conflicts
MaggieKimani1 fd15b0a
Merge branch 'main' into feat/enable-NRT
MaggieKimani1 9ef1bb0
chore: resolve merge conflicts
MaggieKimani1 07b3a2c
refactor: apply nullable to new changes
MaggieKimani1 cd41026
Merge branch 'main' into feat/enable-NRT
baywet ad59b9c
chore: bad merge
baywet b1b2fc5
Merge branch 'main' into feat/enable-NRT
baywet b6d68bb
chore: simplifies filtering condition
baywet e6cc29c
Update src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs
MaggieKimani1 8a4fcc2
chore: address more PR feedback
MaggieKimani1 6116afe
chore: pull latest changes
MaggieKimani1 0805d89
chore: add check for both null and empty strings
MaggieKimani1 0a690ff
chore: revert to include check for empty strings
MaggieKimani1 af8a41c
chore: cleanup
MaggieKimani1 d9afa53
Merge branch 'main' into feat/enable-NRT
MaggieKimani1 cd4de69
chore: clean up public API
MaggieKimani1 0176234
Update src/Microsoft.OpenApi/Reader/Services/OpenApiRemoteReferenceCo…
MaggieKimani1 2e0b42d
fix: resolve PR feedback
MaggieKimani1 7f71fb7
fix: apply suggestion
MaggieKimani1 7a9b01e
chore: Merge remote-tracking branch 'origin/main' into feat/enable-NRT
MaggieKimani1 c5caa27
chore: add defensive programming
MaggieKimani1 02c95e8
Merge branch 'main' into feat/enable-NRT
MaggieKimani1 ff0d877
chore: resolve merge conflicts
MaggieKimani1 2dcc72e
chore: more refactoring
MaggieKimani1 0aea73f
Update src/Microsoft.OpenApi/Reader/V2/OpenApiOperationDeserializer.cs
MaggieKimani1 f942764
Update src/Microsoft.OpenApi/Reader/V2/OpenApiPathItemDeserializer.cs
MaggieKimani1 e545160
Update src/Microsoft.OpenApi/Reader/V31/OpenApiServerVariableDeserial…
MaggieKimani1 6cc7497
Update src/Microsoft.OpenApi/Reader/V31/OpenApiSecurityRequirementDes…
MaggieKimani1 93ac7f0
Update src/Microsoft.OpenApi/Reader/V2/OpenApiSecurityRequirementDese…
MaggieKimani1 571b537
Update src/Microsoft.OpenApi/Reader/V3/OpenApiServerVariableDeseriali…
MaggieKimani1 69ef5c0
Update src/Microsoft.OpenApi/Reader/V3/OpenApiSecurityRequirementDese…
MaggieKimani1 81e0682
chore: another round of refactoring
MaggieKimani1 d9a7bec
chore: clean up nullability of params
MaggieKimani1 32568e8
fix: compiler errors
MaggieKimani1 f608cea
fix: remove redundant cast and update public API
MaggieKimani1 2f8ea28
Merge branch 'main' into feat/enable-NRT
MaggieKimani1 50b06c4
chore: fix merge conflict issues
MaggieKimani1 c9b8f4f
chore: apply copilot suggestion
MaggieKimani1 2a12fa7
Update src/Microsoft.OpenApi/Services/OpenApiWalker.cs
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,7 +155,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog | |
return apiDependency; | ||
} | ||
|
||
private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger, ApiDependency? apiDependency, JsonDocument? postmanCollection, OpenApiDocument document) | ||
private static OpenApiDocument? ApplyFilters(HidiOptions options, ILogger logger, ApiDependency? apiDependency, JsonDocument? postmanCollection, OpenApiDocument? document) | ||
{ | ||
Dictionary<string, List<string>> requestUrls; | ||
if (apiDependency != null) | ||
|
@@ -191,7 +191,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger, | |
return document; | ||
} | ||
|
||
private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken) | ||
private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument? document, ILogger logger, CancellationToken cancellationToken) | ||
{ | ||
using (logger.BeginScope("Output")) | ||
{ | ||
|
@@ -225,9 +225,9 @@ private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat o | |
} | ||
|
||
// Get OpenAPI document either from OpenAPI or CSDL | ||
private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options, string format, ILogger logger, string? metadataVersion = null, CancellationToken cancellationToken = default) | ||
private static async Task<OpenApiDocument?> GetOpenApiAsync(HidiOptions options, string format, ILogger logger, string? metadataVersion = null, CancellationToken cancellationToken = default) | ||
{ | ||
OpenApiDocument document; | ||
OpenApiDocument? document; | ||
Stream stream; | ||
|
||
if (!string.IsNullOrEmpty(options.Csdl)) | ||
|
@@ -248,7 +248,7 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options, | |
|
||
document = await ConvertCsdlToOpenApiAsync(filteredStream ?? stream, format, metadataVersion, options.SettingsConfig, cancellationToken).ConfigureAwait(false); | ||
stopwatch.Stop(); | ||
logger.LogTrace("{Timestamp}ms: Generated OpenAPI with {Paths} paths.", stopwatch.ElapsedMilliseconds, document.Paths.Count); | ||
logger.LogTrace("{Timestamp}ms: Generated OpenAPI with {Paths} paths.", stopwatch.ElapsedMilliseconds, document?.Paths.Count); | ||
} | ||
} | ||
else if (!string.IsNullOrEmpty(options.OpenApi)) | ||
|
@@ -262,7 +262,7 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options, | |
return document; | ||
} | ||
|
||
private static Func<string, OperationType?, OpenApiOperation, bool>? FilterOpenApiDocument(string? filterByOperationIds, string? filterByTags, Dictionary<string, List<string>> requestUrls, OpenApiDocument document, ILogger logger) | ||
private static Func<string, OperationType?, OpenApiOperation, bool>? FilterOpenApiDocument(string? filterByOperationIds, string? filterByTags, Dictionary<string, List<string>> requestUrls, OpenApiDocument? document, ILogger logger) | ||
{ | ||
Func<string, OperationType?, OpenApiOperation, bool>? predicate = null; | ||
|
||
|
@@ -376,7 +376,7 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe | |
|
||
if (result is null) return null; | ||
|
||
return result.Diagnostic.Errors.Count == 0; | ||
return result.Diagnostic?.Errors.Count == 0; | ||
} | ||
|
||
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 | |
/// </summary> | ||
/// <param name="csdl">The CSDL stream.</param> | ||
/// <returns>An OpenAPI document.</returns> | ||
public static async Task<OpenApiDocument> ConvertCsdlToOpenApiAsync(Stream csdl, string format, string? metadataVersion = null, IConfiguration? settings = null, CancellationToken token = default) | ||
public static async Task<OpenApiDocument?> ConvertCsdlToOpenApiAsync(Stream csdl, string format, string? metadataVersion = null, IConfiguration? settings = null, CancellationToken token = default) | ||
{ | ||
using var reader = new StreamReader(csdl); | ||
var csdlText = await reader.ReadToEndAsync(token).ConfigureAwait(false); | ||
|
@@ -429,7 +429,7 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApiAsync(Stream csdl, | |
/// </summary> | ||
/// <param name="document"> The converted OpenApiDocument.</param> | ||
/// <returns> A valid OpenApiDocument instance.</returns> | ||
public static OpenApiDocument FixReferences(OpenApiDocument document, string format) | ||
public static OpenApiDocument? FixReferences(OpenApiDocument document, string format) | ||
{ | ||
// This method is only needed because the output of ConvertToOpenApi isn't quite a valid OpenApiDocument instance. | ||
// 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 | |
private static void LogErrors(ILogger logger, ReadResult result) | ||
{ | ||
var context = result.Diagnostic; | ||
if (context.Errors.Count != 0) | ||
if (context is not null && context.Errors.Count != 0) | ||
{ | ||
using (logger.BeginScope("Detected errors")) | ||
{ | ||
|
@@ -660,11 +660,11 @@ private static void LogErrors(ILogger logger, ReadResult result) | |
} | ||
} | ||
|
||
internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocument document, StreamWriter writer) | ||
internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocument? document, StreamWriter writer) | ||
{ | ||
var rootNode = OpenApiUrlTreeNode.Create(document, "main"); | ||
|
||
writer.WriteLine("# " + document.Info.Title); | ||
writer.WriteLine("# " + document?.Info.Title); | ||
writer.WriteLine(); | ||
writer.WriteLine("API Description: " + openapiUrl); | ||
|
||
|
@@ -681,7 +681,7 @@ internal static void WriteTreeDocumentAsMarkdown(string openapiUrl, OpenApiDocum | |
writer.WriteLine("```"); | ||
} | ||
|
||
internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument document, StreamWriter writer, bool asHtmlFile = false) | ||
internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument? document, StreamWriter writer, bool asHtmlFile = false) | ||
{ | ||
var rootNode = OpenApiUrlTreeNode.Create(document, "main"); | ||
|
||
|
@@ -700,7 +700,7 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d | |
</style> | ||
<body> | ||
"""); | ||
writer.WriteLine("<h1>" + document.Info.Title + "</h1>"); | ||
writer.WriteLine("<h1>" + document?.Info.Title + "</h1>"); | ||
writer.WriteLine(); | ||
writer.WriteLine($"<h3> API Description: <a href='{sourceUrl}'>{sourceUrl}</a></h3>"); | ||
|
||
|
@@ -771,9 +771,13 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg | |
await WriteOpenApiAsync(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false); | ||
|
||
// Create OpenAIPluginManifest from ApiDependency and OpenAPI document | ||
var manifest = new OpenAIPluginManifest(document.Info?.Title ?? "Title", document.Info?.Title ?? "Title", "https://go.microsoft.com/fwlink/?LinkID=288890", document.Info?.Contact?.Email ?? "[email protected]", document.Info?.License?.Url.ToString() ?? "https://placeholderlicenseurl.com") | ||
var manifest = new OpenAIPluginManifest(document?.Info.Title ?? "Title", | ||
document?.Info.Title ?? "Title", | ||
"https://go.microsoft.com/fwlink/?LinkID=288890", | ||
document?.Info?.Contact?.Email ?? "[email protected]", | ||
document?.Info?.License?.Url?.ToString() ?? "https://placeholderlicenseurl.com") | ||
{ | ||
DescriptionForHuman = document.Info?.Description ?? "Description placeholder", | ||
DescriptionForHuman = document?.Info.Description ?? "Description placeholder", | ||
Api = new("openapi", "./openapi.json"), | ||
Auth = new ManifestNoAuth(), | ||
}; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.