Skip to content

Commit fe13c56

Browse files
committed
fix: adds missing type mappings tests
1 parent 1e6e654 commit fe13c56

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
101101
// integer is technically not valid with format, but we must provide some compatibility
102102
("integer" or "number", "int32", false) => typeof(int),
103103
("integer" or "number", "int64", false) => typeof(long),
104-
("integer", null, false) => typeof(int),
104+
("integer", null, false) => typeof(long),
105105
("number", "float", false) => typeof(float),
106106
("number", "double", false) => typeof(double),
107107
("number", "decimal", false) => typeof(decimal),
@@ -116,7 +116,7 @@ public static Type MapOpenApiPrimitiveTypeToSimpleType(this OpenApiSchema schema
116116
("string", "uri", false) => typeof(Uri),
117117
("integer" or "number", "int32", true) => typeof(int?),
118118
("integer" or "number", "int64", true) => typeof(long?),
119-
("integer", null, true) => typeof(int?),
119+
("integer", null, true) => typeof(long?),
120120
("number", "float", true) => typeof(float?),
121121
("number", "double", true) => typeof(double?),
122122
("number", null, true) => typeof(double?),

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ public class OpenApiTypeMapperTests
1616
{
1717
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" } },
22+
new object[] { typeof(Guid?), new OpenApiSchema { Type = "string", Format = "uuid", Nullable = true } },
2123
new object[] { typeof(uint), new OpenApiSchema { Type = "number", Format = "int32" } },
2224
new object[] { typeof(long), new OpenApiSchema { Type = "number", Format = "int64" } },
25+
new object[] { typeof(long?), new OpenApiSchema { Type = "number", Format = "int64", Nullable = true } },
2326
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" } },
@@ -35,11 +38,15 @@ public class OpenApiTypeMapperTests
3538

3639
public static IEnumerable<object[]> OpenApiDataTypes => new List<object[]>
3740
{
38-
new object[] { new OpenApiSchema { Type = "number", 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 = "number", Format = null, Nullable = false}, typeof(int) },
42-
new object[] { new OpenApiSchema { Type = "number", 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?) },

0 commit comments

Comments
 (0)