Skip to content

Commit c3d0c15

Browse files
authored
Merge pull request #2015 from microsoft/dev
release of preview 3
2 parents 2efd4eb + c183323 commit c3d0c15

File tree

88 files changed

+1437
-1358
lines changed

Some content is hidden

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

88 files changed

+1437
-1358
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @irvinesunday @darrelmiller @gavinbarron @millicentachieng @MaggieKimani1 @andrueastman
1+
* @irvinesunday @darrelmiller @gavinbarron @millicentachieng @MaggieKimani1 @andrueastman @baywet

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33
##
4-
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
4+
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
55

66
# User-specific files
77
*.suo

.vscode/launch.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
// Use IntelliSense to find out which attributes exist for C# debugging
66
// Use hover for the description of the existing attributes
7-
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
7+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/main/debugger-launchjson.md
88
"name": "Launch Hidi",
99
"type": "coreclr",
1010
"request": "launch",
@@ -22,7 +22,7 @@
2222
{
2323
// Use IntelliSense to find out which attributes exist for C# debugging
2424
// Use hover for the description of the existing attributes
25-
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
25+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/main/debugger-launchjson.md
2626
"name": "Launch Workbench",
2727
"type": "coreclr",
2828
"request": "launch",

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ VOLUME /app/collection.json
1919
ENV HIDI_CONTAINER=true DOTNET_TieredPGO=1 DOTNET_TC_QuickJitForLoops=1
2020
ENTRYPOINT ["dotnet", "Microsoft.OpenApi.Hidi.dll"]
2121
LABEL description="# Welcome to Hidi \
22-
To start transforming OpenAPI documents checkout [the getting started documentation](https://github.com/microsoft/OpenAPI.NET/tree/vnext/src/Microsoft.OpenApi.Hidi) \
23-
[Source dockerfile](https://github.com/microsoft/OpenAPI.NET/blob/vnext/Dockerfile)"
22+
To start transforming OpenAPI documents checkout [the getting started documentation](https://github.com/microsoft/OpenAPI.NET/tree/main/src/Microsoft.OpenApi.Hidi) \
23+
[Source dockerfile](https://github.com/microsoft/OpenAPI.NET/blob/main/Dockerfile)"

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var httpClient = new HttpClient
8181
BaseAddress = new Uri("https://raw.githubusercontent.com/OAI/OpenAPI-Specification/")
8282
};
8383

84-
var stream = await httpClient.GetStreamAsync("master/examples/v3.0/petstore.yaml");
84+
var stream = await httpClient.GetStreamAsync("main/examples/v3.0/petstore.yaml");
8585

8686
// Read V3 as YAML
8787
var openApiDocument = new OpenApiStreamReader().Read(stream, out var diagnostic);
@@ -95,7 +95,7 @@ var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, Open
9595
In order to test the validity of an OpenApi document, we avail the following tools:
9696
- [Microsoft.OpenApi.Hidi](https://www.nuget.org/packages/Microsoft.OpenApi.Hidi)
9797

98-
A commandline tool for validating and transforming OpenAPI descriptions. [Installation guidelines and documentation](https://github.com/microsoft/OpenAPI.NET/blob/vnext/src/Microsoft.OpenApi.Hidi/readme.md)
98+
A commandline tool for validating and transforming OpenAPI descriptions. [Installation guidelines and documentation](https://github.com/microsoft/OpenAPI.NET/blob/main/src/Microsoft.OpenApi.Hidi/readme.md)
9999

100100
- Microsoft.OpenApi.Workbench
101101

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Nullable>enable</Nullable>
1010
<ToolCommandName>hidi</ToolCommandName>
1111
<PackageOutputPath>./../../artifacts</PackageOutputPath>
12-
<Version>1.4.16</Version>
12+
<Version>2.0.0-preview3</Version>
1313
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
1414
<SignAssembly>true</SignAssembly>
1515
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
@@ -29,23 +29,23 @@
2929

3030
<ItemGroup>
3131
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
32-
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
33-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
34-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
32+
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
33+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
34+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
3535
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
36-
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
36+
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
3737
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3838
<PrivateAssets>all</PrivateAssets>
3939
</PackageReference>
4040
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
41-
<PackageReference Include="Microsoft.OData.Edm" Version="8.2.0" />
41+
<PackageReference Include="Microsoft.OData.Edm" Version="8.2.3" />
4242
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.7" />
43-
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
43+
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.6-preview" />
4444
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
4545
<!--STJ
4646
required until Microsoft.Extensions.Logging.Console and Microsoft.Extensions.Configuration.Json
4747
update their dependencies -->
48-
<PackageReference Include="System.Text.Json" Version="8.0.5" />
48+
<PackageReference Include="System.Text.Json" Version="9.0.0" />
4949
</ItemGroup>
5050

5151
<ItemGroup>

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

+24-27
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
using Microsoft.OData.Edm.Csdl;
2323
using Microsoft.OpenApi.ApiManifest;
2424
using Microsoft.OpenApi.ApiManifest.OpenAI;
25+
using Microsoft.OpenApi.ApiManifest.OpenAI.Authentication;
2526
using Microsoft.OpenApi.Extensions;
2627
using Microsoft.OpenApi.Hidi.Extensions;
2728
using Microsoft.OpenApi.Hidi.Formatters;
@@ -66,7 +67,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
6667

6768
#pragma warning restore CA1308 // Normalize strings to uppercase
6869
options.Output = new($"./output{inputExtension}");
69-
};
70+
}
7071

7172
if (options.CleanOutput && options.Output.Exists)
7273
{
@@ -85,7 +86,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
8586
var apiDependency = await FindApiDependencyAsync(options.FilterOptions.FilterByApiManifest, logger, cancellationToken).ConfigureAwait(false);
8687
if (apiDependency != null)
8788
{
88-
options.OpenApi = apiDependency.ApiDescripionUrl;
89+
options.OpenApi = apiDependency.ApiDescriptionUrl;
8990
}
9091

9192
// If Postman Collection is provided, load it
@@ -97,8 +98,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
9798
}
9899

99100
// Load OpenAPI document
100-
var format = OpenApiModelFactory.GetFormat(options.OpenApi);
101-
var document = await GetOpenApiAsync(options, format, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
101+
var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
102102

103103
if (options.FilterOptions != null)
104104
{
@@ -254,8 +254,8 @@ private static async Task<OpenApiDocument> GetOpenApiAsync(HidiOptions options,
254254
else if (!string.IsNullOrEmpty(options.OpenApi))
255255
{
256256
stream = await GetStreamAsync(options.OpenApi, logger, cancellationToken).ConfigureAwait(false);
257-
var result = await ParseOpenApiAsync(options.OpenApi, options.InlineExternal, logger, stream, cancellationToken).ConfigureAwait(false);
258-
document = result.OpenApiDocument;
257+
var result = await ParseOpenApiAsync(options.OpenApi, format, options.InlineExternal, logger, stream, cancellationToken).ConfigureAwait(false);
258+
document = result.Document;
259259
}
260260
else throw new InvalidOperationException("No input file path or URL provided");
261261

@@ -351,14 +351,14 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
351351
try
352352
{
353353
using var stream = await GetStreamAsync(openApi, logger, cancellationToken).ConfigureAwait(false);
354-
355-
result = await ParseOpenApiAsync(openApi, false, logger, stream, cancellationToken).ConfigureAwait(false);
354+
var openApiFormat = !string.IsNullOrEmpty(openApi) ? GetOpenApiFormat(openApi, logger) : OpenApiFormat.Yaml;
355+
result = await ParseOpenApiAsync(openApi, openApiFormat.GetDisplayName(),false, logger, stream, cancellationToken).ConfigureAwait(false);
356356

357357
using (logger.BeginScope("Calculating statistics"))
358358
{
359359
var statsVisitor = new StatsVisitor();
360360
var walker = new OpenApiWalker(statsVisitor);
361-
walker.Walk(result.OpenApiDocument);
361+
walker.Walk(result.Document);
362362

363363
logger.LogTrace("Finished walking through the OpenApi document. Generating a statistics report..");
364364
#pragma warning disable CA2254
@@ -377,10 +377,10 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
377377

378378
if (result is null) return null;
379379

380-
return result.OpenApiDiagnostic.Errors.Count == 0;
380+
return result.Diagnostic.Errors.Count == 0;
381381
}
382382

383-
private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
383+
private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, string format, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
384384
{
385385
ReadResult result;
386386
var stopwatch = Stopwatch.StartNew();
@@ -396,7 +396,6 @@ private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool
396396
new Uri("file://" + new FileInfo(openApiFile).DirectoryName + Path.DirectorySeparatorChar)
397397
};
398398

399-
var format = OpenApiModelFactory.GetFormat(openApiFile);
400399
result = await OpenApiDocument.LoadAsync(stream, format, settings, cancellationToken).ConfigureAwait(false);
401400

402401
logger.LogTrace("{Timestamp}ms: Completed parsing.", stopwatch.ElapsedMilliseconds);
@@ -439,7 +438,7 @@ public static OpenApiDocument FixReferences(OpenApiDocument document, string for
439438
var sb = new StringBuilder();
440439
document.SerializeAsV3(new OpenApiYamlWriter(new StringWriter(sb)));
441440

442-
var doc = OpenApiDocument.Parse(sb.ToString(), format).OpenApiDocument;
441+
var doc = OpenApiDocument.Parse(sb.ToString(), format).Document;
443442

444443
return doc;
445444
}
@@ -587,8 +586,8 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
587586
throw new ArgumentException("Please input a file path or URL");
588587
}
589588

590-
var format = OpenApiModelFactory.GetFormat(options.OpenApi);
591-
var document = await GetOpenApiAsync(options, format, logger, null, cancellationToken).ConfigureAwait(false);
589+
var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml);
590+
var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, null, cancellationToken).ConfigureAwait(false);
592591

593592
using (logger.BeginScope("Creating diagram"))
594593
{
@@ -649,7 +648,7 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl
649648

650649
private static void LogErrors(ILogger logger, ReadResult result)
651650
{
652-
var context = result.OpenApiDiagnostic;
651+
var context = result.Diagnostic;
653652
if (context.Errors.Count != 0)
654653
{
655654
using (logger.BeginScope("Detected errors"))
@@ -745,12 +744,14 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
745744
var apiDependency = await FindApiDependencyAsync(options.FilterOptions?.FilterByApiManifest, logger, cancellationToken).ConfigureAwait(false);
746745
if (apiDependency != null)
747746
{
748-
options.OpenApi = apiDependency.ApiDescripionUrl;
747+
options.OpenApi = apiDependency.ApiDescriptionUrl;
749748
}
750749

750+
var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi)
751+
? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml);
752+
751753
// Load OpenAPI document
752-
var format = OpenApiModelFactory.GetFormat(options.OpenApi);
753-
var document = await GetOpenApiAsync(options, format, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
754+
var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
754755

755756
cancellationToken.ThrowIfCancellationRequested();
756757

@@ -771,15 +772,11 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
771772
WriteOpenApi(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger);
772773

773774
// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
774-
var manifest = new OpenAIPluginManifest
775+
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")
775776
{
776-
NameForHuman = document.Info.Title,
777-
DescriptionForHuman = document.Info.Description,
778-
Api = new()
779-
{
780-
Type = "openapi",
781-
Url = "./openapi.json"
782-
}
777+
DescriptionForHuman = document.Info?.Description ?? "Description placeholder",
778+
Api = new("openapi", "./openapi.json"),
779+
Auth = new ManifestNoAuth(),
783780
};
784781
manifest.NameForModel = manifest.NameForHuman;
785782
manifest.DescriptionForModel = manifest.DescriptionForHuman;

src/Microsoft.OpenApi.Hidi/StatsVisitor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public override void Visit(OpenApiOperation operation)
6161

6262
public int LinkCount { get; set; }
6363

64-
public override void Visit(OpenApiLink operation)
64+
public override void Visit(OpenApiLink link)
6565
{
6666
LinkCount++;
6767
}

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<LangVersion>latest</LangVersion>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>2.0.0-preview2</Version>
6+
<Version>2.0.0-preview3</Version>
77
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
88
<SignAssembly>true</SignAssembly>
99
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
@@ -25,13 +25,15 @@
2525

2626
<ItemGroup>
2727

28-
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
28+
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
2929
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3030
<PrivateAssets>all</PrivateAssets>
3131
</PackageReference>
3232

3333
<PackageReference Include="SharpYaml" Version="2.1.1" />
34-
<PackageReference Include="System.Text.Json" Version="8.0.5" />
34+
<PackageReference Include="System.Text.Json" Version="[8.0,)" />
35+
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-hh2w-p6rv-4g7w" />
36+
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-8g4q-xg66-9fp4" />
3537
</ItemGroup>
3638

3739
<ItemGroup>

0 commit comments

Comments
 (0)