OpenAPITools / OpenAPITools/openapi-generator
[csharp-netcore] Generic Host: Generated Model ctor misses 'this.' references
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When generating a csharp-netcore client with the "generichost" library, the resulting constructor doesn't reference its properties correctly, which results in a not functioning ctor, since both property and argument names are the same and no values are getting assigned to the class properties.
i.e.:
public User(long? id = default, string? username = default, string? firstName = default, string? lastName = default, string? email = default, string? password = default, string? phone = default, int? userStatus = default)
{
id = id;
username = username;
firstName = firstName;
lastName = lastName;
email = email;
password = password;
phone = phone;
userStatus = userStatus;
}
openapi-generator version
6.0.1
Command line used for generation
java -jar openapi-generator-cli-6.0.1.jar generate \
-i https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml \
-g csharp-netcore \
-c config.json \
-o ./client-stub
and here the config.json:
{
"packageName": "TemplateApi",
"optionalAssemblyInfo": true,
"optionalProjectFile": true,
"targetFramework": "net6.0",
"modelPropertyNaming": "original",
"netCoreProjectFile": true,
"library": "generichost"
}
Steps to reproduce
Generate a sharp-netcore client with "generichost" library ;)
Related issues/PRs
#12793
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 by running the provided openapi-generator command with the generichost configuration and inspect the generated User constructor. Trace the csharp-netcore generichost generation template responsible for that constructor and compare its assignments with the expected property references. Done means generated constructors assign arguments to their corresponding properties rather than to themselves.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100