Skip to content

Commit

Permalink
Merge pull request #2082 from microsoft/fix/flaky-format-to-v1
Browse files Browse the repository at this point in the history
fix: a flaky behaviour for format property serialization
  • Loading branch information
andrueastman authored Jan 23, 2025
2 parents 2a19da4 + 4d06f86 commit e072790
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,7 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
writer.WriteProperty(OpenApiConstants.Type, Type);

// format
if (string.IsNullOrEmpty(Format))
{
Format = AllOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
AnyOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
OneOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format;
}

writer.WriteProperty(OpenApiConstants.Format, Format);
WriteFormatProperty(writer);

// items
writer.WriteOptionalObject(OpenApiConstants.Items, Items, (w, s) => s.SerializeAsV2(w));
Expand Down Expand Up @@ -620,20 +613,26 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_0);
}

internal void WriteAsSchemaProperties(
IOpenApiWriter writer,
ISet<string> parentRequiredProperties,
string propertyName)
private void WriteFormatProperty(IOpenApiWriter writer)
{
// format
if (string.IsNullOrEmpty(Format))
var formatToWrite = Format;
if (string.IsNullOrEmpty(formatToWrite))
{
Format = AllOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
formatToWrite = AllOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
AnyOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format ??
OneOf?.FirstOrDefault(static x => !string.IsNullOrEmpty(x.Format))?.Format;
}

writer.WriteProperty(OpenApiConstants.Format, Format);
writer.WriteProperty(OpenApiConstants.Format, formatToWrite);
}

internal void WriteAsSchemaProperties(
IOpenApiWriter writer,
ISet<string> parentRequiredProperties,
string propertyName)
{
// format
WriteFormatProperty(writer);

// title
writer.WriteProperty(OpenApiConstants.Title, Title);
Expand Down

0 comments on commit e072790

Please sign in to comment.