Skip to content

Commit 51890ee

Browse files
authored
Merge pull request #1444 from microsoft/bugfix/object-type-schema
- fixes a bug where the conversion would ommit the schema type
2 parents 98c3168 + 639aa7e commit 51890ee

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiOperationDeserializer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.Linq;
6+
using System.Security.Cryptography.X509Certificates;
67
using Microsoft.OpenApi.Any;
78
using Microsoft.OpenApi.Extensions;
89
using Microsoft.OpenApi.Models;
@@ -171,6 +172,8 @@ private static OpenApiRequestBody CreateFormBody(ParsingContext context, List<Op
171172
k => k,
172173
_ => mediaType)
173174
};
175+
foreach(var value in formBody.Content.Values.Where(static x => x.Schema is not null && x.Schema.Properties.Any() && string.IsNullOrEmpty(x.Schema.Type)))
176+
value.Schema.Type = "object";
174177

175178
return formBody;
176179
}

src/Microsoft.OpenApi/Models/OpenApiParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ public void SerializeAsV2WithoutReference(IOpenApiWriter writer)
336336
// In V2 parameter's type can't be a reference to a custom object schema or can't be of type object
337337
// So in that case map the type as string.
338338
else
339-
if (Schema?.UnresolvedReference == true || Schema?.Type == "object")
339+
if (Schema?.UnresolvedReference == true || "object".Equals(Schema?.Type, StringComparison.OrdinalIgnoreCase))
340340
{
341341
writer.WriteProperty(OpenApiConstants.Type, "string");
342342
}

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.IO;
67
using System.Text;
@@ -80,6 +81,7 @@ public class OpenApiOperationTests
8081
{
8182
Schema = new()
8283
{
84+
Type = "object",
8385
Properties =
8486
{
8587
["name"] = new()
@@ -103,6 +105,7 @@ public class OpenApiOperationTests
103105
{
104106
Schema = new()
105107
{
108+
Type = "object",
106109
Properties =
107110
{
108111
["name"] = new()

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiPathItemTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.IO;
67
using System.Linq;
@@ -67,6 +68,7 @@ public class OpenApiPathItemTests
6768
{
6869
Schema = new()
6970
{
71+
Type = "object",
7072
Properties =
7173
{
7274
["name"] = new()
@@ -90,6 +92,7 @@ public class OpenApiPathItemTests
9092
{
9193
Schema = new()
9294
{
95+
Type = "object",
9396
Properties =
9497
{
9598
["name"] = new()
@@ -171,6 +174,7 @@ public class OpenApiPathItemTests
171174
{
172175
Schema = new()
173176
{
177+
Type = "object",
174178
Properties =
175179
{
176180
["name"] = new()
@@ -199,6 +203,7 @@ public class OpenApiPathItemTests
199203
{
200204
Schema = new()
201205
{
206+
Type = "object",
202207
Properties =
203208
{
204209
["name"] = new()

0 commit comments

Comments
 (0)