对于Swagger字典类型(Java codegen),是否使用LinkedHashMap而不是HashMap?
我正在使用openapi 3.0.2和codegen插件:
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.14</version>
我使用的是这里描述的招摇字典/哈希映射类型:
https://swagger.io/docs/specification/data-models/dictionaries/
openapi: "3.0.2"
...
Labels:
type: object
additionalProperties:
type: string
minLength: 1
description: A description.
当我为它生成Java代码时,它被建模为一个类,扩展了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> {
...
}
有没有什么方法可以指导斯威格使用LinkedHashMap
而不是HashMap
?(无需将此类从codegen中排除并手动修改)
我想在将词典返回给客户时控制词典中条目的顺序
# 1 楼答案
我使用maven插件修改生成的文件: