Skip to content

Commit

Permalink
feat: Improve GetDataType by handling AllOf
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkallesen committed Jun 24, 2024
1 parent 56e8646 commit 7e6be50
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Atc.OpenApi/Extensions/OpenApiSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -866,11 +866,32 @@ public static string GetDataType(this OpenApiSchema schema)
{
dataType = schema.Reference.Id;
}
else if (schema.OneOf is not null && schema.OneOf.Count == 1 && schema.OneOf[0].Reference?.Id is not null)
else if (schema.OneOf is not null &&
schema.OneOf.Count == 1 &&
schema.OneOf[0].Reference?.Id is not null)
{
dataType = schema.OneOf[0].Reference.Id;
}

if (dataType is null &&
schema.AllOf is not null &&
schema.AllOf.Count > 0)
{
foreach (var apiSchema in schema.AllOf)
{
dataType = apiSchema.GetDataType();
if (!string.IsNullOrEmpty(dataType))
{
break;
}
}
}

if (dataType is null)
{
return string.Empty;
}

return string.Equals(dataType, OpenApiDataTypeConstants.String, StringComparison.Ordinal)
? dataType
: dataType.EnsureFirstCharacterToUpper();
Expand Down

0 comments on commit 7e6be50

Please sign in to comment.