OpenAPITools / OpenAPITools/openapi-generator
[REQ] [csharp],[csharp-netcore] Add Parameter Less Default Constructors For Model Classes
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I've been using openapi-generator-cli for generating APIClient Nugets to be used in .Net Framework, .Net Core Web Apps.
But I'm not able to use generated models as parameter in a [Post] Action methods as default conversion from Post Body (JSON) to Class Object requires a parameter less constructor (a default constructor). But the generated models only have a parameterized constructor, which then results in an error.
Probable solution
Adding a default constructor in all Model classes will be very helpful.
As of now the only solution is to create similar Model classes in Web App itself and when calling an API convert that Web App's Model To APIClient's Model (generated model).
Here's how its being generated using v4.3.1

And here's how it could be generated to resolve the issue. having a default constructor with another parameterized constructor

Not sure how much work is needed here, but i would really appreciate if we can have this added.
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 reproducing generation with the C# and C# .NET Core generators described in the issue, then locate the model-generation templates they use. Done means generated model classes expose a parameterless constructor while retaining the existing parameterized constructor, and the result supports JSON request-body conversion in the reported .NET scenarios.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100