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/vnext to release2 #1893

Merged
merged 23 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ab886ef
Bump Microsoft.Extensions.Logging.Console from 8.0.0 to 8.0.1
dependabot[bot] Oct 9, 2024
eda44a9
Merge pull request #1867 from microsoft/dependabot/nuget/Microsoft.Ex…
baywet Oct 10, 2024
90b51e5
Bump Microsoft.Extensions.Logging.Debug from 8.0.0 to 8.0.1
dependabot[bot] Oct 10, 2024
81114ec
Merge pull request #1868 from microsoft/dependabot/nuget/Microsoft.Ex…
baywet Oct 10, 2024
dbf9beb
Bump Microsoft.OpenApi.OData from 2.0.0-preview.3 to 2.0.0-preview.4
dependabot[bot] Oct 10, 2024
11ff30b
Merge pull request #1869 from microsoft/dependabot/nuget/Microsoft.Op…
baywet Oct 11, 2024
9245685
ci: removes zengin since he doesn't have access to the repo anymore
baywet Oct 11, 2024
581a107
Merge pull request #1870 from microsoft/baywet-patch-1
baywet Oct 11, 2024
a27f1ef
Bumps conversion lib and hidi versions
irvinesunday Oct 11, 2024
36a4f35
Merge pull request #1871 from microsoft/is/bump-up-hidi
irvinesunday Oct 11, 2024
d4d5949
Bump Verify.Xunit from 26.6.0 to 27.0.1 (#1877)
dependabot[bot] Oct 15, 2024
41adb1f
chore(deps): bump Microsoft.OpenApi.OData
dependabot[bot] Oct 17, 2024
f6d3aca
Merge pull request #1882 from microsoft/dependabot/nuget/Microsoft.Op…
baywet Oct 18, 2024
7bf081f
chore(deps): bump Microsoft.OData.Edm from 8.0.2 to 8.1.0
dependabot[bot] Oct 18, 2024
cdbb6e7
Merge pull request #1881 from microsoft/dependabot/nuget/Microsoft.OD…
baywet Oct 18, 2024
df8cdc0
fix: emits number for integer formats
baywet Oct 18, 2024
9b28a5f
Bump Hidi
irvinesunday Oct 22, 2024
1676b19
Merge pull request #1883 from microsoft/fix/integer-type
baywet Oct 22, 2024
95e25ba
Merge pull request #1884 from microsoft/is/bump-hidi
irvinesunday Oct 22, 2024
c08c3b6
use nameof for CallerArgumentExpression
WeihanLi Oct 22, 2024
f2fb6cc
Merge pull request #1886 from WeihanLi/patch-1
MaggieKimani1 Oct 24, 2024
1e6e654
Merge branch 'vnext' into merge/vnext-to-release2
baywet Oct 24, 2024
fe13c56
fix: adds missing type mappings tests
baywet Oct 24, 2024
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
10 changes: 5 additions & 5 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.11</Version>
<Version>1.4.13</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 @@ -31,15 +31,15 @@
<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.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
<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.0.2" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.3" />
<PackageReference Include="Microsoft.OData.Edm" Version="8.1.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.6" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
<!--STJ
Expand Down
29 changes: 15 additions & 14 deletions src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
{
private static readonly Dictionary<Type, Func<OpenApiSchema>> _simpleTypeToOpenApiSchema = new()
{
[typeof(bool)] = () => new() { Type = "boolean" },

Check warning on line 17 in src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'boolean' 4 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
[typeof(byte)] = () => new() { Type = "string", Format = "byte" },

Check warning on line 18 in src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'string' 24 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
[typeof(int)] = () => new() { Type = "integer", Format = "int32" },
[typeof(uint)] = () => new() { Type = "integer", Format = "int32" },
[typeof(long)] = () => new() { Type = "integer", Format = "int64" },
[typeof(ulong)] = () => new() { Type = "integer", Format = "int64" },
[typeof(int)] = () => new() { Type = "number", Format = "int32" },

Check warning on line 19 in src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

View workflow job for this annotation

GitHub Actions / Build

Define a constant instead of using this literal 'number' 26 times. (https://rules.sonarsource.com/csharp/RSPEC-1192)
[typeof(uint)] = () => new() { Type = "number", Format = "int32" },
[typeof(long)] = () => new() { Type = "number", Format = "int64" },
[typeof(ulong)] = () => new() { Type = "number", Format = "int64" },
[typeof(float)] = () => new() { Type = "number", Format = "float" },
[typeof(double)] = () => new() { Type = "number", Format = "double" },
[typeof(decimal)] = () => new() { Type = "number", Format = "double" },
Expand All @@ -31,10 +31,10 @@
// Nullable types
[typeof(bool?)] = () => new() { Type = "boolean", Nullable = true },
[typeof(byte?)] = () => new() { Type = "string", Format = "byte", Nullable = true },
[typeof(int?)] = () => new() { Type = "integer", Format = "int32", Nullable = true },
[typeof(uint?)] = () => new() { Type = "integer", Format = "int32", Nullable = true },
[typeof(long?)] = () => new() { Type = "integer", Format = "int64", Nullable = true },
[typeof(ulong?)] = () => new() { Type = "integer", Format = "int64", Nullable = true },
[typeof(int?)] = () => new() { Type = "number", Format = "int32", Nullable = true },
[typeof(uint?)] = () => new() { Type = "number", Format = "int32", Nullable = true },
[typeof(long?)] = () => new() { Type = "number", Format = "int64", Nullable = true },
[typeof(ulong?)] = () => new() { Type = "number", Format = "int64", Nullable = true },
[typeof(float?)] = () => new() { Type = "number", Format = "float", Nullable = true },
[typeof(double?)] = () => new() { Type = "number", Format = "double", Nullable = true },
[typeof(decimal?)] = () => new() { Type = "number", Format = "double", Nullable = true },
Expand Down Expand Up @@ -98,9 +98,10 @@
var type = (schema.Type?.ToString().ToLowerInvariant(), schema.Format?.ToLowerInvariant(), schema.Nullable) switch
{
("boolean", null, false) => typeof(bool),
("integer", "int32", false) => typeof(int),
("integer", "int64", false) => typeof(long),
("integer", null, false) => typeof(int),
// integer is technically not valid with format, but we must provide some compatibility
("integer" or "number", "int32", false) => typeof(int),
("integer" or "number", "int64", false) => typeof(long),
("integer", null, false) => typeof(long),
("number", "float", false) => typeof(float),
("number", "double", false) => typeof(double),
("number", "decimal", false) => typeof(decimal),
Expand All @@ -113,9 +114,9 @@
("string", null, false) => typeof(string),
("object", null, false) => typeof(object),
("string", "uri", false) => typeof(Uri),
("integer", "int32", true) => typeof(int?),
("integer", "int64", true) => typeof(long?),
("integer", null, true) => typeof(int?),
("integer" or "number", "int32", true) => typeof(int?),
("integer" or "number", "int64", true) => typeof(long?),
("integer", null, true) => typeof(long?),
("number", "float", true) => typeof(float?),
("number", "double", true) => typeof(double?),
("number", null, true) => typeof(double?),
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static class Utils
/// <returns>The input value.</returns>
internal static T CheckArgumentNull<T>(
T value,
[CallerArgumentExpression("value")] string parameterName = "")
[CallerArgumentExpression(nameof(value))] string parameterName = "")
{
return value ?? throw new ArgumentNullException(parameterName, $"Value cannot be null: {parameterName}");
}
Expand Down
24 changes: 12 additions & 12 deletions src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && format == "int32")
if (type is "integer" or "number" && format is "int32")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -149,7 +149,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && format == "int64")
if (type is "integer" or "number" && format is "int64")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -161,7 +161,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && jsonElement.ValueKind is not JsonValueKind.Number)
if (type is "integer")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -173,7 +173,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "number" && format == "float")
if (type is "number" && format is "float")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -185,7 +185,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "number" && format == "double")
if (type is "number" && format is "double")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -197,7 +197,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "number")
if (type is "number")
{
if (jsonElement.ValueKind is not JsonValueKind.Number)
{
Expand All @@ -209,7 +209,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string" && format == "byte")
if (type is "string" && format is "byte")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -221,7 +221,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string" && format == "date")
if (type is "string" && format is "date")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -233,7 +233,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string" && format == "date-time")
if (type is "string" && format is "date-time")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -245,7 +245,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string" && format == "password")
if (type is "string" && format is "password")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -257,7 +257,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "string")
if (type is "string")
{
if (jsonElement.ValueKind is not JsonValueKind.String)
{
Expand All @@ -269,7 +269,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "boolean")
if (type is "boolean")
{
if (jsonElement.ValueKind is not JsonValueKind.True && jsonElement.ValueKind is not JsonValueKind.False)
{
Expand Down
25 changes: 16 additions & 9 deletions test/Microsoft.OpenApi.Tests/Extensions/OpenApiTypeMapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@ public class OpenApiTypeMapperTests
{
public static IEnumerable<object[]> PrimitiveTypeData => new List<object[]>
{
new object[] { typeof(int), new OpenApiSchema { Type = "integer", Format = "int32" } },
new object[] { typeof(int), new OpenApiSchema { Type = "number", Format = "int32" } },
new object[] { typeof(decimal), new OpenApiSchema { Type = "number", Format = "double" } },
new object[] { typeof(decimal?), new OpenApiSchema { Type = "number", Format = "double", Nullable = true } },
new object[] { typeof(bool?), new OpenApiSchema { Type = "boolean", Nullable = true } },
new object[] { typeof(Guid), new OpenApiSchema { Type = "string", Format = "uuid" } },
new object[] { typeof(uint), new OpenApiSchema { Type = "integer", Format = "int32" } },
new object[] { typeof(long), new OpenApiSchema { Type = "integer", Format = "int64" } },
new object[] { typeof(ulong), new OpenApiSchema { Type = "integer", Format = "int64" } },
new object[] { typeof(Guid?), new OpenApiSchema { Type = "string", Format = "uuid", Nullable = true } },
new object[] { typeof(uint), new OpenApiSchema { Type = "number", Format = "int32" } },
new object[] { typeof(long), new OpenApiSchema { Type = "number", Format = "int64" } },
new object[] { typeof(long?), new OpenApiSchema { Type = "number", Format = "int64", Nullable = true } },
new object[] { typeof(ulong), new OpenApiSchema { Type = "number", Format = "int64" } },
new object[] { typeof(string), new OpenApiSchema { Type = "string" } },
new object[] { typeof(double), new OpenApiSchema { Type = "number", Format = "double" } },
new object[] { typeof(float?), new OpenApiSchema { Type = "number", Format = "float", Nullable = true } },
new object[] { typeof(byte?), new OpenApiSchema { Type = "string", Format = "byte", Nullable = true } },
new object[] { typeof(int?), new OpenApiSchema { Type = "integer", Format = "int32", Nullable = true } },
new object[] { typeof(uint?), new OpenApiSchema { Type = "integer", Format = "int32", Nullable = true } },
new object[] { typeof(int?), new OpenApiSchema { Type = "number", Format = "int32", Nullable = true } },
new object[] { typeof(uint?), new OpenApiSchema { Type = "number", Format = "int32", Nullable = true } },
new object[] { typeof(DateTimeOffset?), new OpenApiSchema { Type = "string", Format = "date-time", Nullable = true } },
new object[] { typeof(double?), new OpenApiSchema { Type = "number", Format = "double", Nullable = true } },
new object[] { typeof(char?), new OpenApiSchema { Type = "string", Nullable = true } },
Expand All @@ -35,11 +38,15 @@ public class OpenApiTypeMapperTests

public static IEnumerable<object[]> OpenApiDataTypes => new List<object[]>
{
new object[] { new OpenApiSchema { Type = "integer", Format = "int32"}, typeof(int) },
new object[] { new OpenApiSchema { Type = "number", Format = "int32", Nullable = false}, typeof(int) },
new object[] { new OpenApiSchema { Type = "number", Format = "int32", Nullable = true}, typeof(int?) },
new object[] { new OpenApiSchema { Type = "number", Format = "int64", Nullable = false}, typeof(long) },
new object[] { new OpenApiSchema { Type = "number", Format = "int64", Nullable = true}, typeof(long?) },
new object[] { new OpenApiSchema { Type = "number", Format = "decimal"}, typeof(decimal) },
new object[] { new OpenApiSchema { Type = "integer", Format = null, Nullable = false}, typeof(long) },
new object[] { new OpenApiSchema { Type = "integer", Format = null, Nullable = true}, typeof(long?) },
new object[] { new OpenApiSchema { Type = "number", Format = null, Nullable = false}, typeof(double) },
new object[] { new OpenApiSchema { Type = "integer", Format = null, Nullable = false}, typeof(int) },
new object[] { new OpenApiSchema { Type = "integer", Format = null, Nullable = true}, typeof(int?) },
new object[] { new OpenApiSchema { Type = "number", Format = null, Nullable = true}, typeof(double?) },
new object[] { new OpenApiSchema { Type = "number", Format = "decimal", Nullable = true}, typeof(decimal?) },
new object[] { new OpenApiSchema { Type = "number", Format = "double", Nullable = true}, typeof(double?) },
new object[] { new OpenApiSchema { Type = "string", Format = "date-time", Nullable = true}, typeof(DateTimeOffset?) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="Moq" Version="4.20.72" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="SharpYaml" Version="2.1.1" />
<PackageReference Include="Verify.Xunit" Version="26.6.0" />
<PackageReference Include="Verify.Xunit" Version="27.0.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
Expand Down
Loading