Search code examples
javaswaggerrestlet

Swagger not working


I'm having a bit of trouble making Swagger display API docs using Restlet. What Swagger shows is just these stuff:

enter image description here

And checking the api-docs it only shows this:

enter image description here

I wonder what is wrong with my code:

public class MyApplication extends SwaggerApplication {
    private static final String ROOT_URI = "/";
    public Restlet createInboundRoot() {
        Router router = new Router(getContext());
        router.attach(ROOT_URI, RootServerResource.class);
        router.attach(ROOT_URI + "ping", PingServerResource.class);
        router.attach(ROOT_URI + "ping/", PingServerResource.class);
        // Some code omitted for simplicity
        return router;
    }
}

Solution

  • You could have a look at this article:

    Both Swagger1 and 2 are supported by the Swagger extension of Restlet:

    • Swagger v1

      public class ContactsApplication extends SwaggerApplication {
          public Restlet createInboundRoot() {
              Router router = new Router();
              (...)
              attachSwaggerSpecificationRestlet(router, "/docs");
      
              return router;
          }
      }
      
    • Swagger v2

      public class ContactsApplication extends Application {
         public Restlet createInboundRoot() {
              Router router = new Router();
              (...)
              Swagger2SpecificationRestlet swagger2SpecificationRestlet
                                     = new Swagger2SpecificationRestlet(this);
              swagger2SpecificationRestlet.setBasePath("http://myapp.org/");
              swagger2SpecificationRestlet.attach(router, "/docs");
              return router;
          }
      }