Skip to content

Trailing slash in URL is dropped during generation #4291

Open
@mderriey

Description

@mderriey

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

  1. 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'
    
  2. See the missing trailing slashes in the constructor definitions in the TrailingSlashDroppedIssue4291\Api\V1\App\Item\Msg\MsgRequestBuilder.cs file
    public 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.

Activity

baywet

baywet commented on Mar 5, 2024

@baywet
Member

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:

  1. OpenAPI.net needs to updated to keep the trailing slash without derailing the control logic
  2. Once the patch is released and pulled in kiota, the slash should appear "magically"

Would you be willing to work on a pull request for openapi.net?

added
type:bugA broken experience
help wantedIssue caused by core project dependency modules or library
dependenciesPull requests that update a dependency file
blockedThis work can't be done until an external dependent work is done.
on Mar 5, 2024
added this to the Backlog milestone on Mar 5, 2024
mderriey

mderriey commented on Mar 6, 2024

@mderriey
Author
mderriey

mderriey commented on Mar 6, 2024

@mderriey
Author

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

jlarmstrongiv commented on Oct 2, 2024

@jlarmstrongiv

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

jlarmstrongiv commented on Oct 2, 2024

@jlarmstrongiv

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

sevein commented on Oct 18, 2024

@sevein
Contributor

Oh no! I only tested with a Go client.

reopened this on Oct 18, 2024
moved this from Done ✔️ to In Progress 🚧 in Kiotaon Oct 18, 2024
baywet

baywet commented on Oct 18, 2024

@baywet
Member

@jlarmstrongiv thanks for letting us know! Do you have more context to share around this issue?

linked a pull request that will close this issue on Oct 21, 2024
modified the milestones: Kiota v1.21, Kiota v1.22 on Dec 5, 2024
removed this from the Kiota v1.24 milestone on Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    WIPhelp wantedIssue caused by core project dependency modules or librarytype:bugA broken experience

    Type

    No type

    Projects

    Status

    In Progress 🚧

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @sevein@mderriey@andrueastman@baywet@jlarmstrongiv

      Issue actions

        Trailing slash in URL is dropped during generation · Issue #4291 · microsoft/kiota