swagger-api / swagger-api/swagger-codegen

Swagger-codegen cannot create model object for List<Map<String,Integer>>

Open
#11,107 0 comments 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

Hello team,

We are facing strange issue with our automation, using swagger-codegen(version doesn't matter, in our case 2.4.9) We have the following class:
public class Foo {
private List<Map<String, Long>> fooLong;
private List<Map<String, Integer>> fooInteger;
}

When we execute the step in which swagger codegen generates stubs, it creates 3 classes, 2 of them are as follows:

  • MapstringlongModel
  • MapstringintModel

In first case everything seems OK, the stub is created like this:

  • public class MapstringlongModel extends HashMap<String, Long> {....}
    and everything is imported properly.

In the second case, it looks strange

  • public class MapstringintModel extends HashMap<String, IntegerModel> {.....}
    and also there is an import "com.foo.IntegerModel".

This import cannot be resolved, as such a class is not generated and respectively do not exist. This can be easily fixed if we delete manually this strange import and change IntegerModel with Integer like this:

  • public class MapstringintModel extends HashMap<String, Integer> {....}

The problem is that all this things are automated and we do not submit or do any manual actions as all these steps(including much more) are automated and practically this wrong import breaks our implementation. I am not sure why IntegerModel is generated(or actually not), instead of Integer and if this is correct. But we cannot find a workaround and will appreciate if you have suggestion how we can go through this problem and does somebody already met it at all? Many thanks in advance.

Regards,
SK

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 the generated Foo model and comparing the MapstringlongModel and MapstringintModel outputs described in the report. Trace why the Integer case emits IntegerModel and an unresolved com.foo.IntegerModel import; done means the generated class uses Integer and contains no invalid import.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.