如何告诉Swagger属性是Map [英] How to tell Swagger an attribute is a Map

查看:2877
本文介绍了如何告诉Swagger属性是Map的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Jersey合作开发一种安心的服务.但是,我正在使用Swagger进行文档编制.我的模型具有地图类型的属性. Swagger显示此属性为Object(不是特定类型).那么如何告诉Swagger此属性来自Map类型?

I am developing a restful service with Jersey. However, I am using Swagger for documentation. My Model has a property with Type of Map. Swagger shows that this attribute as an Object (not a specific type). So how can I tell Swagger that this property is from type Map ?

public class Model {
    private String name;
    private Map<Integer, String> myMap;

    public Model(){
        super();
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Map<Integer, String> getMyMap() {
        return myMap;
    }
    public void setMyMap(Map<Integer, String> myMap) {
        this.myMap = myMap;
    }
}

宁静的服务:

@POST
@Path("/createBundle")
@Consumes({MediaType.APPLICATION_JSON})
@ApiOperation(value = "Create Bundle ",
    notes = "",
    response = Model.class)
    public Model createBundle(Bundle bundle){
        return new Model();
    }

我需要Swagger才能将其显示为Map<Integer, String>类型.

I need Swagger to show it as type of Map<Integer, String>.

Swagger将文档显示为此图像.

Swagger shows the documentation as this image.

推荐答案

您可以在@ApiOperation批注中设置响应类型:

You can set a response type in the @ApiOperation annotation:

@ApiOperation(value = "Find thingies as Map",
    notes = "Multiple thingies can be returned, <code>id</code> is the ID field",
    response = java.util.Map.class)

这篇关于如何告诉Swagger属性是Map的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆