@@ -545,7 +545,7 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
545545 }
546546
547547 // type
548- var serializedTypeProperty = TrySerializeTypeProperty ( writer , version ) ;
548+ SerializeTypeProperty ( writer , version ) ;
549549
550550 // allOf
551551 writer . WriteOptionalCollection ( OpenApiConstants . AllOf , AllOf , callback ) ;
@@ -590,13 +590,13 @@ private void SerializeInternal(IOpenApiWriter writer, OpenApiSpecVersion version
590590 writer . WriteOptionalObject ( OpenApiConstants . Default , Default , ( w , d ) => w . WriteAny ( d ) ) ;
591591
592592 // nullable
593- if ( version == OpenApiSpecVersion . OpenApi3_0 && serializedTypeProperty )
593+ if ( version == OpenApiSpecVersion . OpenApi3_0 )
594594 {
595595 // https://spec.openapis.org/oas/v3.0.4.html#fixed-fields-20
596596 // This keyword only takes effect if type is explicitly defined within the same Schema Object.
597597 //
598- // If the user explicitly set IsNullable to true, we serialize it even if redundant .
599- // But if **we** are inferring it (from oneOf/anyOf), we don't serialize it when it's redundant .
598+ // We don't care to avoid an unnecessary serialization .
599+ // So, we attempt to serialize it regardless of whether or not a type property was serialized .
600600 SerializeNullable ( writer , version ) ;
601601 }
602602
@@ -833,7 +833,7 @@ private void SerializeAsV2(
833833 writer . WriteStartObject ( ) ;
834834
835835 // type
836- TrySerializeTypeProperty ( writer , OpenApiSpecVersion . OpenApi2_0 ) ;
836+ SerializeTypeProperty ( writer , OpenApiSpecVersion . OpenApi2_0 ) ;
837837
838838 // description
839839 writer . WriteProperty ( OpenApiConstants . Description , Description ) ;
@@ -1001,14 +1001,13 @@ private void SerializeAsV2(
10011001 writer . WriteEndObject ( ) ;
10021002 }
10031003
1004- private bool TrySerializeTypeProperty ( IOpenApiWriter writer , OpenApiSpecVersion version , JsonSchemaType ? inferredType = null )
1004+ private void SerializeTypeProperty ( IOpenApiWriter writer , OpenApiSpecVersion version )
10051005 {
1006- // Use original type or inferred type when the explicit type is not set
1007- var typeToUse = Type ?? inferredType ;
1006+ var typeToUse = Type ;
10081007
10091008 if ( typeToUse is null )
10101009 {
1011- return false ;
1010+ return ;
10121011 }
10131012
10141013 switch ( version )
@@ -1018,15 +1017,15 @@ private bool TrySerializeTypeProperty(IOpenApiWriter writer, OpenApiSpecVersion
10181017 if ( typeWithoutNull != 0 && ! HasMultipleTypes ( typeWithoutNull ) )
10191018 {
10201019 writer . WriteProperty ( OpenApiConstants . Type , typeWithoutNull . ToFirstIdentifier ( ) ) ;
1021- return true ;
1020+ return ;
10221021 }
10231022 break ;
10241023 default :
10251024 WriteUnifiedSchemaType ( typeToUse . Value , writer ) ;
1026- return true ;
1025+ return ;
10271026 }
10281027
1029- return false ;
1028+ return ;
10301029 }
10311030
10321031 private JsonNode ? GetCompatibilityExample ( )
0 commit comments