我想为使用Jersey开发的ReST服务生成Swagger API文档。
我已经阅读了Swagger API文档并按照文档进行了部署。
但是当我访问URL(http://localhost:8080/MySwagger/swagger.json)时,我得到以下输出。
{
"swagger" : "2.0",
"info" :
{
"version" : "1.0.2",
"title" : "UUK"
},
"host" : "localhost:8080",
"basePath" : "/MySwagger",
"schemes" : [ "http" ]
}
上述内容不包含我们开发的API
我已尝试过文档中提到的各种选项,但结果是一样的。
我已在tomcat 7.0.68中部署了该应用程序。
我的Java版本是7
我已经使用maven下载依赖项Jars并手动将Jars复制到/ WEB-INF / lib目录
mvn dependency:get -DgroupId=io.swagger -DartifactId=swagger-jersey2-jaxrs -Dversion=1.5.7
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>
io.swagger.jaxrs.listing.ApiListingResource,
io.swagger.jaxrs.listing.SwaggerSerializers,
test.EventReceiver
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>SwaggerBootstrap</servlet-name>
<servlet-class>test.bootstrap.SwaggerApplication</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
import io.swagger.jaxrs.config.BeanConfig;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
public class SwaggerApplication extends HttpServlet
{
private static final long serialVersionUID = 1L;
@Override
public void init(ServletConfig config) throws ServletException
{
super.init(config);
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath(config.getServletContext().getContextPath());
beanConfig.setTitle("UUK");
beanConfig.setResourcePackage("io.swagger.resources");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
}
}
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path(value="/v1/")
@Api(value="inboundtransaction" ,description = "Receive Inbound transaction", position = 1, protocols = "http")
public class EventReceiver
{
@POST
@Path(value="/inboundtransaction")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_JSON })
@ApiOperation(value="Receiving Inbound transaction from X", notes = "Must Contain ID",httpMethod = "POST",response=String.class)
@ApiResponses(value =
{
@ApiResponse(code = 201, message = "Received request and process later", response=String.class),
@ApiResponse(code = 400, message = "Server Busy. Please re-send later", response=String.class)
}
)
public String inboundtransaction(
@ApiParam(value = "Pass mandatory values to create EdiAddress",required = true) String data
)
{
return "Success";
}
}
请告诉我当前设置中的问题。
此致
Udhaya
答案 0 :(得分:0)
你需要包含你的包,它是一个包含逗号分隔包的字符串。
beanConfig.setResourcePackage(“io.swagger.resources ,,”);