Content Delivery API - API non compliant to Swagger Spec
See original GitHub issueWhich 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
- Install the latest Umbraco 12 RC2
- Create some dummy content types and content
- Use the swagger UI to retrieve content by path
/
or configure a code generation tool by following the following steps - Save the
/umbraco/swagger/delivery/swagger.json
file in the project asUmbracoDeliveryApiSwagger.json
- 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>
- Add the following to the end of
WithEndpoints
inStartup.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("/");
});
- 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:
- Created 4 months ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
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 👍