0
votes

I have maven project with embedded jetty server. I have already created apis using JAX-RS, which are working properly. Now I want to create swagger documentation for my apis.

To start with swagger I have added servlet configuration as describe below :

@WebServlet(name = "SwaggerConfig")
public class SwaggerServlet extends HttpServlet {
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        System.out.println("init SwaggerServlet");
        BeanConfig beanConfig = new BeanConfig();
        beanConfig.setVersion("1.0.0");
        beanConfig.setSchemes(new String[]{"http"});
        beanConfig.setHost("localhost:8082");
        beanConfig.setBasePath("/api");
        beanConfig.setResourcePackage("com.myCompany.myApisResourcePackage");
        beanConfig.setScan(true);
    }
}

Also, in main method, along with my jersey configuration I have added following code :

//swagger
ServletHolder swaggerServletHolder = new ServletHolder(SwaggerServlet.class);
swaggerServletHolder.setInitOrder(1);
swaggerServletHolder.setInitParameter("swagger.api.basepath", "http://localhost:8082");
context.addServlet(swaggerServletHolder, "/api/*");
//swagger end

So, the problem is, I am not able to find where swagger.json will be created.

In this case, swagger scans packages as server log says it, but swagger.json still not getting created.

Note: I am currently not adding swagger-ui as I think it is not mandatory for creating swagger.json

1
You need to configure the JAX-RS (implementation) servlet and register the api resource with the JAX-RS application. The api resource is what serves up the JSON. Look for examples of how to set up Jersey with Jetty and then register the api resource (should be in most swagger getting started guides) with Jersey. - Paul Samsotha

1 Answers

0
votes

I got swagger json by hitting url "localhost:8082/swagger.json". I used same configuration as posted in my question.