Skip to content

Commit ab0ecf9

Browse files
authored
Merge pull request #1893 from microsoft/merge/vnext-to-release2
merge/vnext to release2
2 parents c3373af + fe13c56 commit ab0ecf9

File tree

6 files changed

+50
-42
lines changed

6 files changed

+50
-42
lines changed

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Nullable>enable</Nullable>
1010
<ToolCommandName>hidi</ToolCommandName>
1111
<PackageOutputPath>./../../artifacts</PackageOutputPath>
12-
<Version>1.4.11</Version>
12+
<Version>1.4.13</Version>
1313
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
1414
<SignAssembly>true</SignAssembly>
1515
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
@@ -31,15 +31,15 @@
3131
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
3232
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
3333
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
34-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
35-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
34+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
35+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
3636
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20">
3737
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3838
<PrivateAssets>all</PrivateAssets>
3939
</PackageReference>
4040
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
41-
<PackageReference Include="Microsoft.OData.Edm" Version="8.0.2" />
42-
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.3" />
41+
<PackageReference Include="Microsoft.OData.Edm" Version="8.1.0" />
42+
<PackageReference Include="Microsoft.OpenApi.OData" Version="2.0.0-preview.6" />
4343
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
4444
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
4545
<!--STJ

src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public static class OpenApiTypeMapper
1616
{
1717
[typeof(bool)] = () => new() { Type = "boolean" },
1818
[typeof(byte)] = () => new() { Type = "string", Format = "byte" },
19-
[typeof(int)] = () => new() { Type = "integer", Format = "int32" },
20-
[typeof(uint)] = () => new() { Type = "integer", Format = "int32" },
21-
[typeof(long)] = () => new() { Type = "integer", Format = "int64" },
22-
[typeof(ulong)] = () => new() { Type = "integer", Format = "int64" },
19+
[typeof(int)] = () => new() { Type = "number", Format = "int32" },
20+
[typeof(uint)] = () => new() { Type = "number", Format = "int32" },
21+
[typeof(long)] = () => new() { Type = "number", Format = "int64" },
22+
[typeof(ulong)] = () => new() { Type = "number", Format = "int64" },
2323
[typeof(float)] = () => new() { Type = "number", Format = "float" },
2424
[typeof(double)] = () => new() { Type = "number", Format = "double" },
2525
[typeof(decimal)] = () => new() { Type = "number", Format = "double" },
@@ -31,10 +31,10 @@ public static class OpenApiTypeMapper
3131
// Nullable types
3232
[typeof(bool?)] = () => new() { Type = "boolean", Nullable = true },
3333
[typeof(byte?)] = () => new() { Type = "string", Format = "byte", Nullable = true },
34-
[typeof(int?)] = () => new() { Type = "integer", Format = "int32", Nullable = true },
35-
[typeof(uint?)] = () => new() { Type = "integer", Format = "int32", Nullable = true },
36-
[typeof(long?)] = () => new() { Type = "integer", Format = "int64", Nullable = true },
37-
[typeof(ulong?)] = () => new() { Type = "integer", Format = "int64", Nullable = true },
34+
[typeof(int?)] = () => new() { Type = "number", Format = "int32", Nullable = true },
35+
[typeof(uint?)] = () => new() { Type = "number", Format = "int32", Nullable = true },
36+
[typeof(long?)] = () => new() { Type = "number", Format = "int64", Nullable = true },
37+
[typeof(ulong?)] = () => new() { Type = "number", Format = "int64", Nullable = true },
3838
[typeof(float?)] = () => new() { Type = "number", Format = "float", Nullable = true },
3939
[typeof(double?)] = () => new() { Type = "number", Format = "double", Nullable = true },
4040
[typeof(decimal?)] = () => new() { Type = "number", Format = "double", Nullable = true },
@@ -98,9 +98,10 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
9898
var type = (schema.Type?.ToString().ToLowerInvariant(), schema.Format?.ToLowerInvariant(), schema.Nullable) switch
9999
{
100100
("boolean", null, false) => typeof(bool),
101-
("integer", "int32", false) => typeof(int),
102-
("integer", "int64", false) => typeof(long),
103-
("integer", null, false) => typeof(int),
101+
// integer is technically not valid with format, but we must provide some compatibility
102+
("integer" or "number", "int32", false) => typeof(int),
103+
("integer" or "number", "int64", false) => typeof(long),
104+
("integer", null, false) => typeof(long),
104105
("number", "float", false) => typeof(float),
105106
("number", "double", false) => typeof(double),
106107
("number", "decimal", false) => typeof(decimal),
@@ -113,9 +114,9 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
113114
("string", null, false) => typeof(string),
114115
("object", null, false) => typeof(object),
115116
("string", "uri", false) => typeof(Uri),
116-
("integer", "int32", true) => typeof(int?),
117-
("integer", "int64", true) => typeof(long?),
118-
("integer", null, true) => typeof(int?),
117+
("integer" or "number", "int32", true) => typeof(int?),
118+
("integer" or "number", "int64", true) => typeof(long?),
119+
("integer", null, true) => typeof(long?),
119120
("number", "float", true) => typeof(float?),
120121
("number", "double", true) => typeof(double?),
121122
("number", null, true) => typeof(double?),

src/Microsoft.OpenApi/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal static class Utils
2020
/// <returns>The input value.</returns>
2121
internal static T CheckArgumentNull<T>(
2222
T value,
23-
[CallerArgumentExpression("value")] string parameterName = "")
23+
[CallerArgumentExpression(nameof(value))] string parameterName = "")
2424
{
2525
return value ?? throw new ArgumentNullException(parameterName, $"Value cannot be null: {parameterName}");
2626
}

src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static void ValidateDataTypeMismatch(
137137
return;
138138
}
139139

140-
if (type == "integer" && format == "int32")
140+
if (type is "integer" or "number" && format is "int32")
141141
{
142142
if (jsonElement.ValueKind is not JsonValueKind.Number)
143143
{
@@ -149,7 +149,7 @@ public static void ValidateDataTypeMismatch(
149149
return;
150150
}
151151

152-
if (type == "integer" && format == "int64")
152+
if (type is "integer" or "number" && format is "int64")
153153
{
154154
if (jsonElement.ValueKind is not JsonValueKind.Number)
155155
{
@@ -161,7 +161,7 @@ public static void ValidateDataTypeMismatch(
161161
return;
162162
}
163163

164-
if (type == "integer" && jsonElement.ValueKind is not JsonValueKind.Number)
164+
if (type is "integer")
165165
{
166166
if (jsonElement.ValueKind is not JsonValueKind.Number)
167167
{
@@ -173,7 +173,7 @@ public static void ValidateDataTypeMismatch(
173173
return;
174174
}
175175

176-
if (type == "number" && format == "float")
176+
if (type is "number" && format is "float")
177177
{
178178
if (jsonElement.ValueKind is not JsonValueKind.Number)
179179
{
@@ -185,7 +185,7 @@ public static void ValidateDataTypeMismatch(
185185
return;
186186
}
187187

188-
if (type == "number" && format == "double")
188+
if (type is "number" && format is "double")
189189
{
190190
if (jsonElement.ValueKind is not JsonValueKind.Number)
191191
{
@@ -197,7 +197,7 @@ public static void ValidateDataTypeMismatch(
197197
return;
198198
}
199199

200-
if (type == "number")
200+
if (type is "number")
201201
{
202202
if (jsonElement.ValueKind is not JsonValueKind.Number)
203203
{
@@ -209,7 +209,7 @@ public static void ValidateDataTypeMismatch(
209209
return;
210210
}
211211

212-
if (type == "string" && format == "byte")
212+
if (type is "string" && format is "byte")
213213
{
214214
if (jsonElement.ValueKind is not JsonValueKind.String)
215215
{
@@ -221,7 +221,7 @@ public static void ValidateDataTypeMismatch(
221221
return;
222222
}
223223

224-
if (type == "string" && format == "date")
224+
if (type is "string" && format is "date")
225225
{
226226
if (jsonElement.ValueKind is not JsonValueKind.String)
227227
{
@@ -233,7 +233,7 @@ public static void ValidateDataTypeMismatch(
233233
return;
234234
}
235235

236-
if (type == "string" && format == "date-time")
236+
if (type is "string" && format is "date-time")
237237
{
238238
if (jsonElement.ValueKind is not JsonValueKind.String)
239239
{
@@ -245,7 +245,7 @@ public static void ValidateDataTypeMismatch(
245245
return;
246246
}
247247

248-
if (type == "string" && format == "password")
248+
if (type is "string" && format is "password")
249249
{
250250
if (jsonElement.ValueKind is not JsonValueKind.String)
251251
{
@@ -257,7 +257,7 @@ public static void ValidateDataTypeMismatch(
257257
return;
258258
}
259259

260-
if (type == "string")
260+
if (type is "string")
261261
{
262262
if (jsonElement.ValueKind is not JsonValueKind.String)
263263
{
@@ -269,7 +269,7 @@ public static void ValidateDataTypeMismatch(
269269
return;
270270
}
271271

272-
if (type == "boolean")
272+
if (type is "boolean")
273273
{
274274
if (jsonElement.ValueKind is not JsonValueKind.True && jsonElement.ValueKind is not JsonValueKind.False)
275275
{

test/Microsoft.OpenApi.Tests/Extensions/OpenApiTypeMapperTests.cs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,22 @@ public class OpenApiTypeMapperTests
1414
{
1515
public static IEnumerable<object[]> PrimitiveTypeData => new List<object[]>
1616
{
17-
new object[] { typeof(int), new OpenApiSchema { Type = "integer", Format = "int32" } },
17+
new object[] { typeof(int), new OpenApiSchema { Type = "number", Format = "int32" } },
1818
new object[] { typeof(decimal), new OpenApiSchema { Type = "number", Format = "double" } },
19+
new object[] { typeof(decimal?), new OpenApiSchema { Type = "number", Format = "double", Nullable = true } },
1920
new object[] { typeof(bool?), new OpenApiSchema { Type = "boolean", Nullable = true } },
2021
new object[] { typeof(Guid), new OpenApiSchema { Type = "string", Format = "uuid" } },
21-
new object[] { typeof(uint), new OpenApiSchema { Type = "integer", Format = "int32" } },
22-
new object[] { typeof(long), new OpenApiSchema { Type = "integer", Format = "int64" } },
23-
new object[] { typeof(ulong), new OpenApiSchema { Type = "integer", Format = "int64" } },
22+
new object[] { typeof(Guid?), new OpenApiSchema { Type = "string", Format = "uuid", Nullable = true } },
23+
new object[] { typeof(uint), new OpenApiSchema { Type = "number", Format = "int32" } },
24+
new object[] { typeof(long), new OpenApiSchema { Type = "number", Format = "int64" } },
25+
new object[] { typeof(long?), new OpenApiSchema { Type = "number", Format = "int64", Nullable = true } },
26+
new object[] { typeof(ulong), new OpenApiSchema { Type = "number", Format = "int64" } },
2427
new object[] { typeof(string), new OpenApiSchema { Type = "string" } },
2528
new object[] { typeof(double), new OpenApiSchema { Type = "number", Format = "double" } },
2629
new object[] { typeof(float?), new OpenApiSchema { Type = "number", Format = "float", Nullable = true } },
2730
new object[] { typeof(byte?), new OpenApiSchema { Type = "string", Format = "byte", Nullable = true } },
28-
new object[] { typeof(int?), new OpenApiSchema { Type = "integer", Format = "int32", Nullable = true } },
29-
new object[] { typeof(uint?), new OpenApiSchema { Type = "integer", Format = "int32", Nullable = true } },
31+
new object[] { typeof(int?), new OpenApiSchema { Type = "number", Format = "int32", Nullable = true } },
32+
new object[] { typeof(uint?), new OpenApiSchema { Type = "number", Format = "int32", Nullable = true } },
3033
new object[] { typeof(DateTimeOffset?), new OpenApiSchema { Type = "string", Format = "date-time", Nullable = true } },
3134
new object[] { typeof(double?), new OpenApiSchema { Type = "number", Format = "double", Nullable = true } },
3235
new object[] { typeof(char?), new OpenApiSchema { Type = "string", Nullable = true } },
@@ -35,11 +38,15 @@ public class OpenApiTypeMapperTests
3538

3639
public static IEnumerable<object[]> OpenApiDataTypes => new List<object[]>
3740
{
38-
new object[] { new OpenApiSchema { Type = "integer", Format = "int32"}, typeof(int) },
41+
new object[] { new OpenApiSchema { Type = "number", Format = "int32", Nullable = false}, typeof(int) },
42+
new object[] { new OpenApiSchema { Type = "number", Format = "int32", Nullable = true}, typeof(int?) },
43+
new object[] { new OpenApiSchema { Type = "number", Format = "int64", Nullable = false}, typeof(long) },
44+
new object[] { new OpenApiSchema { Type = "number", Format = "int64", Nullable = true}, typeof(long?) },
3945
new object[] { new OpenApiSchema { Type = "number", Format = "decimal"}, typeof(decimal) },
46+
new object[] { new OpenApiSchema { Type = "integer", Format = null, Nullable = false}, typeof(long) },
47+
new object[] { new OpenApiSchema { Type = "integer", Format = null, Nullable = true}, typeof(long?) },
4048
new object[] { new OpenApiSchema { Type = "number", Format = null, Nullable = false}, typeof(double) },
41-
new object[] { new OpenApiSchema { Type = "integer", Format = null, Nullable = false}, typeof(int) },
42-
new object[] { new OpenApiSchema { Type = "integer", Format = null, Nullable = true}, typeof(int?) },
49+
new object[] { new OpenApiSchema { Type = "number", Format = null, Nullable = true}, typeof(double?) },
4350
new object[] { new OpenApiSchema { Type = "number", Format = "decimal", Nullable = true}, typeof(decimal?) },
4451
new object[] { new OpenApiSchema { Type = "number", Format = "double", Nullable = true}, typeof(double?) },
4552
new object[] { new OpenApiSchema { Type = "string", Format = "date-time", Nullable = true}, typeof(DateTimeOffset?) },

test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<PackageReference Include="Moq" Version="4.20.72" />
1616
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
1717
<PackageReference Include="SharpYaml" Version="2.1.1" />
18-
<PackageReference Include="Verify.Xunit" Version="26.6.0" />
18+
<PackageReference Include="Verify.Xunit" Version="27.0.1" />
1919
<PackageReference Include="xunit" Version="2.9.2" />
2020
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
2121
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />

0 commit comments

Comments
 (0)