swagger-api / swagger-api/swagger-codegen
[JAVA] Definition of HasMap<String, List<Element>>
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
This issue is about domain class definition. To map some third libraries data, I need to define an object representing a HashMap<String, List>. The generated class Only extends HashMap<String, List> witch breaks the serialization.
Swagger-codegen version
3.0.41
Swagger declaration file content
---
swagger: "2.0"
info
description: "File to reproduce the issue"
version: "1.0.0"
title: "Issue file"
definition:
MainHashMapObject:
type: object
additionalProperties:
type: array
items:
type: object
$ref: '#/definitions/HashMapElement'
HashMapElement:
type: object
properties:
name:
type: string
Command used for generation
io.swagger.codegen.v3.swagger-codegen-maven-plugin
Steps to reproduce
Init a maven project using the swagger gen plugin.
With this set, and the given yaml file, generate java files.
You will get a MainHashMapObject.java defining a class wich extends HashMap<String, List>.
The problem is : for deserialization, this class will generate HashMap<String, List> as it doesn't know about the type of the list's objects.
Suggest a fix/enhancement
Is it possible to always add type paramters to parameterized type in any definitions (fields / extends / implements / function / ...) ?
Eg : List<HashMapElement> insteed of List
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the Swagger 2.0 YAML and the io.swagger.codegen.v3.swagger-codegen-maven-plugin at version 3.0.41. Inspect the generation path for MainHashMapObject.java and its parameterized collection types. Done means the generated class preserves HashMap<String, List> so deserialization retains the list element type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100