Swagger without Spring problem with setup

853 views
Skip to first unread message

mariuszcrust

unread,
Apr 7, 2015, 9:10:30 AM4/7/15
to swagger-sw...@googlegroups.com
Hi,
I struggle to setup swagger (version 1.3.12) into project with CXF (version 2.7.10) without spring (we are usings javax.inject ). Everything seems to be ok, json is visible under defined uri, but it doesnt contain any of documented api. I've annotated class, methods, responses, exceptions and still json contained only uri and version. It looks like swagger could not find my packages to scan.

I've tested almost everyting solution/tutorial which I cound find ...

So the question is it possible to setup swagger in such configuration ? I will try to include my settings in web.xml asap

Ron Ratovsky

unread,
Apr 7, 2015, 9:13:31 AM4/7/15
to swagger-sw...@googlegroups.com
The web.xml may be the key here. Basically, you need to tell swagger-core which packages to scan, otherwise it will not find anything.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
-----------------------------------------
http://swagger.io
https://twitter.com/SwaggerApi
-----------------------------------------

mariuszcrust

unread,
Apr 7, 2015, 9:22:59 AM4/7/15
to swagger-sw...@googlegroups.com
Is it possible to scan external jars ? My web project using REST facade from included jars

my web.xml
<servlet>
    <servlet-name>resteasy</servlet-name>
    <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>com.wordnik.swagger.sample.SwaggerApplication</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>resteasy</servlet-name>
    <url-pattern>/api/*</url-pattern>
  </servlet-mapping>

  <servlet>
    <servlet-name>DefaultJaxrsConfig</servlet-name>
    <servlet-class>com.wordnik.swagger.sample.SwaggerJaxrsConfig</servlet-class>
    <init-param>
      <param-name>api.version</param-name>
      <param-value>1.0.0</param-value>
    </init-param>
    <init-param>
      <param-name>swagger.api.basepath</param-name>
      <param-value>http://localhost:8081/api</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <filter>
    <filter-name>ApiOriginFilter</filter-name>
    <filter-class>com.wordnik.swagger.sample.util.ApiOriginFilter</filter-class>
  </filter>
  <servlet>
    <servlet-name>Bootstrap</servlet-name>
    <servlet-class>com.wordnik.swagger.sample.Bootstrap</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <filter-mapping>
    <filter-name>ApiOriginFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


public class Bootstrap extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    public void init(ServletConfig servletConfig) {

        ConfigFactory.config().setBasePath("http://localhost:8081/administration/api");
        ConfigFactory.config().setApiPath("http://localhost:8081/administration/api");
        ConfigFactory.config().setApiVersion("666.666.666");
        ConfigFactory.config().setSwaggerVersion(com.wordnik.swagger.core.SwaggerSpec.version());
    }


public class ApiOriginFilter implements javax.servlet.Filter {
  @Override
  public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {
    HttpServletResponse res = (HttpServletResponse) response;
    res.addHeader("Access-Control-Allow-Origin", "*");
    res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
    res.addHeader("Access-Control-Allow-Headers", "Content-Type, api_key, Authorization");
    chain.doFilter(request, response);
  }

  @Override
  public void destroy() {
  }

  @Override
  public void init(FilterConfig filterConfig) throws ServletException {
  }
}

public class SwaggerJaxrsConfig extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    public void init(ServletConfig servletConfig) {
        try {
            super.init(servletConfig);
            SwaggerConfig swaggerConfig = new SwaggerConfig();
            ConfigFactory.setConfig(swaggerConfig);
            swaggerConfig.setBasePath("http://localhost:8081/api"); //TODO look up app path
            ScannerFactory.setScanner(new DefaultJaxrsScanner());
            ClassReaders.setReader(new DefaultJaxrsApiReader());
        } catch (Exception e) {

        }
    }
}

Ron Ratovsky

unread,
Apr 7, 2015, 9:34:58 AM4/7/15
to swagger-sw...@googlegroups.com
It looks like you're setting it up in multiple ways (which are conflicting) and you never tell it which packages to scan. I'm not really sure how you ended up with such a set up though I assume it's basically a trial and error.
You'd want to clean that up and make sure you configure the packages. I'd start with the BeanConfig as the basic configuration option and move up in complexity if that doesn't work.
While the wiki pages don't talk about CXF/Non-Spring+BeanConfig, you can still follow a similar logic as it would in Jersey's documentation (for BeanConfig usage).

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages