@@ -583,14 +583,7 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
583583 writer . WriteProperty ( OpenApiConstants . Type , Type . ToIdentifier ( ) ) ;
584584
585585 // format
586- if ( string . IsNullOrEmpty ( Format ) )
587- {
588- Format = AllOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
589- AnyOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
590- OneOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ;
591- }
592-
593- writer . WriteProperty ( OpenApiConstants . Format , Format ) ;
586+ WriteFormatProperty ( writer ) ;
594587
595588 // items
596589 writer . WriteOptionalObject ( OpenApiConstants . Items , Items , ( w , s ) => s . SerializeAsV2 ( w ) ) ;
@@ -643,6 +636,19 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
643636 writer . WriteExtensions ( Extensions , OpenApiSpecVersion . OpenApi2_0 ) ;
644637 }
645638
639+ private void WriteFormatProperty ( IOpenApiWriter writer )
640+ {
641+ var formatToWrite = Format ;
642+ if ( string . IsNullOrEmpty ( formatToWrite ) )
643+ {
644+ formatToWrite = AllOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
645+ AnyOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
646+ OneOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ;
647+ }
648+
649+ writer . WriteProperty ( OpenApiConstants . Format , formatToWrite ) ;
650+ }
651+
646652 /// <summary>
647653 /// Serialize <see cref="OpenApiSchema"/> to Open Api v2.0 and handles not marking the provided property
648654 /// as readonly if its included in the provided list of required properties of parent schema.
@@ -666,14 +672,7 @@ internal virtual void SerializeAsV2(
666672 writer . WriteProperty ( OpenApiConstants . Description , Description ) ;
667673
668674 // format
669- if ( string . IsNullOrEmpty ( Format ) )
670- {
671- Format = AllOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
672- AnyOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ??
673- OneOf ? . FirstOrDefault ( static x => ! string . IsNullOrEmpty ( x . Format ) ) ? . Format ;
674- }
675-
676- writer . WriteProperty ( OpenApiConstants . Format , Format ) ;
675+ WriteFormatProperty ( writer ) ;
677676
678677 // title
679678 writer . WriteProperty ( OpenApiConstants . Title , Title ) ;
0 commit comments