How to tell Swagger an attribute is a Map

帅比萌擦擦* 提交于 2019-12-06 13:32:25

问题


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;
    }
}

The restful service:

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

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

Swagger shows the documentation as this image.


回答1:


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)


来源:https://stackoverflow.com/questions/35411621/how-to-tell-swagger-an-attribute-is-a-map

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!