Java 与Dropwizard的Swagger集成
我的资源结构如下:Java 与Dropwizard的Swagger集成,java,swagger,dropwizard,swagger-2.0,Java,Swagger,Dropwizard,Swagger 2.0,我的资源结构如下: @Path("/v1") class A{ @Path("/abc") B getB(){} @Path("/xyz") C getC(){} } 在B类和C类中定义了API。您能告诉我在哪里使用@Api()和@ApiOperation()注释吗。因为在尝试了很多可能性之后,这对我来说是行不通的。它仍然没有出现在swagger.json中 同样,在应用程序中类中,我必须只添加A,而不是B和C。在类级别使用@Api,在方法级别使用@ApiOperat
@Path("/v1")
class A{
@Path("/abc")
B getB(){}
@Path("/xyz")
C getC(){}
}
在B类
和C类
中定义了API。您能告诉我在哪里使用@Api()
和@ApiOperation()
注释吗。因为在尝试了很多可能性之后,这对我来说是行不通的。它仍然没有出现在swagger.json中
同样,在
应用程序中
类中,我必须只添加A,而不是B和C。在类级别使用@Api
,在方法级别使用@ApiOperation
。您可以相应地将代码修改为以下原型:
import javax.ws.rs.*;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiResponse;
import com.wordnik.swagger.annotations.ApiResponses;
@Path("/v1")
@Api(value = "/v1", description = "Things at A")
class A {
@GET
@Path("/abc/{path}")
@ApiOperation(value = "Things from B", response = B.class)
@ApiResponses(value = {
@ApiResponse(code=HttpStatus.SC_OK, message="OK"),
@ApiResponse(code=HttpStatus.SC_INTERNAL_SERVER_ERROR, message="Server Error")
})
B getB(@PathParam("path") String pathParam) {
// perform ABC task
}
@POST
@Path("/xyz")
@ApiOperation(value = "Things from B", response = C.class)
@ApiResponses(value = {
@ApiResponse(code=HttpStatus.SC_OK, message="OK")
@ApiResponse(code=HttpStatus.SC_BAD_REQUEST, message="Bad Request")
})
C getC(@ApiParam RequestC requestC) {
//perform XYZ task
}
}
此外,在应用程序类中,可以将重写的run()
注册调用添加为:
@Override
public void run(SwaggerCustomConfig config, Environment environment) throws Exception {
environment.jersey().register(A.class);
....
}
你看过吗?