Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge latest changes into master #1199

Merged
merged 23 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a5e91a5
Bump Newtonsoft.Json from 13.0.2 to 13.0.3
dependabot[bot] Mar 8, 2023
f3a74e3
Merge pull request #1184 from microsoft/dependabot/nuget/Newtonsoft.J…
baywet Mar 8, 2023
ac15d22
Bump Verify.Xunit from 19.10.0 to 19.11.0
dependabot[bot] Mar 10, 2023
f2c6ab9
Merge pull request #1186 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Mar 10, 2023
84f8318
Bump Verify.Xunit from 19.11.0 to 19.11.1
dependabot[bot] Mar 13, 2023
5137545
Merge pull request #1187 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Mar 13, 2023
416b8ce
Bump Microsoft.OpenApi.OData from 1.3.0-preview2 to 1.3.0-preview3
dependabot[bot] Mar 21, 2023
48f56b0
Bump Verify.Xunit from 19.11.1 to 19.11.2
dependabot[bot] Mar 21, 2023
a926c4b
Merge pull request #1188 from microsoft/dependabot/nuget/Microsoft.Op…
baywet Mar 21, 2023
5cad512
Merge pull request #1189 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Mar 22, 2023
5801f23
Bump Microsoft.OpenApi.OData from 1.3.0-preview3 to 1.3.0-preview4
dependabot[bot] Mar 23, 2023
db02b95
Merge pull request #1190 from microsoft/dependabot/nuget/Microsoft.Op…
baywet Mar 23, 2023
61fd3f7
OpenApiOperation constructor preserve null
Mar 28, 2023
d479ec3
Update src/Microsoft.OpenApi/Models/OpenApiOperation.cs
MaggieKimani1 Mar 29, 2023
746fe68
Merge pull request #1195 from dldl-cmd/openapioperation-copy-construc…
MaggieKimani1 Mar 29, 2023
9765d06
Adds a metadata version parameter as a commandline option
MaggieKimani1 Mar 29, 2023
03870b5
Bump lib to latest version
MaggieKimani1 Mar 29, 2023
667f241
Clean up tests
MaggieKimani1 Mar 29, 2023
4e6a986
Update path count for test to pass
MaggieKimani1 Mar 29, 2023
8befb81
Update src/Microsoft.OpenApi.Hidi/Program.cs
MaggieKimani1 Mar 29, 2023
c049346
Merge pull request #1197 from microsoft/mk/add-version-command-option
MaggieKimani1 Mar 29, 2023
b854063
Update lib versions
MaggieKimani1 Mar 30, 2023
d432567
Merge pull request #1198 from microsoft/mk/lib-version-upgrade
MaggieKimani1 Mar 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ internal class TransformCommandHandler : ICommandHandler
public Option<FileInfo> OutputOption { get; set; }
public Option<bool> CleanOutputOption { get; set; }
public Option<string?> VersionOption { get; set; }
public Option<string?> MetadataVersionOption { get; set; }
public Option<OpenApiFormat?> FormatOption { get; set; }
public Option<bool> TerseOutputOption { get; set; }
public Option<string> SettingsFileOption { get; set; }
Expand All @@ -41,6 +42,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
FileInfo output = context.ParseResult.GetValueForOption(OutputOption);
bool cleanOutput = context.ParseResult.GetValueForOption(CleanOutputOption);
string? version = context.ParseResult.GetValueForOption(VersionOption);
string metadataVersion = context.ParseResult.GetValueForOption(MetadataVersionOption);
OpenApiFormat? format = context.ParseResult.GetValueForOption(FormatOption);
bool terseOutput = context.ParseResult.GetValueForOption(TerseOutputOption);
string settingsFile = context.ParseResult.GetValueForOption(SettingsFileOption);
Expand All @@ -57,7 +59,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, settingsFile, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, logger, cancellationToken);
await OpenApiService.TransformOpenApiDocument(openapi, csdl, csdlFilter, output, cleanOutput, version, metadataVersion, format, terseOutput, settingsFile, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, logger, cancellationToken);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<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.15.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.3.0-preview2" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.3.0" />
MaggieKimani1 marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
</ItemGroup>

Expand Down
19 changes: 12 additions & 7 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security;
Expand All @@ -20,7 +19,6 @@
using Microsoft.OpenApi.OData;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Validations;
using Microsoft.OpenApi.Writers;
using static Microsoft.OpenApi.Hidi.OpenApiSpecVersionHelper;
using System.Threading;
Expand All @@ -43,6 +41,7 @@ public static async Task TransformOpenApiDocument(
FileInfo output,
bool cleanoutput,
string? version,
string metadataVersion,
OpenApiFormat? format,
bool terseOutput,
string settingsFile,
Expand Down Expand Up @@ -81,7 +80,7 @@ CancellationToken cancellationToken
OpenApiFormat openApiFormat = format ?? (!string.IsNullOrEmpty(openapi) ? GetOpenApiFormat(openapi, logger) : OpenApiFormat.Yaml);
OpenApiSpecVersion openApiVersion = version != null ? TryParseOpenApiSpecVersion(version) : OpenApiSpecVersion.OpenApi3_0;

OpenApiDocument document = await GetOpenApi(openapi, csdl, csdlFilter, settingsFile, inlineExternal, logger, cancellationToken);
OpenApiDocument document = await GetOpenApi(openapi, csdl, csdlFilter, settingsFile, inlineExternal, logger, cancellationToken, metadataVersion);
document = await FilterOpenApiDocument(filterbyoperationids, filterbytags, filterbycollection, document, logger, cancellationToken);
WriteOpenApi(output, terseOutput, inlineLocal, inlineExternal, openApiFormat, openApiVersion, document, logger);
}
Expand Down Expand Up @@ -132,11 +131,11 @@ private static void WriteOpenApi(FileInfo output, bool terseOutput, bool inlineL
}

// Get OpenAPI document either from OpenAPI or CSDL
private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csdl, string csdlFilter, string settingsFile, bool inlineExternal, ILogger logger, CancellationToken cancellationToken)
private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csdl, string csdlFilter, string settingsFile, bool inlineExternal, ILogger logger, CancellationToken cancellationToken, string metadataVersion = null)
{
OpenApiDocument document;
Stream stream;

if (!string.IsNullOrEmpty(csdl))
{
var stopwatch = new Stopwatch();
Expand All @@ -154,7 +153,7 @@ private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csd
stream = null;
}

document = await ConvertCsdlToOpenApi(filteredStream ?? stream, settingsFile, cancellationToken);
document = await ConvertCsdlToOpenApi(filteredStream ?? stream, metadataVersion, settingsFile, cancellationToken);
stopwatch.Stop();
logger.LogTrace("{timestamp}ms: Generated OpenAPI with {paths} paths.", stopwatch.ElapsedMilliseconds, document.Paths.Count);
}
Expand Down Expand Up @@ -317,14 +316,20 @@ internal static IConfiguration GetConfiguration(string settingsFile)
/// </summary>
/// <param name="csdl">The CSDL stream.</param>
/// <returns>An OpenAPI document.</returns>
public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, string settingsFile = null, CancellationToken token = default)
public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, string metadataVersion = null, string settingsFile = null, CancellationToken token = default)
{
using var reader = new StreamReader(csdl);
var csdlText = await reader.ReadToEndAsync(token);
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());

var config = GetConfiguration(settingsFile);
var settings = new OpenApiConvertSettings();

if (!string.IsNullOrEmpty(metadataVersion))
{
settings.SemVerVersion = metadataVersion;
}

config.GetSection("OpenApiConvertSettings").Bind(settings);

OpenApiDocument document = edmModel.ConvertToOpenApi(settings);
Expand Down
7 changes: 6 additions & 1 deletion src/Microsoft.OpenApi.Hidi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ internal static RootCommand CreateRootCommand()
var versionOption = new Option<string?>("--version", "OpenAPI specification version");
versionOption.AddAlias("-v");

var metadataVersionOption = new Option<string?>("--metadata-version", "Graph metadata version to use.");
metadataVersionOption.AddAlias("--mv");

var formatOption = new Option<OpenApiFormat?>("--format", "File format");
formatOption.AddAlias("-f");

var terseOutputOption = new Option<bool>("--terse-output", "Produce terse json output");
terseOutputOption.AddAlias("--to");

Expand Down Expand Up @@ -93,6 +96,7 @@ internal static RootCommand CreateRootCommand()
outputOption,
cleanOutputOption,
versionOption,
metadataVersionOption,
formatOption,
terseOutputOption,
settingsFileOption,
Expand All @@ -112,6 +116,7 @@ internal static RootCommand CreateRootCommand()
OutputOption = outputOption,
CleanOutputOption = cleanOutputOption,
VersionOption = versionOption,
MetadataVersionOption = metadataVersionOption,
FormatOption = formatOption,
TerseOutputOption = terseOutputOption,
SettingsFileOption = settingsFileOption,
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ public OpenApiOperation() {}
/// </summary>
public OpenApiOperation(OpenApiOperation operation)
{
Tags = new List<OpenApiTag>(operation?.Tags);
Tags = operation?.Tags != null ? new List<OpenApiTag>(operation?.Tags) : null;
Summary = operation?.Summary ?? Summary;
Description = operation?.Description ?? Description;
ExternalDocs = operation?.ExternalDocs != null ? new(operation?.ExternalDocs) : null;
OperationId = operation?.OperationId ?? OperationId;
Parameters = operation?.Parameters != null ? new List<OpenApiParameter>(operation.Parameters) : null;
RequestBody = new(operation?.RequestBody);
RequestBody = operation?.RequestBody != null ? new(operation?.RequestBody) : null;
Responses = operation?.Responses != null ? new(operation?.Responses) : null;
Callbacks = operation?.Callbacks != null ? new Dictionary<string, OpenApiCallback>(operation.Callbacks) : null;
Deprecated = operation?.Deprecated ?? Deprecated;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ public void SerializeAsV3WithoutReference(IOpenApiWriter writer)
// style
if (_style.HasValue)
{
writer.WriteProperty(OpenApiConstants.Style, Style.Value.GetDisplayName());
writer.WriteProperty(OpenApiConstants.Style, _style.Value.GetDisplayName());
}

// explode
writer.WriteProperty(OpenApiConstants.Explode, Explode, Style.HasValue && Style.Value == ParameterStyle.Form);
writer.WriteProperty(OpenApiConstants.Explode, _explode, _style.HasValue && _style.Value == ParameterStyle.Form);

// allowReserved
writer.WriteProperty(OpenApiConstants.AllowReserved, AllowReserved, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public async Task ReturnConvertedCSDLFile()
}

[Theory]
[InlineData("Todos.Todo.UpdateTodo",null, 1)]
[InlineData("Todos.Todo.UpdateTodo", null, 1)]
[InlineData("Todos.Todo.ListTodo", null, 1)]
[InlineData(null, "Todos.Todo", 4)]
[InlineData(null, "Todos.Todo", 5)]
public async Task ReturnFilteredOpenApiDocBasedOnOperationIdsAndInputCsdlDocument(string operationIds, string tags, int expectedPathCount)
{
// Arrange
Expand Down Expand Up @@ -190,7 +190,7 @@ public async Task TransformCommandConvertsOpenApi()
{
var fileinfo = new FileInfo("sample.json");
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument("UtilityFiles\\SampleOpenApi.yml",null, null, fileinfo, true, null, null,false,null,false,false,null,null,null,new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());
await OpenApiService.TransformOpenApiDocument("UtilityFiles\\SampleOpenApi.yml",null, null, fileinfo, true, null, null, null,false,null,false,false,null,null,null,new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());

var output = File.ReadAllText("sample.json");
Assert.NotEmpty(output);
Expand All @@ -201,7 +201,7 @@ public async Task TransformCommandConvertsOpenApi()
public async Task TransformCommandConvertsOpenApiWithDefaultOutputname()
{
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument("UtilityFiles\\SampleOpenApi.yml", null, null, null, true, null, null, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());
await OpenApiService.TransformOpenApiDocument("UtilityFiles\\SampleOpenApi.yml", null, null, null, true, null, null, null, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());

var output = File.ReadAllText("output.yml");
Assert.NotEmpty(output);
Expand All @@ -211,7 +211,7 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputname()
public async Task TransformCommandConvertsCsdlWithDefaultOutputname()
{
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument(null, "UtilityFiles\\Todo.xml", null, null, true, null, null, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());
await OpenApiService.TransformOpenApiDocument(null, "UtilityFiles\\Todo.xml", null, null, true, null, null, null, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());

var output = File.ReadAllText("output.yml");
Assert.NotEmpty(output);
Expand All @@ -221,7 +221,7 @@ public async Task TransformCommandConvertsCsdlWithDefaultOutputname()
public async Task TransformCommandConvertsOpenApiWithDefaultOutputnameAndSwitchFormat()
{
// create a dummy ILogger instance for testing
await OpenApiService.TransformOpenApiDocument("UtilityFiles\\SampleOpenApi.yml", null, null, null, true, "3.0", OpenApiFormat.Yaml, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());
await OpenApiService.TransformOpenApiDocument("UtilityFiles\\SampleOpenApi.yml", null, null, null, true, "3.0", null, OpenApiFormat.Yaml, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken());

var output = File.ReadAllText("output.yml");
Assert.NotEmpty(output);
Expand All @@ -231,7 +231,7 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputnameAndSwitchF
public async Task ThrowTransformCommandIfOpenApiAndCsdlAreEmpty()
{
await Assert.ThrowsAsync<ArgumentException>(async () =>
await OpenApiService.TransformOpenApiDocument(null, null, null, null, true, null, null, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken()));
await OpenApiService.TransformOpenApiDocument(null, null, null, null, true, null, null, null, false, null, false, false, null, null, null, new Logger<OpenApiService>(new LoggerFactory()), new CancellationToken()));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="FluentAssertions" Version="6.10.0">
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2">
<PackageReference Include="Newtonsoft.Json" Version="13.0.3">
</PackageReference>
<PackageReference Include="SharpYaml" Version="2.1.0">
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
<PackageReference Include="FluentAssertions" Version="6.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SharpYaml" Version="2.1.0" />
<PackageReference Include="Verify.Xunit" Version="19.10.0" />
<PackageReference Include="Verify.Xunit" Version="19.11.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading