Skip to content

Content Delivery API - API non compliant to Swagger Spec #14299

@vsilvar

Description

@vsilvar

Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)

12.0.0-rc2

Bug summary

The OpenAPI v3 specification does not support path parameters with multiple segments (OAI/OpenAPI-Specification#892).

This means that any OpenApi tooling won't support it either, and will simply encode the slashes when doing API requests.
This can already be seen in the swagger UI itself, which means you get a 404 when trying to, for example, retrieve the root /

In order for Umbraco to have a compliant spec and allow consumers to use code generation tools, I think it should support both encoded and non-encoded paths.

Specifics

No response

Steps to reproduce

  1. Install the latest Umbraco 12 RC2
  2. Create some dummy content types and content
  3. Use the swagger UI to retrieve content by path / or configure a code generation tool by following the following steps
  4. Save the /umbraco/swagger/delivery/swagger.json file in the project as UmbracoDeliveryApiSwagger.json
  5. Add the following to the .csproj file:
<ItemGroup>
 <PackageReference Include="NSwag.ApiDescription.Client" Version="13.19.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 </PackageReference>
 <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
 <PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="7.0.5">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
 </PackageReference>
 <OpenApiReference Include="UmbracoDeliveryApiSwagger.json" CodeGenerator="NSwagCSharp" Namespace="Umbraco.DeliveryApi" ClassName="DeliveryApiClient" />
</ItemGroup>
  1. Add the following to the end of WithEndpoints in Startup.cs:
u.EndpointRouteBuilder.MapGet("/delivery-test", async (HttpContext context, IOptions<WebRoutingSettings> webRoutingSettings, IHttpClientFactory httpClientFactory) =>
{
    DeliveryApiClient client = new(context.Request.GetApplicationUri(webRoutingSettings.Value).ToString(), httpClientFactory.CreateClient(nameof(DeliveryApiClient)));

    return await client.GetContentItemByPathAsync("/");
});
  1. When you call the /delivery-test endpoint you'll get an exception due to the 404

Expected result / actual result

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions