Skip to content

Commit

Permalink
Merge pull request #1084 from microsoft/vnext
Browse files Browse the repository at this point in the history
Release libs
  • Loading branch information
MaggieKimani1 authored Nov 21, 2022
2 parents 1b02c01 + cbafb8c commit 656ac9a
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 51 deletions.
9 changes: 7 additions & 2 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ stages:
- job: build
steps:
- task: UseDotNet@2
displayName: 'Use .NET 6'
displayName: 'Use .NET 2' # needed for ESRP signing
inputs:
version: 6.x
version: 2.x

- task: UseDotNet@2
displayName: 'Use .NET 7'
inputs:
version: 7.x

- task: PoliCheck@1
displayName: 'Run PoliCheck "/src"'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

- name: Data gatherer
id: data_gatherer
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- if: steps.conditionals_handler.outputs.is_default_branch == 'true'
name: Bump GH tag
id: tag_generator
uses: mathieudutour/github-tag-action@v6.0
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x

- name: Initialize CodeQL
id: init_codeql
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/net6.0/Microsoft.OpenApi.Hidi.dll",
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/net7.0/Microsoft.OpenApi.Hidi.dll",
"args": [],
"cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env
WORKDIR /app

COPY ./src ./hidi/src
WORKDIR /app/hidi
RUN dotnet publish ./src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj -c Release

FROM mcr.microsoft.com/dotnet/runtime:6.0 as runtime
FROM mcr.microsoft.com/dotnet/runtime:7.0 as runtime
WORKDIR /app

COPY --from=build-env /app/hidi/src/Microsoft.OpenApi.Hidi/bin/Release/net6.0 ./
COPY --from=build-env /app/hidi/src/Microsoft.OpenApi.Hidi/bin/Release/net7.0 ./

VOLUME /app/output
VOLUME /app/openapi.yml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class TransformCommandHandler : ICommandHandler
public Option<string?> VersionOption { get; set; }
public Option<OpenApiFormat?> FormatOption { get; set; }
public Option<bool> TerseOutputOption { get; set; }
public Option<string> SettingsFileOption { get; set; }
public Option<LogLevel> LogLevelOption { get; set; }
public Option<string> FilterByOperationIdsOption { get; set; }
public Option<string> FilterByTagsOption { get; set; }
Expand All @@ -42,6 +43,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
string? version = context.ParseResult.GetValueForOption(VersionOption);
OpenApiFormat? format = context.ParseResult.GetValueForOption(FormatOption);
bool terseOutput = context.ParseResult.GetValueForOption(TerseOutputOption);
string settingsFile = context.ParseResult.GetValueForOption(SettingsFileOption);
LogLevel logLevel = context.ParseResult.GetValueForOption(LogLevelOption);
bool inlineLocal = context.ParseResult.GetValueForOption(InlineLocalOption);
bool inlineExternal = context.ParseResult.GetValueForOption(InlineExternalOption);
Expand All @@ -54,7 +56,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
var logger = loggerFactory.CreateLogger<OpenApiService>();
try
{
await OpenApiService.TransformOpenApiDocument(openapi, csdl, csdlFilter, output, cleanOutput, version, format, terseOutput, logLevel, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, cancellationToken);
await OpenApiService.TransformOpenApiDocument(openapi, csdl, csdlFilter, output, cleanOutput, version, format, terseOutput, settingsFile, logLevel, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, cancellationToken);

return 0;
}
Expand Down
25 changes: 17 additions & 8 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<PackAsTool>true</PackAsTool>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
Expand All @@ -15,7 +15,7 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.1.0-preview3</Version>
<Version>1.1.0</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand All @@ -37,18 +37,27 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.4" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.2.0-preview5" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.5" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.2.0-preview8" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj" />
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
</ItemGroup>

<!-- Make internals available for Unit Testing -->
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Microsoft.OpenApi.Hidi.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<!-- End Unit test Internals -->

</Project>
26 changes: 22 additions & 4 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using System.Xml.Xsl;
using System.Xml;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using System.Runtime.CompilerServices;

namespace Microsoft.OpenApi.Hidi
{
Expand All @@ -44,6 +46,7 @@ public static async Task TransformOpenApiDocument(
string? version,
OpenApiFormat? format,
bool terseOutput,
string settingsFile,
LogLevel logLevel,
bool inlineLocal,
bool inlineExternal,
Expand Down Expand Up @@ -98,7 +101,8 @@ CancellationToken cancellationToken
stream = ApplyFilter(csdl, csdlFilter, transform);
stream.Position = 0;
}
document = await ConvertCsdlToOpenApi(stream);

document = await ConvertCsdlToOpenApi(stream, settingsFile);
stopwatch.Stop();
logger.LogTrace("{timestamp}ms: Generated OpenAPI with {paths} paths.", stopwatch.ElapsedMilliseconds, document.Paths.Count);
}
Expand Down Expand Up @@ -304,25 +308,37 @@ public static async Task ValidateOpenApiDocument(
}
}

internal static IConfiguration GetConfiguration(string settingsFile)
{
settingsFile ??= "appsettings.json";

IConfiguration config = new ConfigurationBuilder()
.AddJsonFile(settingsFile, true)
.Build();

return config;
}

/// <summary>
/// Converts CSDL to OpenAPI
/// </summary>
/// <param name="csdl">The CSDL stream.</param>
/// <returns>An OpenAPI document.</returns>
public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl)
public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, string settingsFile = null)
{
using var reader = new StreamReader(csdl);
var csdlText = await reader.ReadToEndAsync();
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());


var config = GetConfiguration(settingsFile);
var settings = new OpenApiConvertSettings()
{
AddSingleQuotesForStringParameters = true,
AddEnumDescriptionExtension = true,
DeclarePathParametersOnPathItem = true,
EnableKeyAsSegment = true,
EnableOperationId = true,
ErrorResponsesAsDefault = false,
ErrorResponsesAsDefault = false,
PrefixEntityTypeNameBeforeKey = true,
TagDepth = 2,
EnablePagination = true,
Expand All @@ -335,6 +351,8 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl)
EnableCount = true,
UseSuccessStatusCodeRange = true
};
config.GetSection("OpenApiConvertSettings").Bind(settings);

OpenApiDocument document = edmModel.ConvertToOpenApi(settings);

document = FixReferences(document);
Expand Down
11 changes: 11 additions & 0 deletions src/Microsoft.OpenApi.Hidi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
// Licensed under the MIT license.

using System.CommandLine;
using System.CommandLine.Builder;
using System.CommandLine.Hosting;
using System.CommandLine.Parsing;

using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Hidi.Handlers;

Expand Down Expand Up @@ -41,6 +47,9 @@ static async Task Main(string[] args)
var terseOutputOption = new Option<bool>("--terse-output", "Produce terse json output");
terseOutputOption.AddAlias("--to");

var settingsFileOption = new Option<string>("--settings-path", "The configuration file with CSDL conversion settings.");
settingsFileOption.AddAlias("--sp");

var logLevelOption = new Option<LogLevel>("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output.");
logLevelOption.AddAlias("--ll");

Expand Down Expand Up @@ -81,6 +90,7 @@ static async Task Main(string[] args)
versionOption,
formatOption,
terseOutputOption,
settingsFileOption,
logLevelOption,
filterByOperationIdsOption,
filterByTagsOption,
Expand All @@ -99,6 +109,7 @@ static async Task Main(string[] args)
VersionOption = versionOption,
FormatOption = formatOption,
TerseOutputOption = terseOutputOption,
SettingsFileOption = settingsFileOption,
LogLevelOption = logLevelOption,
FilterByOperationIdsOption = filterByOperationIdsOption,
FilterByTagsOption = filterByTagsOption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi.Readers</Title>
<PackageId>Microsoft.OpenApi.Readers</PackageId>
<Version>1.4.4-preview1</Version>
<Version>1.4.4</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
18 changes: 11 additions & 7 deletions src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ public OpenApiReference ConvertToOpenApiReference(
catch (OpenApiException ex)
{
Diagnostic.Errors.Add(new OpenApiError(ex));
return null;
}
}
// Where fragments point into a non-OpenAPI document, the id will be the complete fragment identifier
string id = segments[1];
var openApiReference = new OpenApiReference();

// $ref: externalSource.yaml#/Pet
if (id.StartsWith("/components/"))
{
Expand All @@ -128,13 +129,16 @@ public OpenApiReference ConvertToOpenApiReference(
}
id = localSegments[3];
}

return new OpenApiReference
else
{
ExternalResource = segments[0],
Type = type,
Id = id
};
openApiReference.IsFragrament = true;
}

openApiReference.ExternalResource = segments[0];
openApiReference.Type = type;
openApiReference.Id = id;

return openApiReference;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.346202">
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.355802">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="6.0.0" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi</Title>
<PackageId>Microsoft.OpenApi</PackageId>
<Version>1.4.4-preview1</Version>
<Version>1.4.4</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
12 changes: 11 additions & 1 deletion src/Microsoft.OpenApi/Models/OpenApiReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class OpenApiReference : IOpenApiSerializable
/// </summary>
public bool IsLocal => ExternalResource == null;

/// <summary>
/// Gets a flag indicating whether a file is a valid OpenAPI document or a fragment
/// </summary>
public bool IsFragrament = false;

/// <summary>
/// The OpenApiDocument that is hosting the OpenApiReference instance. This is used to enable dereferencing the reference.
/// </summary>
Expand Down Expand Up @@ -196,7 +201,12 @@ private string GetExternalReferenceV3()
{
if (Id != null)
{
return ExternalResource + "#/components/" + Type.GetDisplayName() + "/"+ Id;
if (IsFragrament)
{
return ExternalResource + "#" + Id;
}

return ExternalResource + "#/components/" + Type.GetDisplayName() + "/"+ Id;
}

return ExternalResource;
Expand Down
Loading

0 comments on commit 656ac9a

Please sign in to comment.