OpenAPITools / OpenAPITools/openapi-generator
[BUG] [CSHARP] openapi-generator-cli produces invalid constructors with AllOf
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [ X ] Have you provided a full/minimal spec to reproduce the issue?
- [ X ] Have you validated the input using an OpenAPI validator (example)?
- [ X ] Have you tested with the latest master to confirm the issue still exists?
- [ X ] Have you searched for related issues/PRs?
- [ X ] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The C# client API code generator produces constructors that will not compile:
The spec contains cases where derived classes inherit from base classes using AllOf. In some cases, the derived class contains properties that shadow properties in the base class, possibly with different types, though I'm not sure that is relevant here.
The generator produces constructors for the derived types that call the base type constructors. Some of the arguments to the base type constructors are not present in the derived type constructor, so the code will not compile due to undefined arguments to the base constructor.
In many cases, the generator injects an argument, "type", as the last argument to the base constructor call, even though no such property exists in the base type, and no such argument is expected in the base constructor.
e.g., This constructor is created:
public SimpleProjectCustomField(CustomField field = default(CustomField), Project project = default(Project), bool canBeEmpty = default(bool), string emptyFieldText = default(string), int ordinal = default(int), bool isPublic = default(bool), CustomFieldCondition condition = default(CustomFieldCondition)) : base(field, project, canBeEmpty, emptyFieldText, ordinal, isPublic, hasRunningJob, condition, type)
In this case, the argument, "hasRunningJob" is not defined anywhere. It is an expected argument in the base constructor, but is absent in the parameter list of the derived constructor. The argument, "type", in the base constructor is neither defined nor expected - it just appears with no apparent reason.
openapi-generator version
openapi-generator-7.4.0
OpenAPI declaration file content or url
Generation Details
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="openapi-generator-cli-7.4.0.jar"
"$java" -jar $jar generate -i YouTrack.json -o api -g 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
- Build the solution
- Look at the constructor for any of the failed types
- The "type" argument is added to the base constructor
- The base constructor references variables that do not exist in the derived constructor
Related issues/PRs
Could not find similar PRs
Suggest a fix
I have no suggestions for a fix. This is a code generation error.
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
Reproduce the generator command with YouTrack.json and config.json, then inspect the generated C# constructors in the api/Cogent YouTrack.sln output. Compare derived constructor parameters with the arguments passed to each base constructor. Done means the generated solution builds without undefined or unexpected constructor arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100