Skip to content

Commit 920a51a

Browse files
committed
fix: 3.0 serialization when type is set to null
Signed-off-by: Vincent Biret <[email protected]>
1 parent 121bb48 commit 920a51a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,8 @@ private void SerializeAsV2(
632632
private void SerializeTypeProperty(JsonSchemaType? type, IOpenApiWriter writer, OpenApiSpecVersion version)
633633
{
634634
// check whether nullable is true for upcasting purposes
635-
var isNullable = Nullable ||
635+
var isNullable = Nullable ||
636+
Type is JsonSchemaType.Null ||
636637
Extensions is not null &&
637638
Extensions.TryGetValue(OpenApiConstants.NullableExtension, out var nullExtRawValue) &&
638639
nullExtRawValue is OpenApiAny { Node: JsonNode jsonNode} &&
@@ -652,9 +653,14 @@ Extensions is not null &&
652653
case OpenApiSpecVersion.OpenApi3_1 when isNullable:
653654
UpCastSchemaTypeToV31(type.Value, writer);
654655
break;
655-
case OpenApiSpecVersion.OpenApi3_0 when isNullable:
656+
case OpenApiSpecVersion.OpenApi3_0 when isNullable && type.Value == JsonSchemaType.Null:
656657
writer.WriteProperty(OpenApiConstants.Nullable, true);
657-
goto default;
658+
writer.WriteProperty(OpenApiConstants.Type, JsonSchemaType.Object.ToIdentifier());
659+
break;
660+
case OpenApiSpecVersion.OpenApi3_0 when isNullable && type.Value != JsonSchemaType.Null:
661+
writer.WriteProperty(OpenApiConstants.Nullable, true);
662+
writer.WriteProperty(OpenApiConstants.Type, type.Value.ToIdentifier());
663+
break;
658664
default:
659665
writer.WriteProperty(OpenApiConstants.Type, type.Value.ToIdentifier());
660666
break;

0 commit comments

Comments
 (0)