swagger-api / swagger-api/swagger-codegen
[CSHARP] swagger-codegen-cli produces invalid constructors with AllOf
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The C# client API code generator produces constructors that are wrong in a few ways:
- Members in the derived class that shadow members in the AllOf class appear twice in the constructor parameters
- Some constructor parameters in the derived class are missing
- The base class constructor is missing parameters
- The call to the base class constructor uses parameters that are not in the parameter list of the derived class constructor
e.g., public DerivedClass (string a, string b) : BaseClass (a, c)
Swagger-codegen version
swagger-codegen-3.0.52
Swagger declaration file content or url
Attached file is the OpenAPI definition file for YouTrack (https://www.jetbrains.com/youtrack/)
config.json
YouTrack.json
Command line used for generation
export JAVA_HOME="c:\Program Files\Java\jdk-18.0.1.1"
java="c:/Program Files/Java/jdk-18.0.1.1/bin/java"
jar="swagger-codegen-3.0.52\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar"
"$java" -jar $jar generate -i YouTrack.json -o api -l csharp -c config.json
Steps to reproduce
- Build the API using the above command
- Open the resulting api/Cogent YouTrack.sln file in Visual Studio 2022
- Change the target framework in the Cogent.YouTrack project to version 4.6.2
- Build the solution
- Look at the constructor for Article in Mode/Article.cs
- Some arguments are duplicated
- The "id" argument to the base() constructor is undefined
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/11905
https://github.com/swagger-api/swagger-codegen/issues/11900
Suggest a fix/enhancement
I have no suggestions. It just appears to be broken.
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
Generate the API from YouTrack.json using the stated swagger-codegen-cli command and inspect api/Mode/Article.cs, especially its constructor and base() call. Compare the generated constructors against the AllOf model relationships described in the issue; done means the generated Cogent YouTrack solution builds for .NET Framework 4.6.2 without duplicated, missing, or undefined constructor arguments.
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