Skip to content

Commit 56bb532

Browse files
committed
feat: enable NRT
1 parent 7a5e709 commit 56bb532

File tree

193 files changed

+2663
-1532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+2663
-1532
lines changed

src/Microsoft.OpenApi.Hidi/Extensions/OpenApiExtensibleExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal static class OpenApiExtensibleExtensions
1414
/// <returns>A <see cref="string"/> value matching the provided extensionKey. Return null when extensionKey is not found. </returns>
1515
internal static string GetExtension(this IDictionary<string, IOpenApiExtension> extensions, string extensionKey)
1616
{
17-
if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiAny castValue)
17+
if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiAny castValue && castValue.Node is not null)
1818
{
1919
return castValue.Node.GetValue<string>();
2020
}

src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public override void Visit(IOpenApiSchema schema)
5353

5454
public override void Visit(IOpenApiPathItem pathItem)
5555
{
56-
if (pathItem.Operations.TryGetValue(OperationType.Put, out var value) &&
56+
if (pathItem.Operations is not null && pathItem.Operations.TryGetValue(OperationType.Put, out var value) &&
5757
value.OperationId != null)
5858
{
5959
var operationId = value.OperationId;
@@ -149,7 +149,7 @@ private static string RemoveKeyTypeSegment(string operationId, IList<IOpenApiPar
149149
var segments = operationId.SplitByChar('.');
150150
foreach (var parameter in parameters)
151151
{
152-
var keyTypeExtension = parameter.Extensions.GetExtension("x-ms-docs-key-type");
152+
var keyTypeExtension = parameter.Extensions?.GetExtension("x-ms-docs-key-type");
153153
if (keyTypeExtension != null && operationId.Contains(keyTypeExtension, StringComparison.OrdinalIgnoreCase))
154154
{
155155
segments.Remove(keyTypeExtension);
@@ -178,7 +178,10 @@ private static void ResolveFunctionParameters(IList<IOpenApiParameter> parameter
178178

179179
private void AddAdditionalPropertiesToSchema(IOpenApiSchema schema)
180180
{
181-
if (schema is OpenApiSchema openApiSchema && !_schemaLoop.Contains(schema) && schema.Type.Equals(JsonSchemaType.Object))
181+
if (schema is OpenApiSchema openApiSchema
182+
&& !_schemaLoop.Contains(schema)
183+
&& schema.Type.Equals(JsonSchemaType.Object)
184+
&& schema.AdditionalProperties is not null)
182185
{
183186
openApiSchema.AdditionalProperties = new OpenApiSchema() { Type = JsonSchemaType.Object };
184187

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
};

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
1212
<EmbedUntrackedSources>true</EmbedUntrackedSources>
1313
<NoWarn>NU5048</NoWarn>
14+
<Nullable>enable</Nullable>
1415
<PackageReadmeFile>README.md</PackageReadmeFile>
1516
</PropertyGroup>
1617

src/Microsoft.OpenApi.Readers/OpenApiYamlReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ public static ReadResult Read(JsonNode jsonNode, OpenApiReaderSettings settings)
8484
}
8585

8686
/// <inheritdoc/>
87-
public T ReadFragment<T>(MemoryStream input,
87+
public T? ReadFragment<T>(MemoryStream input,
8888
OpenApiSpecVersion version,
8989
OpenApiDocument openApiDocument,
9090
out OpenApiDiagnostic diagnostic,
91-
OpenApiReaderSettings settings = null) where T : IOpenApiElement
91+
OpenApiReaderSettings? settings = null) where T : IOpenApiElement
9292
{
9393
if (input is null) throw new ArgumentNullException(nameof(input));
9494
JsonNode jsonNode;
@@ -110,7 +110,7 @@ public T ReadFragment<T>(MemoryStream input,
110110
}
111111

112112
/// <inheritdoc/>
113-
public static T ReadFragment<T>(JsonNode input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings settings = null) where T : IOpenApiElement
113+
public static T ReadFragment<T>(JsonNode input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings? settings = null) where T : IOpenApiElement
114114
{
115115
return _jsonReader.ReadFragment<T>(input, version, openApiDocument, out diagnostic, settings);
116116
}

src/Microsoft.OpenApi/Any/OpenApiAny.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ namespace Microsoft.OpenApi.Any
1212
/// </summary>
1313
public class OpenApiAny : IOpenApiElement, IOpenApiExtension
1414
{
15-
private readonly JsonNode jsonNode;
15+
private readonly JsonNode? jsonNode;
1616

1717
/// <summary>
1818
/// Initializes the <see cref="OpenApiAny"/> class.
1919
/// </summary>
2020
/// <param name="jsonNode"></param>
21-
public OpenApiAny(JsonNode jsonNode)
21+
public OpenApiAny(JsonNode? jsonNode)
2222
{
2323
this.jsonNode = jsonNode;
2424
}
2525

2626
/// <summary>
2727
/// Gets the underlying JsonNode.
2828
/// </summary>
29-
public JsonNode Node { get { return jsonNode; } }
29+
public JsonNode? Node { get { return jsonNode; } }
3030

3131
/// <summary>
3232
/// Writes out the OpenApiAny type.

src/Microsoft.OpenApi/Attributes/DisplayAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public class DisplayAttribute : Attribute
1515
/// Initializes a new instance of the <see cref="DisplayAttribute"/> class.
1616
/// </summary>
1717
/// <param name="name">The display name.</param>
18-
public DisplayAttribute(string name)
18+
public DisplayAttribute(string? name)
1919
{
2020
Name = Utils.CheckArgumentNullOrEmpty(name);
2121
}
2222

2323
/// <summary>
2424
/// The display Name.
2525
/// </summary>
26-
public string Name { get; }
26+
public string? Name { get; }
2727
}
2828
}

src/Microsoft.OpenApi/Exceptions/OpenApiException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public OpenApiException(string message)
3333
/// </summary>
3434
/// <param name="message">The plain text error message for this exception.</param>
3535
/// <param name="innerException">The inner exception that is the cause of this exception to be thrown.</param>
36-
public OpenApiException(string message, Exception innerException)
36+
public OpenApiException(string message, Exception? innerException)
3737
: base(message, innerException)
3838
{
3939
}
@@ -46,6 +46,6 @@ public OpenApiException(string message, Exception innerException)
4646
/// a text/plain pointer as defined in https://tools.ietf.org/html/rfc5147
4747
/// Currently only line= is provided because using char= causes tests to break due to CR/LF and LF differences
4848
/// </summary>
49-
public string Pointer { get; set; }
49+
public string? Pointer { get; set; }
5050
}
5151
}

src/Microsoft.OpenApi/Exceptions/OpenApiReaderException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -39,7 +39,7 @@ public OpenApiReaderException(string message, ParsingContext context) : base(mes
3939
/// </summary>
4040
/// <param name="message">Plain text error message for this exception.</param>
4141
/// <param name="node">Parsing node where error occured</param>
42-
public OpenApiReaderException(string message, JsonNode node) : base(message)
42+
public OpenApiReaderException(string message, JsonNode? node) : base(message)
4343
{
4444
// This only includes line because using a char range causes tests to break due to CR/LF & LF differences
4545
// See https://tools.ietf.org/html/rfc5147 for syntax

src/Microsoft.OpenApi/Exceptions/OpenApiUnsupportedSpecVersionException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class OpenApiUnsupportedSpecVersionException : Exception
1818
/// Initializes the <see cref="OpenApiUnsupportedSpecVersionException"/> class with a specification version.
1919
/// </summary>
2020
/// <param name="specificationVersion">Version that caused this exception to be thrown.</param>
21-
public OpenApiUnsupportedSpecVersionException(string specificationVersion)
21+
public OpenApiUnsupportedSpecVersionException(string? specificationVersion)
2222
: base(string.Format(CultureInfo.InvariantCulture, messagePattern, specificationVersion))
2323
{
2424
this.SpecificationVersion = specificationVersion;
@@ -39,6 +39,6 @@ public OpenApiUnsupportedSpecVersionException(string specificationVersion, Excep
3939
/// <summary>
4040
/// The unsupported specification version.
4141
/// </summary>
42-
public string SpecificationVersion { get; }
42+
public string? SpecificationVersion { get; }
4343
}
4444
}

0 commit comments

Comments
 (0)