diff --git a/src/Umbraco.Core/DeliveryApi/ApiElementBuilder.cs b/src/Umbraco.Core/DeliveryApi/ApiElementBuilder.cs index 3d7a8a401393..83d2c8e4c9fa 100644 --- a/src/Umbraco.Core/DeliveryApi/ApiElementBuilder.cs +++ b/src/Umbraco.Core/DeliveryApi/ApiElementBuilder.cs @@ -29,6 +29,7 @@ public IApiElement Build(IPublishedElement element) return new ApiElement( element.Key, + element.Name, element.ContentType.Alias, properties); } diff --git a/src/Umbraco.Core/Models/DeliveryApi/ApiContent.cs b/src/Umbraco.Core/Models/DeliveryApi/ApiContent.cs index c2566905b034..e8ba0fcb5773 100644 --- a/src/Umbraco.Core/Models/DeliveryApi/ApiContent.cs +++ b/src/Umbraco.Core/Models/DeliveryApi/ApiContent.cs @@ -16,17 +16,13 @@ public class ApiContent : ApiElement, IApiContent /// The route information for the content. /// The property values of the content. public ApiContent(Guid id, string name, string contentType, DateTime createDate, DateTime updateDate, IApiContentRoute route, IDictionary properties) - : base(id, contentType, properties) + : base(id, name, contentType, properties) { - Name = name; CreateDate = createDate; UpdateDate = updateDate; Route = route; } - /// - public string Name { get; } - /// public DateTime CreateDate { get; } diff --git a/src/Umbraco.Core/Models/DeliveryApi/ApiElement.cs b/src/Umbraco.Core/Models/DeliveryApi/ApiElement.cs index d461878ac698..991160d3de3c 100644 --- a/src/Umbraco.Core/Models/DeliveryApi/ApiElement.cs +++ b/src/Umbraco.Core/Models/DeliveryApi/ApiElement.cs @@ -7,15 +7,23 @@ namespace Umbraco.Cms.Core.Models.DeliveryApi; /// public class ApiElement : IApiElement { + [Obsolete("Please use the constructor with all parameters. Scheduled for removal in Umbraco 20.")] + public ApiElement(Guid id, string contentType, IDictionary properties) + : this(id, string.Empty, contentType, properties) + { + } + /// /// Initializes a new instance of the class. /// /// The unique identifier of the element. + /// The name of the element. /// The content type alias of the element. /// The property values of the element. - public ApiElement(Guid id, string contentType, IDictionary properties) + public ApiElement(Guid id, string name, string contentType, IDictionary properties) { Id = id; + Name = name; ContentType = contentType; Properties = properties; } @@ -23,6 +31,9 @@ public ApiElement(Guid id, string contentType, IDictionary prop /// public Guid Id { get; } + /// + public string Name { get; } + /// /// Gets the content type alias of the element. /// diff --git a/src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs b/src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs index 7c3139972afa..8bb557bedf48 100644 --- a/src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs +++ b/src/Umbraco.Core/Models/DeliveryApi/IApiContent.cs @@ -8,7 +8,9 @@ public interface IApiContent : IApiElement /// /// Gets the name of the content. /// - string? Name { get; } + // TODO (V19): Remove this declaration; it is retained only to preserve the IApiContent.Name binary slot for + // consumers compiled against v18.0. Name now lives on the IApiElement base interface. + new string? Name { get; } /// /// Gets the date and time when the content was created. diff --git a/src/Umbraco.Core/Models/DeliveryApi/IApiElement.cs b/src/Umbraco.Core/Models/DeliveryApi/IApiElement.cs index 3a81fa17d04d..9be47cf03dac 100644 --- a/src/Umbraco.Core/Models/DeliveryApi/IApiElement.cs +++ b/src/Umbraco.Core/Models/DeliveryApi/IApiElement.cs @@ -12,6 +12,12 @@ public interface IApiElement /// Guid Id { get; } + /// + /// Gets the name of the element. + /// + // TODO (V19): Remove the default implementations from this interface. + string? Name => null; + /// /// Gets the content type alias of the element. /// diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Api.Delivery/OpenApi/ExpectedContracts/typed-schemas-empty-project.json b/tests/Umbraco.Tests.Integration/Umbraco.Api.Delivery/OpenApi/ExpectedContracts/typed-schemas-empty-project.json index b1d4c2373c88..5e64699489c8 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Api.Delivery/OpenApi/ExpectedContracts/typed-schemas-empty-project.json +++ b/tests/Umbraco.Tests.Integration/Umbraco.Api.Delivery/OpenApi/ExpectedContracts/typed-schemas-empty-project.json @@ -1516,6 +1516,12 @@ "type": "string", "format": "uuid" }, + "name": { + "type": [ + "null", + "string" + ] + }, "properties": { "type": [ "null", diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Api.Delivery/OpenApi/ExpectedContracts/typed-schemas-with-sample-types.json b/tests/Umbraco.Tests.Integration/Umbraco.Api.Delivery/OpenApi/ExpectedContracts/typed-schemas-with-sample-types.json index 9762e77c3b25..8e16772a1d0b 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Api.Delivery/OpenApi/ExpectedContracts/typed-schemas-with-sample-types.json +++ b/tests/Umbraco.Tests.Integration/Umbraco.Api.Delivery/OpenApi/ExpectedContracts/typed-schemas-with-sample-types.json @@ -1669,6 +1669,12 @@ "type": "string", "format": "uuid" }, + "name": { + "type": [ + "null", + "string" + ] + }, "properties": { "type": [ "null", diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ElementPickerValueConverterTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ElementPickerValueConverterTests.cs index 9ff896309577..7118fde5494d 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ElementPickerValueConverterTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/DeliveryApi/ElementPickerValueConverterTests.cs @@ -40,6 +40,7 @@ public void ElementPickerValueConverter_BuildsDeliveryApiOutput() Assert.AreEqual(1, result!.Count()); var element = result.First(); Assert.AreEqual(PublishedElement.Key, element.Id); + Assert.AreEqual(PublishedElement.Name, element.Name); Assert.AreEqual("TheElementType", element.ContentType); Assert.IsEmpty(element.Properties); } @@ -86,6 +87,7 @@ public void ElementPickerValueConverter_RendersContentProperties() Assert.AreEqual(1, result!.Count()); var element = result.First(); Assert.AreEqual(key, element.Id); + Assert.AreEqual("The element", element.Name); Assert.AreEqual("theElementType", element.ContentType); Assert.AreEqual(2, element.Properties.Count); Assert.AreEqual("Delivery API value", element.Properties[DeliveryApiPropertyType.Alias]);