我使用swagger来生成Java和Type脚本中的类。我在用对象列表作为值定义map属性时遇到了问题。我试图将其定义如下:
DataMap
type: object
additionalProperties:
#type: array -- This config does not work.
$ref: '#/definitions/Data'
上面的yml定义用java生成了以下代码:
class DataMap extends HashMap<String, Data> {
}
如何配置yml以生成包含数据列表的密钥?就像下课一样:
class DataMap extends HashMap<String, List<Data>> {
}
或
class DataInfo {
Map<String, List<Data>> dataMap;
}
如果使用swagger2.0,这有可能吗?我正在考虑定义另一个DataList类,它扩展了ArrayList,然后将该类用作映射的值。
谢谢@nickb
我使用swagger-codegen-maven-plugin版本2.2.1和yml定义生成地图,如下所示:
DataInfo
type: object
properties:
dataMap:
type: object
additionalProperties:
type: array
items:
$ref: '#/definitions/Data'
发布于 2017-07-11 13:14:26
我使用Swagger codegen v2.1.6的模型定义如下:
foo:
properties:
baz:
type: string
bar:
properties:
map:
type: object
additionalProperties:
type: array
items:
$ref: '#/definitions/foo'
这将生成一个具有以下字段的Bar
类:
Map<String, List<Foo>> map = new HashMap<String, List<Foo>>();
如果你看到的是不同的行为,你可能会陷入倒退。尝试测试早期版本,或者具体地查看2.1.6是否正确地生成此模型。
https://stackoverflow.com/questions/45027428
复制相似问题