Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10894
Closed
Open
Issue created Nov 19, 2021 by Administrator@rootContributor6 of 6 checklist items completed6/6 checklist items

[BUG][csharp-netcore] C# Model never calls default constructor, it always calls parametrized constructor

Created by: Ghufz

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

C# Model has two constructor

  1. Default constructor
  2. Parameterized constructor

When we create a object using default constructor , it never calls the default constructor it always calls the parametrized constructor which has default value for all the parameters.
Example code defined in the class

public CommHttpProxyPolicy
{
[JsonConstructorAttribute]
        protected CommHttpProxyPolicy()
        {
            this.AdditionalProperties = new Dictionary<string, object>();
        }
       
       public CommHttpProxyPolicy(ClassIdEnum classId = ClassIdEnum.CommHttpProxyPolicy, ObjectTypeEnum objectType = ObjectTypeEnum.CommHttpProxyPolicy, List<HyperflexClusterProfileRelationship> clusterProfiles = default(List<HyperflexClusterProfileRelationship>), string moid = default(string), List<string> owners = default(List<string>), List<MoTag> tags = default(List<MoTag>), MoVersionContext versionContext = default(MoVersionContext), MoBaseMoRelationship parent = default(MoBaseMoRelationship), string description = default(string), string name = default(string), string hostname = default(string), string password = default(string), long port = default(long), string username = default(string), OrganizationOrganizationRelationship organization = default(OrganizationOrganizationRelationship)) : base()
        {
            this.ClassId = classId;
            this.ObjectType = objectType;
            this.ClusterProfiles = clusterProfiles;
            this.AdditionalProperties = new Dictionary<string, object>();
        }
}

when we create a object for the above class

CommHttpProxyPolicy comm = new CommHttpProxyPolicy() // it always calls the parametrized constructor

ideally it should call the default constructor.

openapi-generator version

OAS v3

OpenAPI declaration file content or url
Generation Details
Steps to reproduce

create the object using default constructor

CommHttpProxyPolicy comm = new CommHttpProxyPolicy() // it always calls the parametrized constructor even no parameter is specified.
Related issues/PRs
Suggest a fix

We can initialize the properties using default constructor with defaults.

protected CommHttpProxyPolicy()
        {
            this.AdditionalProperties = new Dictionary<string, object>();
           ClassId = ClassIdEnum.CommHttpProxyPolicy; 
ObjectType = ObjectTypeEnum.CommHttpProxyPolicy; 
ClusterProfiles = default(List<HyperflexClusterProfileRelationship>);
 Moid = default(string); 
Owners = default(List<string>);
 Tags = default(List<MoTag>);
VersionContext = default(MoVersionContext); 
Parent = default(MoBaseMoRelationship); 
Description = default(string); 
Name = default(string); 
Hostname = default(string); 
Password = default(string);
 Port = default(long); 
Username = default(string); 
Organization = default(OrganizationOrganizationRelationship)
        }

but for parametrized constructor we should not use parameters with default value.

public CommHttpProxyPolicy(ClassIdEnum classId , ObjectTypeEnum objectType , List<HyperflexClusterProfileRelationship> clusterProfiles, string moid , List<string> owners , List<MoTag> tags , MoVersionContext versionContext, MoBaseMoRelationship parent , string description , string name , string hostname , string password , long port , string username , OrganizationOrganizationRelationship organization ) : base()
        {
            this.ClassId = classId;
            this.ObjectType = objectType;
            this.ClusterProfiles = clusterProfiles;
            this.AdditionalProperties = new Dictionary<string, object>();
        }
Assignee
Assign to
Time tracking