Skip to content

Commit 3504b3e

Browse files
authored
Fix type/formats for primitive types (#56745)
1 parent b1765ca commit 3504b3e

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/OpenApi/src/Extensions/JsonNodeSchemaExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ internal static class JsonNodeSchemaExtensions
2727
private static readonly Dictionary<Type, OpenApiSchema> _simpleTypeToOpenApiSchema = new()
2828
{
2929
[typeof(bool)] = new() { Type = "boolean" },
30-
[typeof(byte)] = new() { Type = "string", Format = "byte" },
30+
[typeof(byte)] = new() { Type = "integer", Format = "uint8" },
31+
[typeof(byte[])] = new() { Type = "string", Format = "byte" },
3132
[typeof(int)] = new() { Type = "integer", Format = "int32" },
3233
[typeof(uint)] = new() { Type = "integer", Format = "uint32" },
3334
[typeof(long)] = new() { Type = "integer", Format = "int64" },
@@ -40,7 +41,7 @@ internal static class JsonNodeSchemaExtensions
4041
[typeof(DateTime)] = new() { Type = "string", Format = "date-time" },
4142
[typeof(DateTimeOffset)] = new() { Type = "string", Format = "date-time" },
4243
[typeof(Guid)] = new() { Type = "string", Format = "uuid" },
43-
[typeof(char)] = new() { Type = "string" },
44+
[typeof(char)] = new() { Type = "string", Format = "char" },
4445
[typeof(Uri)] = new() { Type = "string", Format = "uri" },
4546
[typeof(string)] = new() { Type = "string" },
4647
[typeof(TimeOnly)] = new() { Type = "string", Format = "time" },

src/OpenApi/test/Services/OpenApiDocumentService/OpenApiDocumentServiceTests.RequestBody.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,8 @@ private void ActionWithDateTimeForm([FromForm] DateTime model) { }
808808
[([FromForm] decimal id) => {}, "number", "double"],
809809
[([FromForm] bool id) => {}, "boolean", null],
810810
[([FromForm] string id) => {}, "string", null],
811-
[([FromForm] char id) => {}, "string", null],
812-
[([FromForm] byte id) => {}, "string", "byte"],
811+
[([FromForm] char id) => {}, "string", "char"],
812+
[([FromForm] byte id) => {}, "integer", "uint8"],
813813
[([FromForm] short id) => {}, "integer", "int16"],
814814
[([FromForm] ushort id) => {}, "integer", "uint16"],
815815
[([FromForm] uint id) => {}, "integer", "uint32"],

src/OpenApi/test/Services/OpenApiSchemaService/OpenApiSchemaService.ParameterSchemas.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ public partial class OpenApiSchemaServiceTests : OpenApiDocumentServiceTestBase
2121
[(decimal id) => {}, "number", "double", false],
2222
[(bool id) => {}, "boolean", null, false],
2323
[(string id) => {}, "string", null, false],
24-
[(char id) => {}, "string", null, false],
25-
[(byte id) => {}, "string", "byte", false],
24+
[(char id) => {}, "string", "char", false],
25+
[(byte id) => {}, "integer", "uint8", false],
26+
[(byte[] id) => {}, "string", "byte", false],
2627
[(short id) => {}, "integer", "int16", false],
2728
[(ushort id) => {}, "integer", "uint16", false],
2829
[(uint id) => {}, "integer", "uint32", false],
@@ -37,8 +38,9 @@ public partial class OpenApiSchemaServiceTests : OpenApiDocumentServiceTestBase
3738
[(decimal? id) => {}, "number", "double", true],
3839
[(bool? id) => {}, "boolean", null, true],
3940
[(string? id) => {}, "string", null, true],
40-
[(char? id) => {}, "string", null, true],
41-
[(byte? id) => {}, "string", "byte", true],
41+
[(char? id) => {}, "string", "char", true],
42+
[(byte? id) => {}, "integer", "uint8", true],
43+
[(byte[]? id) => {}, "string", "byte", true],
4244
[(short? id) => {}, "integer", "int16", true],
4345
[(ushort? id) => {}, "integer", "uint16", true],
4446
[(uint? id) => {}, "integer", "uint32", true],

src/OpenApi/test/Services/OpenApiSchemaService/OpenApiSchemaService.ResponseSchemas.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ public partial class OpenApiSchemaServiceTests : OpenApiDocumentServiceTestBase
1818
[() => 12.0m, "application/json", "number", "double"],
1919
[() => false, "application/json", "boolean", null],
2020
[() => "test", "text/plain", "string", null],
21-
[() => 't', "application/json", "string", null],
22-
[() => byte.MaxValue, "application/json", "string", "byte"],
21+
[() => 't', "application/json", "string", "char"],
22+
[() => byte.MaxValue, "application/json", "integer", "uint8"],
23+
[() => new byte[] { }, "application/json", "string", "byte"],
2324
[() => short.MaxValue, "application/json", "integer", "int16"],
2425
[() => ushort.MaxValue, "application/json", "integer", "uint16"],
2526
[() => uint.MaxValue, "application/json", "integer", "uint32"],

0 commit comments

Comments
 (0)