diff --git a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs index 957e0f946..fa7a504fa 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiSchema.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiSchema.cs @@ -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)); @@ -620,20 +613,26 @@ internal void WriteAsItemsProperties(IOpenApiWriter writer) writer.WriteExtensions(Extensions, OpenApiSpecVersion.OpenApi2_0); } - internal void WriteAsSchemaProperties( - IOpenApiWriter writer, - ISet 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 parentRequiredProperties, + string propertyName) + { + // format + WriteFormatProperty(writer); // title writer.WriteProperty(OpenApiConstants.Title, Title);