Skip to content

Commit

Permalink
Merge pull request #1444 from microsoft/bugfix/object-type-schema
Browse files Browse the repository at this point in the history
- fixes a bug where the conversion would ommit the schema type
  • Loading branch information
baywet authored Oct 27, 2023
2 parents 98c3168 + 639aa7e commit 51890ee
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

return formBody;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Models/OpenApiParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public void SerializeAsV2WithoutReference(IOpenApiWriter writer)
// In V2 parameter's type can't be a reference to a custom object schema or can't be of type object
// So in that case map the type as string.
else
if (Schema?.UnresolvedReference == true || Schema?.Type == "object")
if (Schema?.UnresolvedReference == true || "object".Equals(Schema?.Type, StringComparison.OrdinalIgnoreCase))
{
writer.WriteProperty(OpenApiConstants.Type, "string");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
Expand Down Expand Up @@ -80,6 +81,7 @@ public class OpenApiOperationTests
{
Schema = new()
{
Type = "object",
Properties =
{
["name"] = new()
Expand All @@ -103,6 +105,7 @@ public class OpenApiOperationTests
{
Schema = new()
{
Type = "object",
Properties =
{
["name"] = new()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -67,6 +68,7 @@ public class OpenApiPathItemTests
{
Schema = new()
{
Type = "object",
Properties =
{
["name"] = new()
Expand All @@ -90,6 +92,7 @@ public class OpenApiPathItemTests
{
Schema = new()
{
Type = "object",
Properties =
{
["name"] = new()
Expand Down Expand Up @@ -171,6 +174,7 @@ public class OpenApiPathItemTests
{
Schema = new()
{
Type = "object",
Properties =
{
["name"] = new()
Expand Down Expand Up @@ -199,6 +203,7 @@ public class OpenApiPathItemTests
{
Schema = new()
{
Type = "object",
Properties =
{
["name"] = new()
Expand Down

0 comments on commit 51890ee

Please sign in to comment.