microsoft / microsoft/kiota

Trailing slash in URL is dropped during generation

Open
#4,291 11 comments 1 reaction 0 assignees View on GitHub
help wanted type:bug WIP
Dominant language
C#
Stars
3.8k
Forks
333
Avg merge
16h 29m
Merged PRs (30d)
116

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:

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'
```
1. See the missing trailing slashes in the constructor definitions in the `TrailingSlashDroppedIssue4291\Api\V1\App\Item\Msg\MsgRequestBuilder.cs` file
```csharp
public class MsgRequestBuilder : BaseRequestBuilder {
public MsgRequestBuilder(Dictionary 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.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided kiota generate command and OpenAPI document. Inspect the generated TrailingSlashDroppedIssue4291\Api\V1\App\Item\Msg\MsgRequestBuilder.cs constructors and trace how the `/api/v1/app/{app_id}/msg/` path becomes the emitted template. Done means generated request-builder URLs preserve the documented trailing slash and the existing reproduction no longer returns 404.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.