microsoft / kiota

OpenAPI based HTTP Client code generator
https://aka.ms/kiota/docs
MIT License
2.45k stars 174 forks source link

Child path/RequestBuilder with same name as parent not reachable in generated C# client #4831

Open CocoDico78 opened 3 weeks ago

CocoDico78 commented 3 weeks ago

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

I am trying to generate client code with Kiota 1.15.0 for this openAPI document:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Sample API with repeated paths",
    "version": "1.0.0"
  },
  "paths": {
    "/sample/sample": {
      "get": {
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}

but the generated code looks like

namespace ApiSdk.Sample;
public class SampleRequestBuilder : BaseRequestBuilder
{
    // Returns an instance of itself instead of the nested RequestBuilder... It is missing an extra "Sample" in the namespace
    public ApiSdk.Sample.SampleRequestBuilder Sample => new ApiSdk.Sample.SampleRequestBuilder(PathParameters, RequestAdapter);
    // [...]
}

Expected behavior

Generated code should look like

namespace ApiSdk.Sample;
public class SampleRequestBuilder : BaseRequestBuilder
{
    public ApiSdk.Sample.Sample.SampleRequestBuilder Sample => new ApiSdk.Sample.Sample.SampleRequestBuilder(PathParameters, RequestAdapter);
    // [...]
}

(notice the extra Sample namespace)

How to reproduce

Run kiota generate -l CSharp -d ./definition_problematic.json -o ./Client

Or see repro repository here.

Open API description file

definition_problematic.json

Kiota Version

1.15.0+b535a94064cd8c14a022aaba42964467d5db525a

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

I have to go in after generation and manually append the missing namespace segments.

Configuration

No response

Debug output

No response

Other information

No response

baywet commented 2 weeks ago

Thanks for reporting this. Potentially related #4814 and #4796