@@ -632,7 +632,8 @@ private void SerializeAsV2(
632
632
private void SerializeTypeProperty ( JsonSchemaType ? type , IOpenApiWriter writer , OpenApiSpecVersion version )
633
633
{
634
634
// check whether nullable is true for upcasting purposes
635
- var isNullable = Nullable ||
635
+ var isNullable = Nullable ||
636
+ Type is JsonSchemaType . Null ||
636
637
Extensions is not null &&
637
638
Extensions . TryGetValue ( OpenApiConstants . NullableExtension , out var nullExtRawValue ) &&
638
639
nullExtRawValue is OpenApiAny { Node : JsonNode jsonNode } &&
@@ -652,9 +653,14 @@ Extensions is not null &&
652
653
case OpenApiSpecVersion . OpenApi3_1 when isNullable :
653
654
UpCastSchemaTypeToV31 ( type . Value , writer ) ;
654
655
break ;
655
- case OpenApiSpecVersion . OpenApi3_0 when isNullable :
656
+ case OpenApiSpecVersion . OpenApi3_0 when isNullable && type . Value == JsonSchemaType . Null :
656
657
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 ;
658
664
default :
659
665
writer . WriteProperty ( OpenApiConstants . Type , type . Value . ToIdentifier ( ) ) ;
660
666
break ;
0 commit comments