我们有一个带dao和GET端点的简单控制器:
@Api("users")
@Named
@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
public class UserController {
private final UserDao userDao;
@Inject
public AdController(KeywordsDao userDao) {
this.userDao = userDao;
}
@GET
public Response getUser(@QueryParam("id") int userId) {
User res = userDao.getUser(userId);
return Response.ok(res).build();
}
}
class User {
@JsonProperty
private int id;
@JsonProperty
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
展示问题的swagger.json
的一部分:
...
"paths" : {
"/users" : {
"get" : {
"tags" : [ "users" ],
"operationId" : "getUsers",
"produces" : [ "application/json" ],
"parameters" : [
{
"in" : "body",
"name" : "body",
"required" : false,
"schema" : {
"$ref" : "#/definitions/UserDao"
}
}, {
"name" : "userId",
"in" : "query",
"required" : false,
"type" : "integer",
"format" : "int32"
} ]
...
任何想法如何摆脱那些"隐含的"参数?它们在Swagger UI中看起来真的很混乱。
项目的一般配置:RESTEasy 3.0.11 + spring-context 3.2.14 + swagger-jaxrs 1.5.4。
使用BeanConfig
和ApiListingResource
配置Swagger,它在应用程序上下文中声明:
....
<bean class="io.swagger.jaxrs.listing.ApiListingResource"/>
<bean id="beanConfig" class="io.swagger.jaxrs.config.BeanConfig">
<property ...
</bean>
....