I am trying to integrate my Spring MVC application with Swagger to get the REST API documentation clean and up to date. But I ran into the problem of presenting a java map in the swagger user interface. Here is my simple controller and model:
@Data
@ApiModel
public class User {
@ApiModelProperty(example = "test@example.com")
private String email;
@ApiModelProperty(example = "John")
private String firstName;
@ApiModelProperty(example = "Doe")
private String lastName;
@ApiModelProperty
private Map<String, Address> addresses;
}
@Data
@ApiModel
public class Address {
@ApiModelProperty(example = "Calle 39 No 1540")
private String street;
@ApiModelProperty(example = "B1000TBU")
private String postalCode;
@ApiModelProperty(example = "San Sebastian")
private String city;
@ApiModelProperty(example = "Argentina")
private String country;
}
@RestController
@Api(value = "User Management")
public class UserController {
@ApiOperation("Get a user profile by the email")
@RequestMapping(value = "/user/{email:.+}", method = RequestMethod.GET)
public User getPersonByFirstName(@ApiParam @PathVariable("email") String email) {
return new User();
}
}
To create the Swagger specification, I use the Swagger Maven Plugin. In and I received the following documentation:

Instead of the correct type - Map [String, Address] - I got a weird inline_model. On the Example value tab, the address value is an empty object - {} .
I am trying to specify the data type of this Map field, but none of the following annotations will work:
@ApiModelProperty (value = "" , dataType =
" [, com.redkite.model.Address]" )
@ApiModelProperty (value = "" , dataType = "java.util.Map" )
@ApiModelProperty (value = "" , dataType =
"java.util.Map < java.lang.String, com.redkite.model.Address > " )
, , .
, Swagger java Map ? - - ?
:
- Swagger Maven - 3.1.3 ( 2.0)
- Swagger - 1.5.9
- Swagger - 2.2.10
.