OpenAPITools / OpenAPITools/openapi-generator
[BUG] csharp generichost generator generates duplicate api methods
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generated .NET code seems to generate duplicate API methods.
For example, in GroupsApi.cs:
public interface IGroupsApi : IApi
{
...
Task<IGetGroupsIdApiResponse> GetGroupsIdAsync(int id, System.Threading.CancellationToken cancellationToken = default);
Task<IGetGroupsIdApiResponse?> GetGroupsIdOrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default);
Task<IGetGroupsId_0ApiResponse> GetGroupsId_0Async(int id, System.Threading.CancellationToken cancellationToken = default);
Task<IGetGroupsId_0ApiResponse?> GetGroupsId_0OrDefaultAsync(int id, System.Threading.CancellationToken cancellationToken = default);
...
I don't see any differences between the duplicated API methods.
openapi-generator version
7.9.0
OpenAPI declaration file content or url
Generation Details
csharp.config
{
"apiName": "FilesComApi",
"library": "generichost",
"netCoreProjectFile": true,
"nullableReferenceTypes": true,
"optionalAssemblyInfo": true,
"packageName": "Files.Com.Core",
"targetFramework": "net8.0",
"sourceFolder": "src"
}
Steps to reproduce
- Create csharp.config file
- Execute the following:
nvm install latest
nvm use latest
npm install -g npm@latest
npm install @openapitools/openapi-generator-cli -D
curl -o filescom-v1.json https://app.files.com/api/rest/v1/swagger_doc.json
npx @openapitools/openapi-generator-cli generate -i .\filescom-v1.json -o .\generated -g csharp -c csharp.config
Build
cd generated
dotnet new globaljson --sdk-version 8.0.400 --roll-forward feature
dotnet build
Related issues/PRs
#19626
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated GroupsApi.cs and csharp.config, then reproduce the duplicate methods using the provided OpenAPI document and generator command. Compare the GetGroupsIdAsync and GetGroupsId_0Async variants, and confirm the fix by generating the client again and running dotnet build without duplicate API methods.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100