如何在swagger yml中定义HashMap <String,List >属性?
我正在使用swagger在Java和Type脚本中生成类。 我有问题定义map属性与对象列表作为值。 我试着定义如下:
DataMap type: object additionalProperties: #type: array -- This config does not work. $ref: '#/definitions/Data'
在java中生成以下代码的yml定义:
class DataMap extends HashMap { }
如何配置yml以生成包含数据列表的密钥? 类似下面的课:
class DataMap extends HashMap<String, List> { }
要么
class DataInfo { Map<String, List> dataMap; }
swagger 2.0有可能吗? 我正在考虑定义另一个扩展ArrayList的DataList类,然后将此类用作Map的值。
————–更新和答案———–
谢谢@nickb
我使用swagger-codegen-maven-plugin版本2.2.1和yml定义来生成map,如下所示:
DataInfo type: object properties: dataMap: type: object additionalProperties: type: array items: $ref: '#/definitions/Data'
我正在使用Swagger codegen v2.1.6以及以下模型定义:
foo: properties: baz: type: string bar: properties: map: type: object additionalProperties: type: array items: $ref: '#/definitions/foo'
这将生成一个Bar
Java类,其中包含以下字段:
Map> map = new HashMap>();
如果你看到不同的行为,你可能会偶然发现回归。 尝试测试早期版本,或者专门查看2.1.6是否正确生成此模型。