How to say Swagger attribute is a map

I develop a calm service with Jersey. However, I use Swagger for documentation. My model has a property with a map type. Swagger shows that this attribute as an object (not a specific type). So, how can I tell Swagger that this property is of 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;
    }
}

Late 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 display it as a type Map<Integer, String>.

Swagger shows the documentation like this image. enter image description here

-1
source share
1 answer

You can specify the type of response in the annotation @ApiOperation:

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

Source: https://habr.com/ru/post/1667269/


All Articles