Skip to content

Commit 56365d7

Browse files
committed
fix: 3.0 serialization when type is set to null
Signed-off-by: Vincent Biret <[email protected]>
1 parent 33b40a2 commit 56365d7

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
@@ -633,7 +633,8 @@ private void SerializeAsV2(
633633
private void SerializeTypeProperty(JsonSchemaType? type, IOpenApiWriter writer, OpenApiSpecVersion version)
634634
{
635635
// check whether nullable is true for upcasting purposes
636-
var isNullable = Nullable ||
636+
var isNullable = Nullable ||
637+
Type is JsonSchemaType.Null ||
637638
Extensions is not null &&
638639
Extensions.TryGetValue(OpenApiConstants.NullableExtension, out var nullExtRawValue) &&
639640
nullExtRawValue is OpenApiAny { Node: JsonNode jsonNode} &&
@@ -653,9 +654,14 @@ Extensions is not null &&
653654
case OpenApiSpecVersion.OpenApi3_1 when isNullable:
654655
UpCastSchemaTypeToV31(type.Value, writer);
655656
break;
656-
case OpenApiSpecVersion.OpenApi3_0 when isNullable:
657+
case OpenApiSpecVersion.OpenApi3_0 when isNullable && type.Value == JsonSchemaType.Null:
657658
writer.WriteProperty(OpenApiConstants.Nullable, true);
658-
goto default;
659+
writer.WriteProperty(OpenApiConstants.Type, JsonSchemaType.Object.ToIdentifier());
660+
break;
661+
case OpenApiSpecVersion.OpenApi3_0 when isNullable && type.Value != JsonSchemaType.Null:
662+
writer.WriteProperty(OpenApiConstants.Nullable, true);
663+
writer.WriteProperty(OpenApiConstants.Type, type.Value.ToIdentifier());
664+
break;
659665
default:
660666
writer.WriteProperty(OpenApiConstants.Type, type.Value.ToIdentifier());
661667
break;

0 commit comments

Comments
 (0)