@g00glen00b的答案中提到的问题似乎已得到解决。下面是如何完成的代码片段。
在控制器类中:
// omitted other annotations
@ApiImplicitParams(
@ApiImplicitParam(
name = "body",
dataType = "ApplicationProperties",
examples = @Example(
@ExampleProperty(
mediaType = "application/json",
value = "{\"applicationName\":\"application-name\"}"
)
)
)
)
public Application updateApplicationName(
@RequestBody Map<String, String> body
) {
// ...
}
// Helper class for Swagger documentation - see http://springfox.github.io/springfox/docs/snapshot/#q27
public static class ApplicationProperties {
private String applicationName;
public String getApplicationName() {
return applicationName;
}
public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}
}
此外,您需要将以下行添加到 Swagger 配置中:
// omitted other imports...
import com.fasterxml.classmate.TypeResolver;
@Bean
public Docket api(TypeResolver resolver) {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
// the following line is important!
.additionalModels(resolver.resolve(DashboardController.ApplicationProperties.class));
}
更多文档可以在这里找到:http://springfox.github.io/springfox/docs/snapshot/#q27