Skip to content

Commit 263e3ca

Browse files
committed
Use HasMultipleTypes helper method
1 parent 9a2ee7e commit 263e3ca

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

src/Microsoft.OpenApi/Models/OpenApiSchema.cs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -877,43 +877,24 @@ private static (IList<IOpenApiSchema>? effective, JsonSchemaType? inferredType,
877877

878878
if (nonNullSchemas.Count > 0)
879879
{
880-
// Check if all schemas have the same type (excluding null)
881-
JsonSchemaType? firstType = null;
882-
bool allSameType = true;
880+
JsonSchemaType commonType = 0;
883881

884882
foreach (var schema in nonNullSchemas)
885883
{
886-
var schemaType = schema.Type;
887-
if (schemaType.HasValue)
888-
{
889-
var typeWithoutNull = schemaType.Value & ~JsonSchemaType.Null;
890-
891-
if (typeWithoutNull != 0)
892-
{
893-
if (firstType == null)
894-
{
895-
firstType = typeWithoutNull;
896-
}
897-
else if (firstType != typeWithoutNull)
898-
{
899-
allSameType = false;
900-
break;
901-
}
902-
}
903-
}
884+
commonType |= schema.Type.GetValueOrDefault() & ~JsonSchemaType.Null;
904885
}
905886

906-
if (allSameType && firstType.HasValue)
887+
var isSingleType = !HasMultipleTypes(commonType);
888+
if (isSingleType)
907889
{
908-
// All schemas share the same type
909-
return (nonNullSchemas, firstType.Value, true);
890+
// Single common type
891+
return (nonNullSchemas, commonType, true);
910892
}
911893
else
912894
{
913895
// Multiple different types
914896
return (nonNullSchemas, null, true);
915897
}
916-
917898
}
918899
else
919900
{

0 commit comments

Comments
 (0)