Skip to content

Commit

Permalink
Merge pull request #1885 from microsoft/vnext
Browse files Browse the repository at this point in the history
Release Hidi lib.
  • Loading branch information
irvinesunday authored Oct 22, 2024
2 parents 97f8450 + 95e25ba commit 8c64b50
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
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.4.12</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 Down Expand Up @@ -38,8 +38,8 @@
<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.5" />
<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
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
}
else
{
if (type == "integer" && format == "int32")
if (type is "integer" or "number" && format == "int32")
{
if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var intValue))
{
return new OpenApiInteger(intValue);
}
}

if (type == "integer" && format == "int64")
if (type is "integer" or "number" && format == "int64")
{
if (long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out var longValue))
{
Expand Down
25 changes: 13 additions & 12 deletions src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public static class OpenApiTypeMapper
{
[typeof(bool)] = () => new() { Type = "boolean" },
[typeof(byte)] = () => new() { Type = "string", Format = "byte" },
[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" },
[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 @@ public static class OpenApiTypeMapper
// 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,8 +98,9 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
var type = (schema.Type?.ToLowerInvariant(), schema.Format?.ToLowerInvariant(), schema.Nullable) switch
{
("boolean", null, false) => typeof(bool),
("integer", "int32", false) => typeof(int),
("integer", "int64", false) => typeof(long),
// 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(int),
("number", "float", false) => typeof(float),
("number", "double", false) => typeof(double),
Expand All @@ -113,8 +114,8 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
("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" or "number", "int32", true) => typeof(int?),
("integer" or "number", "int64", true) => typeof(long?),
("integer", null, true) => typeof(int?),
("number", "float", true) => typeof(float?),
("number", "double", true) => typeof(double?),
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && format == "int32")
if (type is "integer" or "number" && format == "int32")
{
if (value is not OpenApiInteger)
{
Expand All @@ -146,7 +146,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && format == "int64")
if (type is "integer" or "number" && format == "int64")
{
if (value is not OpenApiLong)
{
Expand All @@ -158,7 +158,7 @@ public static void ValidateDataTypeMismatch(
return;
}

if (type == "integer" && value is not OpenApiInteger)
if (type is "integer" && value is not OpenApiInteger)
{
if (value is not OpenApiInteger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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(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 } },
Expand All @@ -24,6 +24,7 @@ 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"}, typeof(int) },
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 = "string" }, typeof(string) },
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

0 comments on commit 8c64b50

Please sign in to comment.