Open
Description
Hi there
Problem
We're working with an API which endpoints contain trailing slashes, for example {+baseUrl}/api/v1/app/{app_id}/msg/
.
During the client generation, the trailing slash is dropped, and the generated client doesn't work as expected as all requests return a 404.
Repro
For reference, here's a link to the OpenAPI document used here: https://github.com/svix/svix-webhooks/blob/8d32e47e0484f5d0839bce364d8700d2c7457937/openapi.json#L7779
- Generate the .NET client
kiota generate ` --openapi https://raw.githubusercontent.com/svix/svix-webhooks/main/openapi.json ` --output .\TrailingSlashDroppedIssue4291 ` --language CSharp ` --class-name SvixClient ` --namespace-name SvixApiClient ` --exclude-backward-compatible true ` --serializer Microsoft.Kiota.Serialization.Json.JsonSerializationWriterFactory ` --deserializer Microsoft.Kiota.Serialization.Json.JsonParseNodeFactory ` --structured-mime-types application/json ` --include-path '/api/v1/app/{app_id}/msg/#POST'
- See the missing trailing slashes in the constructor definitions in the
TrailingSlashDroppedIssue4291\Api\V1\App\Item\Msg\MsgRequestBuilder.cs
filepublic class MsgRequestBuilder : BaseRequestBuilder { public MsgRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/v1/app/{app_id}/msg{?with_content*}", pathParameters) { } public MsgRequestBuilder(string rawUrl, IRequestAdapter requestAdapter) : base(requestAdapter, "{+baseurl}/api/v1/app/{app_id}/msg{?with_content*}", rawUrl) { } }
Expected result
Kiota shouldn't manipulate paths defined in the OpenAPI document, or should provide an option to opt out of this behavior.
Metadata
Metadata
Assignees
Type
Projects
Status
In Progress 🚧
Activity
baywet commentedon Mar 5, 2024
Hi @mderriey,
Thanks for using kiota and for reaching out.
Let me start by saying that while requiring trailing slashes is supported according to RFCs 9110 and 3986, it's a bit unusual from a REST API design perspective, see this stack overflow post. This is not an excuse, just adding some perspective here.
Kiota generates the URI templates here and additional unit tests can be added here
The challenge is that kiota relies on OpenAPI.net to parse the description and build the tree of the API. And that process kind of relies on trimming the trailing slashes to work as you can see here and there. In fact it's removing the trailing slash
From kiota's perspective, the trailing slash doesn't exist, and adding it systematically would be wrong in the same sense it's wrong to remove it.
What needs to happen it:
Would you be willing to work on a pull request for openapi.net?
mderriey commentedon Mar 6, 2024
mderriey commentedon Mar 6, 2024
My bad, please ignore my last message, after writing a test in the Kiota codebase, I can see now how it comes from
OpenApiUrlTreeNode
, which you originally pointed to. And I also realised what I thought was the leading slash is actually the trailing slash as it works segment by segment.Let me open an issue in the OpenAPI.NET repo, thanks again.
jlarmstrongiv commentedon Oct 2, 2024
We just fixed trailing slashes in the OpenAPI.NET repo via microsoft/OpenAPI.NET#1835, which was released in 1.6.22.
Can we update the OpenAPI.NET dependency to see if it adds trailing slash support in Kiota?
jlarmstrongiv commentedon Oct 2, 2024
It looks like the OpenAPI.NET dependency was already updated by dependabot https://github.com/microsoft/kiota/blob/main/src/Kiota.Builder/Kiota.Builder.csproj#L47 once the latest preview includes it, I’ll try it out.
13 remaining items
sevein commentedon Oct 18, 2024
Oh no! I only tested with a Go client.
baywet commentedon Oct 18, 2024
@jlarmstrongiv thanks for letting us know! Do you have more context to share around this issue?