Skip to content

Commit 45b835c

Browse files
committed
Merge remote-tracking branch 'upstream/vnext' into remove-some-un-used-fields
2 parents 683589e + 306dda2 commit 45b835c

File tree

128 files changed

+2183
-2074
lines changed

Some content is hidden

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

128 files changed

+2183
-2074
lines changed

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal static class OpenApiService
4141
/// <summary>
4242
/// Implementation of the transform command
4343
/// </summary>
44-
public static async Task TransformOpenApiDocument(HidiOptions options, ILogger logger, CancellationToken cancellationToken)
44+
public static async Task TransformOpenApiDocument(HidiOptions options, ILogger logger, CancellationToken cancellationToken = default)
4545
{
4646
if (string.IsNullOrEmpty(options.OpenApi) && string.IsNullOrEmpty(options.Csdl) && string.IsNullOrEmpty(options.FilterOptions?.FilterByApiManifest))
4747
{
@@ -85,7 +85,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
8585
}
8686

8787
// Load OpenAPI document
88-
OpenApiDocument document = await GetOpenApi(options, logger, cancellationToken, options.MetadataVersion).ConfigureAwait(false);
88+
OpenApiDocument document = await GetOpenApi(options, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
8989

9090
if (options.FilterOptions != null)
9191
{
@@ -116,7 +116,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
116116
}
117117
}
118118

119-
private static async Task<ApiDependency?> FindApiDependency(string? apiManifestPath, ILogger logger, CancellationToken cancellationToken)
119+
private static async Task<ApiDependency?> FindApiDependency(string? apiManifestPath, ILogger logger, CancellationToken cancellationToken = default)
120120
{
121121
ApiDependency? apiDependency = null;
122122
// If API Manifest is provided, load it, use it get the OpenAPI path
@@ -212,7 +212,7 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma
212212
}
213213

214214
// Get OpenAPI document either from OpenAPI or CSDL
215-
private static async Task<OpenApiDocument> GetOpenApi(HidiOptions options, ILogger logger, CancellationToken cancellationToken, string? metadataVersion = null)
215+
private static async Task<OpenApiDocument> GetOpenApi(HidiOptions options, ILogger logger, string? metadataVersion = null, CancellationToken cancellationToken = default)
216216
{
217217

218218
OpenApiDocument document;
@@ -326,7 +326,7 @@ private static Stream ApplyFilterToCsdl(Stream csdlStream, string entitySetOrSin
326326
public static async Task ValidateOpenApiDocument(
327327
string openApi,
328328
ILogger logger,
329-
CancellationToken cancellationToken)
329+
CancellationToken cancellationToken = default)
330330
{
331331
if (string.IsNullOrEmpty(openApi))
332332
{
@@ -361,7 +361,7 @@ public static async Task ValidateOpenApiDocument(
361361
}
362362
}
363363

364-
private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken)
364+
private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
365365
{
366366
ReadResult result;
367367
Stopwatch stopwatch = Stopwatch.StartNew();
@@ -480,7 +480,7 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
480480
/// <summary>
481481
/// Reads stream from file system or makes HTTP request depending on the input string
482482
/// </summary>
483-
private static async Task<Stream> GetStream(string input, ILogger logger, CancellationToken cancellationToken)
483+
private static async Task<Stream> GetStream(string input, ILogger logger, CancellationToken cancellationToken = default)
484484
{
485485
Stream stream;
486486
using (logger.BeginScope("Reading input stream"))
@@ -556,7 +556,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
556556
return extension;
557557
}
558558

559-
internal static async Task<string?> ShowOpenApiDocument(HidiOptions options, ILogger logger, CancellationToken cancellationToken)
559+
internal static async Task<string?> ShowOpenApiDocument(HidiOptions options, ILogger logger, CancellationToken cancellationToken = default)
560560
{
561561
try
562562
{
@@ -565,7 +565,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
565565
throw new ArgumentException("Please input a file path or URL");
566566
}
567567

568-
var document = await GetOpenApi(options, logger, cancellationToken).ConfigureAwait(false);
568+
var document = await GetOpenApi(options, logger, null, cancellationToken).ConfigureAwait(false);
569569

570570
using (logger.BeginScope("Creating diagram"))
571571
{
@@ -664,18 +664,21 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
664664
{
665665
var rootNode = OpenApiUrlTreeNode.Create(document, "main");
666666

667-
writer.WriteLine(@"<!doctype html>
668-
<html>
669-
<head>
670-
<meta charset=""utf-8""/>
671-
<script src=""https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.0.0/mermaid.min.js""></script>
672-
</head>
673-
<style>
674-
body {
675-
font-family: Verdana, sans-serif;
676-
}
677-
</style>
678-
<body>");
667+
writer.WriteLine(
668+
"""
669+
<!doctype html>
670+
<html>
671+
<head>
672+
<meta charset="utf-8"/>
673+
<script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.0.0/mermaid.min.js"></script>
674+
</head>
675+
<style>
676+
body {
677+
font-family: Verdana, sans-serif;
678+
}
679+
</style>
680+
<body>
681+
""");
679682
writer.WriteLine("<h1>" + document.Info.Title + "</h1>");
680683
writer.WriteLine();
681684
writer.WriteLine($"<h3> API Description: <a href='{sourceUrl}'>{sourceUrl}</a></h3>");
@@ -686,30 +689,34 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
686689
{
687690
writer.WriteLine($"<span style=\"padding:2px;background-color:{style.Value.Color};border: 2px solid\">{style.Key.Replace("_", " ", StringComparison.OrdinalIgnoreCase)}</span>");
688691
}
692+
689693
writer.WriteLine("</div>");
690694
writer.WriteLine("<hr/>");
691695
writer.WriteLine("<code class=\"language-mermaid\">");
692696
rootNode.WriteMermaid(writer);
693697
writer.WriteLine("</code>");
694698

695699
// Write script tag to include JS library for rendering markdown
696-
writer.WriteLine(@"<script>
697-
var config = {
698-
startOnLoad:true,
699-
theme: 'forest',
700-
flowchart:{
701-
useMaxWidth:false,
702-
htmlLabels:true
703-
}
704-
};
705-
mermaid.initialize(config);
706-
window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
707-
</script>");
700+
writer.WriteLine(
701+
"""
702+
<script>
703+
var config = {
704+
startOnLoad:true,
705+
theme: 'forest',
706+
flowchart:{
707+
useMaxWidth:false,
708+
htmlLabels:true
709+
}
710+
};
711+
mermaid.initialize(config);
712+
window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
713+
</script>
714+
""");
708715
// Write script tag to include JS library for rendering mermaid
709716
writer.WriteLine("</html");
710717
}
711718

712-
internal static async Task PluginManifest(HidiOptions options, ILogger logger, CancellationToken cancellationToken)
719+
internal static async Task PluginManifest(HidiOptions options, ILogger logger, CancellationToken cancellationToken = default)
713720
{
714721
// If ApiManifest is provided, set the referenced OpenAPI document
715722
var apiDependency = await FindApiDependency(options.FilterOptions?.FilterByApiManifest, logger, cancellationToken).ConfigureAwait(false);
@@ -719,7 +726,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
719726
}
720727

721728
// Load OpenAPI document
722-
OpenApiDocument document = await GetOpenApi(options, logger, cancellationToken, options.MetadataVersion).ConfigureAwait(false);
729+
OpenApiDocument document = await GetOpenApi(options, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
723730

724731
cancellationToken.ThrowIfCancellationRequested();
725732

src/Microsoft.OpenApi.Hidi/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT license.
33

44
using System.CommandLine;
5-
using System.CommandLine.Parsing;
65
using System.Threading.Tasks;
76
using Microsoft.OpenApi.Hidi.Handlers;
87
using Microsoft.OpenApi.Hidi.Options;

src/Microsoft.OpenApi.Readers/Interface/IOpenApiVersionService.cs

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

4-
using System;
54
using Microsoft.OpenApi.Interfaces;
65
using Microsoft.OpenApi.Models;
76
using Microsoft.OpenApi.Readers.ParseNodes;

src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic)
6060
public async Task<ReadResult> ReadAsync(Stream input, CancellationToken cancellationToken = default)
6161
{
6262
MemoryStream bufferedStream;
63-
if (input is MemoryStream)
63+
if (input is MemoryStream stream)
6464
{
65-
bufferedStream = (MemoryStream)input;
65+
bufferedStream = stream;
6666
}
6767
else
6868
{

src/Microsoft.OpenApi.Readers/OpenApiTextReaderReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public T ReadFragment<T>(TextReader input, OpenApiSpecVersion version, out OpenA
104104
{
105105
diagnostic = new OpenApiDiagnostic();
106106
diagnostic.Errors.Add(new OpenApiError($"#line={ex.Start.Line}", ex.Message));
107-
return default(T);
107+
return default;
108108
}
109109

110110
return new OpenApiYamlDocumentReader(this._settings).ReadFragment<T>(yamlDocument, version, out diagnostic);

src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.IO;
76
using System.Linq;
87
using System.Threading;
98
using System.Threading.Tasks;
@@ -140,15 +139,15 @@ public async Task<ReadResult> ReadAsync(YamlDocument input, CancellationToken ca
140139
};
141140
}
142141

143-
private async Task<OpenApiDiagnostic> LoadExternalRefs(OpenApiDocument document, CancellationToken cancellationToken)
142+
private async Task<OpenApiDiagnostic> LoadExternalRefs(OpenApiDocument document, CancellationToken cancellationToken = default)
144143
{
145144
// Create workspace for all documents to live in.
146145
var openApiWorkSpace = new OpenApiWorkspace();
147146

148147
// Load this root document into the workspace
149148
var streamLoader = new DefaultStreamLoader(_settings.BaseUrl);
150149
var workspaceLoader = new OpenApiWorkspaceLoader(openApiWorkSpace, _settings.CustomExternalLoader ?? streamLoader, _settings);
151-
return await workspaceLoader.LoadAsync(new OpenApiReference { ExternalResource = "/" }, document, cancellationToken);
150+
return await workspaceLoader.LoadAsync(new OpenApiReference { ExternalResource = "/" }, document, null, cancellationToken);
152151
}
153152

154153
private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument document)

src/Microsoft.OpenApi.Readers/ParseNodes/AnyMapFieldMapParameter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using Microsoft.OpenApi.Any;
7-
using Microsoft.OpenApi.Interfaces;
87
using Microsoft.OpenApi.Models;
98

109
namespace Microsoft.OpenApi.Readers.ParseNodes

src/Microsoft.OpenApi.Readers/ParseNodes/JsonPointerExtensions.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ public static YamlNode Find(this JsonPointer currentPointer, YamlNode baseYamlNo
2626
var pointer = baseYamlNode;
2727
foreach (var token in currentPointer.Tokens)
2828
{
29-
var sequence = pointer as YamlSequenceNode;
30-
31-
if (sequence != null)
29+
if (pointer is YamlSequenceNode sequence)
3230
{
3331
pointer = sequence.Children[Convert.ToInt32(token)];
3432
}
3533
else
3634
{
37-
var map = pointer as YamlMappingNode;
38-
if (map != null)
35+
if (pointer is YamlMappingNode map)
3936
{
4037
if (!map.Children.TryGetValue(new YamlScalarNode(token), out pointer))
4138
{

src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public override Dictionary<string, T> CreateMap<T>(Func<MapNode, T> map)
7474
{
7575
Context.StartObject(key);
7676
value = n.Value as YamlMappingNode == null
77-
? default(T)
77+
? default
7878
: map(new MapNode(Context, n.Value as YamlMappingNode));
7979
}
8080
finally
@@ -152,8 +152,7 @@ public override Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
152152
try
153153
{
154154
Context.StartObject(key);
155-
YamlScalarNode scalarNode = n.Value as YamlScalarNode;
156-
if (scalarNode == null)
155+
if (n.Value is not YamlScalarNode scalarNode)
157156
{
158157
throw new OpenApiReaderException($"Expected scalar while parsing {typeof(T).Name}", Context);
159158
}
@@ -205,8 +204,7 @@ public string GetReferencePointer()
205204

206205
public string GetScalarValue(ValueNode key)
207206
{
208-
var scalarNode = _node.Children[new YamlScalarNode(key.GetScalarValue())] as YamlScalarNode;
209-
if (scalarNode == null)
207+
if (_node.Children[new YamlScalarNode(key.GetScalarValue())] is not YamlScalarNode scalarNode)
210208
{
211209
throw new OpenApiReaderException($"Expected scalar at line {_node.Start.Line} for key {key.GetScalarValue()}", Context);
212210
}

src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
5050
return newObject;
5151
}
5252

53-
if (!(openApiAny is OpenApiString))
53+
if (openApiAny is not OpenApiString apiString)
5454
{
5555
return openApiAny;
5656
}
5757

58-
var value = ((OpenApiString)openApiAny).Value;
58+
var value = apiString.Value;
5959
var type = schema?.Type;
6060
var format = schema?.Format;
6161

62-
if (((OpenApiString)openApiAny).IsExplicit())
62+
if (apiString.IsExplicit())
6363
{
6464
// More narrow type detection for explicit strings, only check types that are passed as strings
6565
if (schema == null)
@@ -113,7 +113,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
113113
}
114114
}
115115

116-
return openApiAny;
116+
return apiString;
117117
}
118118

119119
if (value is null or "null")
@@ -247,7 +247,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
247247

248248
if (type == "string")
249249
{
250-
return openApiAny;
250+
return apiString;
251251
}
252252

253253
if (type == "boolean")
@@ -262,7 +262,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
262262
// If data conflicts with the given type, return a string.
263263
// This converter is used in the parser, so it does not perform any validations,
264264
// but the validator can be used to validate whether the data and given type conflicts.
265-
return openApiAny;
265+
return apiString;
266266
}
267267
}
268268
}

0 commit comments

Comments
 (0)