question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Content Delivery API - API non compliant to Swagger Spec

See original GitHub issue

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 (https://github.com/OAI/OpenAPI-Specification/issues/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

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
kjaccommented, May 25, 2023

Hi again @vsilvar,

Thanks for investigating, I really appreciate you taking the time 🥇

I’m going to keep this issue open for now, even though technically it is a duplicate of #14298 … we’ll make sure to update both issues when we know more.

0reactions
kjaccommented, May 31, 2023

https://github.com/umbraco/Umbraco-CMS/pull/14311 has been merged now, so I’ll go ahead and close this issue.

We are looking into a V12 RC3, which will contain this fix. It is still unknown when it will be out, we have a few more things we’d like in there.

Again, thank you so much for bringing this issue to our attention 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content Delivery API - API non compliant to Swagger Spec
The simple, flexible and friendly ASP.NET CMS used by more than 730.000 websites - Content Delivery API - API non compliant to Swagger...
Read more >
OpenAPI Specification - Version 3.0.3
The OpenAPI Specification (OAS) defines a standard, language-agnostic interface to HTTP APIs which allows both humans and computers to discover and understand ...
Read more >
Unable to import openapi 3 spec with bearer auth
I get the following error: Your API was not imported due to errors in the Swagger file. Unsupported security definition type 'http' for...
Read more >
How to improve API documentation with Swagger and ...
API documentation with Swagger tooling and the OpenAPI specification can ease overall API creation and management processes.
Read more >
Import Swagger to Define and Control API Groups
This guide provides instructions on how to import a Swagger file to define API groups and set rules to control access to APIs,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found