Skip to content

Commit aa503ff

Browse files
Fix anyOf and oneOf serialization by checking for null first before writing either as allOf
1 parent c564a98 commit aa503ff

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,12 +700,12 @@ internal void WriteAsSchemaProperties(
700700
if (AllOf == null || AllOf.Count == 0)
701701
{
702702
// anyOf (Not Supported in V2) - Write the first schema only as an allOf.
703-
writer.WriteOptionalCollection(OpenApiConstants.AllOf, AnyOf.Take(1), (w, s) => s.SerializeAsV2(w));
703+
writer.WriteOptionalCollection(OpenApiConstants.AllOf, AnyOf?.Take(1), (w, s) => s.SerializeAsV2(w));
704704

705705
if (AnyOf == null || AnyOf.Count == 0)
706706
{
707707
// oneOf (Not Supported in V2) - Write the first schema only as an allOf.
708-
writer.WriteOptionalCollection(OpenApiConstants.AllOf, OneOf.Take(1), (w, s) => s.SerializeAsV2(w));
708+
writer.WriteOptionalCollection(OpenApiConstants.AllOf, OneOf?.Take(1), (w, s) => s.SerializeAsV2(w));
709709
}
710710
}
711711

0 commit comments

Comments
 (0)