OpenAPITools / OpenAPITools/openapi-generator

When polymorphism is present, csharp code has an issue on positional parameters

Open
#3,475 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp Feature: Composition / Inheritance Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

CSharp client for framework netcoreapp2.0 version.
When polymorphism is present, such as MyJob extends Job, MyJob constructor calls base constructor
with not named arguments, when these arguments are not optional.
This issue occurs when a parameter is Enum type and so it's required, not optional

public partial class Job :  IEquatable<Job>, IValidatableObject
{
  public Job(long? jobId = default(long?), JobStatusEnum? jobStatus = default(JobStatusEnum?), string name = default(string))
  {
  ...
  }
}

public partial class MyJob : Job,  IEquatable<MyJob>, IValidatableObject
{
  public MyJob(...) : base(jobStatus)
}
Swagger-codegen version

swagger-codegen-cli-2.4.0-20181007.065826-339

Suggest a fix/enhancement
public partial class MyJob : Job,  IEquatable<MyJob>, IValidatableObject
{
  public MyJob(...) : base(jobStatus: jobStatus)
}

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

Reproduce the issue with a polymorphic model where the base constructor has a required enum parameter, then trace the C# generator's model-constructor emission. Compare the generated derived constructor's base call with the requested named-argument form; done means valid C# is generated for this case and the regression is covered by an appropriate generator test.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.