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

Fixes bugs and failing tests #1503

Merged
merged 63 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
4bc07e3
Handle number overflow during parsing of min/max values
Robulane Nov 22, 2023
d06a89d
Merge pull request #1480 from Robulane/users/robulane/DontCrash
baywet Nov 22, 2023
47ef775
Configure the settings file path to be relative to the current workin…
MaggieKimani1 Nov 22, 2023
85dafb5
Upgrade lib versions
MaggieKimani1 Nov 22, 2023
9037ca4
Merge pull request #1481 from microsoft/mk/fix-hidi-relative-path
MaggieKimani1 Nov 22, 2023
fecac2a
Bump Verify.Xunit from 22.5.0 to 22.6.0
dependabot[bot] Nov 27, 2023
05c5615
Merge pull request #1483 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Nov 27, 2023
b786bc0
Update bug_report.md
MaggieKimani1 Nov 28, 2023
2e77c9c
Merge pull request #1484 from microsoft/mk/update-issue-template
MaggieKimani1 Nov 28, 2023
66b8167
Bump Moq from 4.20.69 to 4.20.70
dependabot[bot] Nov 28, 2023
57084f4
Merge pull request #1485 from microsoft/dependabot/nuget/Moq-4.20.70
baywet Nov 28, 2023
cf2106a
Update public API interface
MaggieKimani1 Nov 29, 2023
10c69a8
Create Json schema mappings with references in components
MaggieKimani1 Nov 29, 2023
1ac5b1b
Add spec version param for writing out $refs for different versions
MaggieKimani1 Nov 29, 2023
9ed4887
Clean up code and tests
MaggieKimani1 Nov 29, 2023
6c88daa
Remove dependency on external lib that uses YamlDotNet to reduce ambi…
MaggieKimani1 Nov 29, 2023
80e7d84
Throw an exception if referenced schema does not exist
MaggieKimani1 Nov 29, 2023
9198a2c
code cleanup
MaggieKimani1 Nov 29, 2023
bfacb4e
Bump Microsoft.OData.Edm from 7.18.0 to 7.19.0
dependabot[bot] Nov 30, 2023
d1cf89f
Merge pull request #1488 from microsoft/dependabot/nuget/Microsoft.OD…
baywet Nov 30, 2023
5b40826
Fix unresolved references in OpenApiWalker
dldl-cmd Dec 4, 2023
8a40801
Fix culture dependency in ParseDecimalWithFallbackOnOverflow_Overflow…
dldl-cmd Dec 4, 2023
c2ca883
Merge pull request #1492 from dldl-cmd/fix_ParseDecimalWithFallbackOn…
MaggieKimani1 Dec 4, 2023
ffc87ca
Use keyword examples instead of example
irvinesunday Dec 4, 2023
7aa2e32
Bump PublicApiGenerator from 11.0.0 to 11.1.0
dependabot[bot] Dec 4, 2023
030d397
Bump Verify.Xunit from 22.6.0 to 22.7.1
dependabot[bot] Dec 4, 2023
7c20dee
Bump actions/setup-java from 3 to 4
dependabot[bot] Dec 4, 2023
252d08c
Bump actions/setup-dotnet from 3 to 4
dependabot[bot] Dec 4, 2023
47636da
Merge pull request #1496 from microsoft/dependabot/github_actions/act…
baywet Dec 4, 2023
d3fa9ef
Merge pull request #1494 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Dec 4, 2023
7d49674
Merge pull request #1493 from microsoft/dependabot/nuget/PublicApiGen…
baywet Dec 4, 2023
f6777e4
Merge pull request #1495 from microsoft/dependabot/github_actions/act…
andrueastman Dec 5, 2023
2b1d082
Merge pull request #1491 from dldl-cmd/openapiwalker_references
MaggieKimani1 Dec 5, 2023
3e159d2
Serialize JsonSchema
irvinesunday Dec 5, 2023
ae52035
Refactor code to resolve Oneof and AnyOf schemas
MaggieKimani1 Dec 7, 2023
4ca2f87
Clean up tests
MaggieKimani1 Dec 7, 2023
6fd73a0
Removing irrelevant docs
timheuer Dec 7, 2023
3c76bf7
Merge pull request #1497 from timheuer/vnext
baywet Dec 7, 2023
8491402
Bump Verify.Xunit from 22.7.1 to 22.8.0
dependabot[bot] Dec 7, 2023
808c868
Merge pull request #1498 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Dec 7, 2023
fce5388
Bump Microsoft.OpenApi.OData from 1.5.0-preview9 to 1.5.0
dependabot[bot] Dec 8, 2023
05e43a4
Merge pull request #1500 from microsoft/dependabot/nuget/Microsoft.Op…
baywet Dec 8, 2023
2f7307f
Bump Microsoft.OData.Edm from 7.19.0 to 7.20.0
dependabot[bot] Dec 8, 2023
de67e95
Merge pull request #1499 from microsoft/dependabot/nuget/Microsoft.OD…
baywet Dec 9, 2023
0934c91
Bump xunit.runner.visualstudio from 2.5.4 to 2.5.5
dependabot[bot] Dec 11, 2023
9ad7599
Merge pull request #1501 from microsoft/dependabot/nuget/xunit.runner…
baywet Dec 11, 2023
3ebe0f0
Bump xunit from 2.6.2 to 2.6.3
dependabot[bot] Dec 11, 2023
ffd84ed
Merge pull request #1502 from microsoft/dependabot/nuget/xunit-2.6.3
baywet Dec 11, 2023
807890c
Merge remote-tracking branch 'origin/is/release/2.0.0/fix-breaking-te…
MaggieKimani1 Dec 13, 2023
964b751
Write out examples
MaggieKimani1 Dec 13, 2023
94d8c8a
Clean up tests
MaggieKimani1 Dec 13, 2023
f9aea51
Merge remote-tracking branch 'origin/vnext' into mk/fix-bugs-and-fail…
MaggieKimani1 Dec 13, 2023
8a48a77
Use ternary operator and compound assignment.
MaggieKimani1 Dec 13, 2023
d6a6b53
Update src/Microsoft.OpenApi/Validations/Rules/JsonSchemaRules.cs
MaggieKimani1 Dec 13, 2023
a9048c1
Update src/Microsoft.OpenApi/Validations/Rules/JsonSchemaRules.cs
MaggieKimani1 Dec 13, 2023
cb8288b
Update src/Microsoft.OpenApi/Validations/Rules/JsonSchemaRules.cs
MaggieKimani1 Dec 13, 2023
60d6993
Remove commented out code
MaggieKimani1 Dec 13, 2023
d190669
Merge branch 'mk/fix-bugs-and-failing-tests' of https://github.com/mi…
MaggieKimani1 Dec 13, 2023
0880d82
Remove null check
MaggieKimani1 Dec 13, 2023
dedf3a2
Use pattern matching and the native count extension method
MaggieKimani1 Dec 13, 2023
e585f4c
code cleanup
MaggieKimani1 Dec 13, 2023
0ed8e45
Apply suggestions from code review
baywet Dec 13, 2023
744d045
- updates public API
baywet Dec 13, 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
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ assignees: ''
**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the current behavior:
**OpenApi File To Reproduce**
Add the OpenApi file you're using or a link to it as well as the steps to reproduce the current behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
GITHUB_RUN_NUMBER: ${{ github.run_number }}
steps:
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x

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 @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ jobs:
runs-on: windows-latest
steps:
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 17
- name: Setup .NET 5 # At the moment the scanner requires dotnet 5 https://www.nuget.org/packages/dotnet-sonarscanner
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 5.0.x
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 7.0.x
- uses: actions/checkout@v4
Expand Down
81 changes: 0 additions & 81 deletions docs/CI-CD_DOCUMENTATION.md

This file was deleted.

Binary file removed docs/images/Actions_workflow_dispatch.png
Binary file not shown.
15 changes: 12 additions & 3 deletions src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ static PowerShellFormatter()
// 6. Add AdditionalProperties to object schemas.

public override void Visit(ref JsonSchema schema)
{
AddAdditionalPropertiesToSchema(schema);
{
AddAdditionalPropertiesToSchema(ref schema);
schema = ResolveAnyOfSchema(ref schema);
schema = ResolveOneOfSchema(ref schema);

Expand Down Expand Up @@ -174,7 +174,7 @@ private static IList<OpenApiParameter> ResolveFunctionParameters(IList<OpenApiPa
return parameters;
}

private void AddAdditionalPropertiesToSchema(JsonSchema schema)
private void AddAdditionalPropertiesToSchema(ref JsonSchema schema)
{
if (schema != null && !_schemaLoop.Contains(schema) && schema.GetJsonType().Equals(SchemaValueType.Object))
{
Expand All @@ -200,6 +200,7 @@ private void AddAdditionalPropertiesToSchema(JsonSchema schema)
_schemaLoop.Push(additionalProps);
}
}

}

private static JsonSchema ResolveOneOfSchema(ref JsonSchema schema)
Expand Down Expand Up @@ -254,6 +255,14 @@ private static JsonSchema FlattenSchema(JsonSchema schema, JsonSchema newSchema)
private static JsonSchema CopySchema(JsonSchema schema, JsonSchema newSchema)
{
var schemaBuilder = new JsonSchemaBuilder();
var keywords = schema.Keywords;
if (keywords != null)
{
foreach (var keyword in keywords)
{
schemaBuilder.Add(keyword);
}
}

if (schema.GetTitle() == null && newSchema.GetTitle() is { } title)
{
Expand Down
6 changes: 3 additions & 3 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.3.5</Version>
<Version>1.3.6</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 @@ -34,8 +34,8 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.18.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.5.0-preview9" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.20.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.5.0" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
</ItemGroup>
Expand Down
11 changes: 8 additions & 3 deletions src/Microsoft.OpenApi.Hidi/Utilities/SettingsUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.OpenApi.OData;

Expand All @@ -11,15 +12,19 @@ internal static class SettingsUtilities
internal static IConfiguration GetConfiguration(string? settingsFile = null)
{
if (string.IsNullOrEmpty(settingsFile))
{
settingsFile = "appsettings.json";
}

var settingsFilePath = Path.Combine(Directory.GetCurrentDirectory(), settingsFile);

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

return config;
}

internal static OpenApiConvertSettings GetOpenApiConvertSettings(IConfiguration config, string? metadataVersion)
{
if (config == null) { throw new System.ArgumentNullException(nameof(config)); }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.6.10</Version>
<Version>1.6.11</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 @@ -21,7 +21,6 @@
<PackageReference Include="JsonSchema.Net" Version="4.1.5" />
<PackageReference Include="JsonSchema.Net.OpenApi" Version="1.1.0" />
<PackageReference Include="SharpYaml" Version="2.1.0" />
<PackageReference Include="Yaml2JsonNode" Version="1.1.1" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
</ItemGroup>

Expand Down
52 changes: 52 additions & 0 deletions src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;
using Json.Schema;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -123,6 +124,57 @@ public override Dictionary<string, T> CreateMapWithReference<T>(
return nodes.Where(n => n != default).ToDictionary(k => k.key, v => v.value);
}

public override Dictionary<string, JsonSchema> CreateJsonSchemaMapWithReference(
ReferenceType referenceType,
Func<MapNode, JsonSchema> map,
OpenApiSpecVersion version)
{
var jsonMap = _node ?? throw new OpenApiReaderException($"Expected map while parsing {typeof(JsonSchema).Name}", Context);

var nodes = jsonMap.Select(
n =>
{
var key = n.Key;
(string key, JsonSchema value) entry;
try
{
Context.StartObject(key);
entry = (key,
value: map(new MapNode(Context, (JsonObject)n.Value))
);
if (entry.value == null)
{
return default; // Body Parameters shouldn't be converted to Parameters
}
// If the component isn't a reference to another component, then point it to itself.
if (entry.value.GetRef() == null)
{
var builder = new JsonSchemaBuilder();

// construct the Ref and append it to the builder
var reference = version == OpenApiSpecVersion.OpenApi2_0 ? string.Concat("#/definitions/", entry.key) :
string.Concat("#/components/schemas/", entry.key);

builder.Ref(reference);

// Append all the keywords in original schema to our new schema using a builder instance
foreach (var keyword in entry.value.Keywords)
{
builder.Add(keyword);
}
entry.value = builder.Build();
}
}
finally
{
Context.EndObject();
}
return entry;
}
);
return nodes.Where(n => n != default).ToDictionary(k => k.key, v => v.value);
}

public override Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
{
var jsonMap = _node ?? throw new OpenApiReaderException($"Expected map while parsing {typeof(T).Name}", Context);
Expand Down
11 changes: 10 additions & 1 deletion src/Microsoft.OpenApi.Readers/ParseNodes/ParseNode.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using Json.Schema;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -66,6 +67,14 @@ public virtual Dictionary<string, T> CreateMapWithReference<T>(
throw new OpenApiReaderException("Cannot create map from this reference.", Context);
}

public virtual Dictionary<string, JsonSchema> CreateJsonSchemaMapWithReference(
ReferenceType referenceType,
Func<MapNode, JsonSchema> map,
OpenApiSpecVersion version)
{
throw new OpenApiReaderException("Cannot create map from this reference.", Context);
}

public virtual List<T> CreateSimpleList<T>(Func<ValueNode, T> map)
{
throw new OpenApiReaderException("Cannot create simple list from this type of node.", Context);
Expand Down
35 changes: 35 additions & 0 deletions src/Microsoft.OpenApi.Readers/ParseNodes/ParserHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Globalization;

namespace Microsoft.OpenApi.Readers.ParseNodes
{
/// <summary>
/// Useful tools to parse data
/// </summary>
internal class ParserHelper
{
/// <summary>
/// Parses decimal in invariant culture.
/// If the decimal is too big or small, it returns the default value
///
/// Note: sometimes developers put Double.MaxValue or Long.MaxValue as min/max values for numbers in json schema even if their numbers are not expected to be that big/small.
/// As we have already released the library with Decimal type for Max/Min, let's not introduce the breaking change and just fallback to Decimal.Max / Min. This should satisfy almost every scenario.
/// We can revisit this if somebody really needs to have double or long here.
/// </summary>
/// <returns></returns>
public static decimal ParseDecimalWithFallbackOnOverflow(string value, decimal defaultValue)
{
try
{
return decimal.Parse(value, NumberStyles.Float, CultureInfo.InvariantCulture);
}
catch (OverflowException)
{
return defaultValue;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ internal static partial class OpenApiV2Deserializer
"definitions",
(o, n) =>
{
if (o.Components == null)
{
o.Components = new();
}

o.Components.Schemas = n.CreateMap(LoadSchema);
o.Components ??= new();
o.Components.Schemas = n.CreateJsonSchemaMapWithReference(ReferenceType.Schema, LoadSchema, OpenApiSpecVersion.OpenApi2_0);
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down
Loading
Loading