swagger-api / swagger-api/swagger-codegen

Swagger-codegen for sharp not properly calling base constructor for enum in superclass

Open
#8,022 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When I use swagger-codegen to generate a client in sharp using the Json seen in the gist below It does not property set the errorcode in the constructor for the Response[SomeDTO] class, but instead generates the following:

public ResponseImageDTO(bool? success = default(bool?), List<string> errorProperties = default(List<string>), string response = "Response[ImageDTO]") : base(success, errorProperties, errorKey, response) { }

As you can see the errorKey is never set in the constructor only in the call to the constructor of the superclass thus resulting in a syntax error.

If I in the response class change errorkey to the following:

"errorKey":{  
   "$ref":"#/definitions/ErrorCode",
   "readOnly":true
}

Then by using swagger-codegen 2.3.1 it generates the constructor properly but not by using the newest version on master.

However what I would like is that I don't have to ref to the ErrorKey in order for it to be set correctly in the generated constructor.

Swagger declaration content

Small sample:
https://gist.github.com/Flarenityy/ace43932311c9939e96c1af04f0dbaf3

Full sample (however it is huge so I would suggest u look above)
https://gist.github.com/Flarenityy/cacf31288da8db5ae86a65699968eb67

Command line used for generation

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://localhost:5000/swagger/v1/swagger.json -l csharp

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 with the small Swagger declaration in the linked gist and reproduce generation using modules/swagger-codegen-cli/target/swagger-codegen-cli.jar with the csharp language option. Inspect how the generated Response[SomeDTO] constructor handles the inherited enum property. Done means the generated constructor initializes errorKey correctly without requiring an explicit ErrorCode reference and produces valid C#.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.