我在我的Apache CXF项目中使用了Swagger,使用了@Api、@ApiOperation和@ApiParam注解,并为REST服务生成了API文档。
但是我想从模型属性或完整模块或属性中排除一些字段,例如EntityTag、StatusType和MediaType等。
如何实现这一点?
我从数据库中获取数据并将其设置为用户对象,然后将该用户对象传递给JAX-RS响应构建器。
以下是我的DTO对象之一:
@ApiModel
public class User{
private String name;
private String email;
@ApiModelProperty(position = 1, required = true, notes = "used to display user name")
public int getName() {
return name;
}
public void setName(String name) {
this.name= name;
}
@ApiModelProperty(position = 2, required = true, notes = "used to display user email")
public int getEmail() {
return email;
}
public void setEmail(String email) {
this.email= email;
}
现在我在Swagger返回的 JSON 格式中看不到 User 对象的字段或属性。
我的服务类方法响应是:
@GET
@ApiOperation(value = "xxx", httpMethod = "GET", notes = "user details", response = Response.class)
public Response getUserInfo(){
User userdto = userdaoimpl.getUserDetails();
ResponseBuilder builder = Response.ok(user, Status.OK), MediaType.APPLICATION_JSON);
builder.build();
}
<bean id="swaggerConfig" class="com.wordnik.swagger.jaxrs.config.BeanConfig">
<property name="resourcePackage" value="com.services.impl" />
<property name="version" value="1.0.0" />
<property name="basePath" value="http://localhost:8080/api" />
<property name="license" value="Apache 2.0 License" />
<property name="licenseUrl"
value="http://www.apache.org/licenses/LICENSE-2.0.html" />
<property name="scan" value="true" />
</bean>