Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions src/Microsoft.OpenApi/Models/OpenApiSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,7 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
writer.WriteProperty(OpenApiConstants.Type, Type.ToIdentifier());

// 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 @@ -643,6 +636,19 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer)
writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_0);
}

private void WriteFormatProperty(IOpenApiWriter writer)
{
var formatToWrite = Format;
if (string.IsNullOrEmpty(formatToWrite))
{
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, formatToWrite);
}

/// <summary>
/// Serialize <see cref="OpenApiSchema"/> to Open Api v2.0 and handles not marking the provided property
/// as readonly if its included in the provided list of required properties of parent schema.
Expand All @@ -666,14 +672,7 @@ internal virtual void SerializeAsV2(
writer.WriteProperty(OpenApiConstants.Description, Description);

// 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);

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