我已经连续几天撞到这头了,所以希望有人可以帮忙解决这个简单的问题。
我一直在遵循各种指南,让RESTEasy在Java中工作,并将Swagger附加到它以自动生成文档。我现在终于设法让所有事情都能正常运行,但Swagger除了内置的默认内容外,并没有产生任何文档,而且我无法弄清楚我的生活是什么。我失踪了。
我已经将应用程序分成了一个包含两个类的包。
SimpleEndpoint.java
package SwaggerAndRESTEasy;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.PathParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
@Api(value="My First RESTEASY Endpoint")
@Path("/simpleendpoint")
public class SimpleEndpoint
{
@GET
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "Returns a nice little message")
@ApiResponse(code = 200, message = "yay", response = SimpleEndpoint.class)
public String getTest() {
return "Hello REST World!";
}
@GET
@Path("/users/{id}")
@Produces("application/json")
@ApiOperation(value = "Returns a nice little message")
public String returnID(@PathParam("id") Integer id)
{
return id + "";
}
}
Init.java
package SwaggerAndRESTEasy;
import io.swagger.jaxrs.config.BeanConfig;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
@ApplicationPath("/api")
public class Init extends Application
{
public Init()
{
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.0");
beanConfig.setContact("Mario");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost");
beanConfig.setBasePath("/api");
//beanConfig.setResourcePackage("io.swagger.resources");
beanConfig.setResourcePackage("SimpleEndpoint.class.getPackage().getName()");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
}
@Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> resources = new HashSet();
resources.add(SimpleEndpoint.class);
//Swagger Resources
resources.add(io.swagger.jaxrs.listing.ApiListingResource.class);
resources.add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
return resources;
}
}
Swagger输出
{
"swagger":"2.0",
"info":{
"version":"1.0.0",
"contact":{
"name":"Mario"
}
},
"host":"localhost",
"basePath":"/api",
"schemes":[
"http"
]
}
有人能指出我做错的方向吗?