OpenAPITools / OpenAPITools/openapi-generator

[REQ] [csharp],[csharp-netcore] Add Parameter Less Default Constructors For Model Classes

Open
#8,162 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Enhancement: Feature
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

image

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

image

Not sure how much work is needed here, but i would really appreciate if we can have this added.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.