swagger-api / swagger-api/swagger-codegen
Use LinkedHashMap instead of HashMap for Swagger dictionary type (Java codegen)?
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
I'm using openapi 3.0.2, and the codegen plugin:
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.14</version>
I'm using the swagger dictionary/hashmap type described here:
https://swagger.io/docs/specification/data-models/dictionaries/
openapi: "3.0.2"
...
Labels:
type: object
additionalProperties:
type: string
minLength: 1
description: A description.
When I generate Java code for this, it is modelled as a class which extends HashMap:
@ApiModel(description = "A description.")
@Validated
@javax.annotation.Generated(value = "io.swagger.codegen.v3.generators.java.SpringCodegen", date = "2020-02-26T12:17:36.248Z[Europe/London]")
public class Labels extends HashMap<String, String> {
...
}
Is there any way to instruct swagger to use a LinkedHashMap instead of a HashMap? (without having to exclude this class from codegen and manually modify it).
I would like to control the ordering of the entries in this dictionary when returning it to clients.
Related: https://github.com/swagger-api/swagger-core/issues/2021
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
Start with the swagger-codegen-maven-plugin 3.0.14 and its Java codegen path, since no specific files or tests are named. Trace how the OpenAPI additionalProperties dictionary becomes a Java HashMap and identify whether the map type can be configured. Done means generated dictionary models use LinkedHashMap without manual edits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100