@@ -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