Skip to content

Commit aa3781b

Browse files
committed
If type array has been provided alongside a nullable keyword, don't emit type
1 parent be414df commit aa3781b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,17 @@ internal static partial class OpenApiV31Deserializer
185185
(o, n, _) =>
186186
{
187187
var nullable = bool.Parse(n.GetScalarValue());
188-
if (nullable) // if nullable, convert type into an array of type and null
188+
if (nullable) // if nullable, convert type into an array of type(s) and null
189189
{
190-
o.Type = new string[]{o.Type.ToString(), OpenApiConstants.Null};
190+
if (o.Type is string[] typeArray)
191+
{
192+
var typeList = new List<string>(typeArray) { OpenApiConstants.Null };
193+
o.Type = typeList.ToArray();
194+
}
195+
else if (o.Type is string typeString)
196+
{
197+
o.Type = new string[]{typeString, OpenApiConstants.Null};
198+
}
191199
}
192200
}
193201
},

0 commit comments

Comments
 (0)