-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Open
Description
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
- Default constructor
- 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>();
}