I am trying to use the Swagger Core JAX-RS 2.0 project to generate documentation for my existing webservices. My project is set up so the webservices are in one project and the servlets that use the webservices are in another project.
I added the dependency for swagger-jaxrs2 to both projects and added the following to the web.xml in the servlet project:
<servlet>
<!-- use OpenApi servlet to serve spec -->
<servlet-name>OpenApi</servlet-name>
<servlet-class>io.swagger.jaxrs2.integration.OpenApiServlet</servlet-class>
<init-param>
<param-name>openApi.configuration.resourcePackages</param-name>
<param-value>myorg.webservices.resources,myorg.webservices.resources.subpackage1,myorg.webservices.resources.subpackage2</param-value>
</init-param>
<!-- alternatively specify configuration file location <init-param> <param-name>openApi.configuration.location</param-name>
<param-value>/openapi-configuration.json</param-value> </init-param> -->
<!-- alternatively include a file openapi-configuration.json or openapi-configuration.yaml
in classpath -->
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>OpenApi</servlet-name>
<url-pattern>/openapi/*</url-pattern>
</servlet-mapping>
I can run the servlet project and it works, but when I go to /openapi all I get is:
{"openapi":"3.0.0"}
I expect to instead see that and a bunch of RESTful webservice documentation stubs.
I'm clearly missing something obvious - most of the documentation is for Jersey; my project does not use Jersey or really any framework. Is there a magic annotation, or am I referring to the classes wrong, or ?
While we're on the subject, do I need to explicitly refer to subpackages, or does it recurse into subpackages?
<repository>
<id>sonatype-snapshots</id>
<name>sonatype-snapshots</name>
<url>https://nexus.swaggerhub.com/content/repositories/sonatype-snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
package myorg.resources;
import a.bunch.of.stuff
@GZIP()
@Path("/Tokens")
public class TokenResource extends BaseResource {
@Resource
protected WebServiceContext webServiceContext;
@Override
protected String getClientAppName(){
//impl
}
@Override
protected WebServiceContext getWebServiceContext() {
//impl
}
@Override
public Logger getLogger() {
//impl
}
@Override
protected String getWebServiceType() {
//impl
}
@GET
@Path("/ForgotPassword/{userId}")
@Produces({MediaType.APPLICATION_JSON})
public Response getPassword(@PathParam("userId") String userId, @Context HttpServletRequest request) throws RemoteException {
//impl
}
@POST
@Produces({MediaType.APPLICATION_JSON})
public Response getToken(@FormParam("userid") String userId, @FormParam("password") String password,@Context HttpServletRequest request) throws RemoteException{
//impl
}
}
I really appreciate the help, thank you
That website doesn't go anywhere for me. I do see there is an rc2 available, so I'll try that.
<repository> | |
<id>maven-snapshots</id> | |
<url>http://oss.sonatype.org/content/repositories/snapshots</url> | |
<layout>default</layout> | |
<releases> | |
<enabled>false</enabled> | |
</releases> |
<snapshots> | |
<enabled>true</enabled> | |
</snapshots> | |
</repository> |
I'm not sure how to tell if the resource classes are on the classpath for the swagger webapp. I'm attempting to embed the swagger webapp in our existing webapp.This is what my setup is - a war with servlets, the web.xml, etc. I've added the swagger servlet to web.xml. I've added the swagger jars to the war's lib. I also have the jaxrs webservices I want to document in the war's lib as a jar. The jaxrs webservices jar is on the war's classpath.