1- // Copyright (c) Microsoft Corporation. All rights reserved.
1+ // Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT license.
33
44using System . Collections . Generic ;
@@ -630,6 +630,10 @@ internal void WriteAsSchemaProperties(
630630 }
631631
632632 // format
633+ Format ??= AllOf ? . FirstOrDefault ( x => x . Format != null ) ? . Format ??
634+ AnyOf ? . FirstOrDefault ( x => x . Format != null ) ? . Format ??
635+ OneOf ? . FirstOrDefault ( x => x . Format != null ) ? . Format ;
636+
633637 writer . WriteProperty ( OpenApiConstants . Format , Format ) ;
634638
635639 // title
@@ -695,7 +699,7 @@ internal void WriteAsSchemaProperties(
695699 // allOf
696700 writer . WriteOptionalCollection ( OpenApiConstants . AllOf , AllOf , ( w , s ) => s . SerializeAsV2 ( w ) ) ;
697701
698- // If there isn't already an AllOf , and the schema contains a oneOf or anyOf write an allOf with the first
702+ // If there isn't already an allOf , and the schema contains a oneOf or anyOf write an allOf with the first
699703 // schema in the list as an attempt to guess at a graceful downgrade situation.
700704 if ( AllOf == null || AllOf . Count == 0 )
701705 {
@@ -707,12 +711,6 @@ internal void WriteAsSchemaProperties(
707711 // oneOf (Not Supported in V2) - Write the first schema only as an allOf.
708712 writer . WriteOptionalCollection ( OpenApiConstants . AllOf , OneOf ? . Take ( 1 ) , ( w , s ) => s . SerializeAsV2 ( w ) ) ;
709713 }
710- if ( OneOf ? . Count > 0 )
711- {
712- // Take the format and set it at the root
713- var oneOfFormat = OneOf . Select < OpenApiSchema , string > ( x => x . Format . ToString ( ) ) . FirstOrDefault ( ) ;
714- this . Format = oneOfFormat ;
715- }
716714 }
717715
718716 // properties
0 commit comments