Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoints with difference only in return types are resulting in error for C# generator #4448

Closed
derigel23 opened this issue Apr 4, 2024 · 4 comments · Fixed by #4517
Closed
Assignees
Labels
generator Issues or improvements relater to generation capabilities. type:bug A broken experience
Milestone

Comments

@derigel23
Copy link

derigel23 commented Apr 4, 2024

I have an OpenAPI specification for TeamCity.
For example, here https://teamcity.jetbrains.com/guestAuth/app/rest/swagger.json

It compiles with error.
WithPathRequestBuilder.cs(60, 40): [CS0111] Type 'WithPathRequestBuilder' already defines a member called 'GetAsync' with the same parameter types.
Generated C# code is not valid:

        /// <summary>
        /// Get specific file zipped.
        /// </summary>
        /// <returns>A <see cref="Stream"/></returns>
        /// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
        /// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
        public async Task<Stream?> GetAsync(Action<RequestConfiguration<WithPathRequestBuilderGetQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
        {
            var requestInfo = ToGetRequestInformation(requestConfiguration);
            return await RequestAdapter.SendPrimitiveAsync<Stream>(requestInfo, default, cancellationToken).ConfigureAwait(false);
        }
        /// <summary>
        /// Get metadata of specific file.
        /// </summary>
        /// <returns>A <see cref="FileObject"/></returns>
        /// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
        /// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
        public async Task<FileObject?> GetAsync(Action<RequestConfiguration<WithPathRequestBuilderGetQueryParameters>>? requestConfiguration = default, CancellationToken cancellationToken = default)
        {
            var requestInfo = ToGetRequestInformation(requestConfiguration);
            return await RequestAdapter.SendAsync<FileObject>(requestInfo, FileObject.CreateFromDiscriminatorValue, default, cancellationToken).ConfigureAwait(false);
        }

C# can't have overloads with difference only in return type,

@github-project-automation github-project-automation bot moved this to Todo in Kiota Apr 4, 2024
@andrueastman andrueastman added the type:bug A broken experience label Apr 15, 2024
@andrueastman andrueastman added this to the Backlog milestone Apr 15, 2024
@baywet
Copy link
Member

baywet commented Apr 16, 2024

Hi @derigel23
Thanks for using kiota, for reaching out and for your patience.
Can you share which operation/path item is this code snippet for please?
This is most likely cause by a limitation of the generator we have today. See #2317

@baywet baywet added duplicate This issue or pull request already exists enhancement New feature or request Needs: Author Feedback and removed type:bug A broken experience labels Apr 16, 2024
@derigel23
Copy link
Author

Hi @baywet
It seems not my case - I do not have several results for one operation.
I do have several different operations but with the same suffix parameter.
For example
/app/rest/buildTypes/{btLocator}/vcs/files/latest/metadata{path}
/app/rest/buildTypes/{btLocator}/vcs/files/latest/{path}
And that suffix parameter get reused in WithPathRequestBuilderGetQueryParameters but applying it to different paths will result in different result type.

@andrueastman
Copy link
Member

The error here looks to be caused by paths in the descriptions that end up having conflicting request builders.

The following paths end up being resolved to the same request builder by kiota with the name WithPathRequestBuilder. The naming doesn't take the prefix before the indexer into account causing the conflict.

This ends up adding multiple executors to the same class.

/app/rest/server/files/{areaId}/metadata{path}
/app/rest/server/files/{areaId}/{path}
/app/rest/server/files/{areaId}/archived{path}
/app/rest/server/files/{areaId}/files{path}

The metadata{path} and {path} segments end up being mapped to the same request builder rather two separate ones.

The culprit looks to be

private static string CleanupParametersFromPath(string pathSegment)

whose Regex doesn't seem to cater for such a case.
[GeneratedRegex(@"(?:\w+)?=?'?\{(?<paramName>\w+)\}'?,?", RegexOptions.Singleline, 500)]

@andrueastman andrueastman added type:bug A broken experience and removed duplicate This issue or pull request already exists Needs: Attention 👋 enhancement New feature or request labels Apr 19, 2024
@andrueastman andrueastman modified the milestones: Backlog, Kiota v1.14 Apr 19, 2024
@andrueastman andrueastman self-assigned this Apr 19, 2024
@andrueastman andrueastman moved this from Todo 📃 to In Progress 🚧 in Kiota Apr 19, 2024
@andrueastman
Copy link
Member

Authored #4517 to resolve.

@github-project-automation github-project-automation bot moved this from In Progress 🚧 to Done ✔️ in Kiota Apr 22, 2024
@andrueastman andrueastman added the generator Issues or improvements relater to generation capabilities. label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Issues or improvements relater to generation capabilities. type:bug A broken experience
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants