提问者:小点点

斯威格不工作


我在使用Restlet使Swagger显示API文档时遇到了一些麻烦。Swagger显示的只是这些东西:

检查api文档,它只显示:

我想知道我的代码有什么问题:

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;
    }
}

共3个答案

匿名用户

你可以看看这篇文章:

  • APISpark能为您现有的Web API带来什么(第2部分)-http://restlet.com/blog/2016/01/04/what-can-apispark-bring-to-your-existing-web-apis-part-2/

Swagger1和2都由Restlet的Swagger扩展支持:

>

  • 斯威格v1

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

    斯威格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;
        }
    }
    

  • 匿名用户

    解决方案是添加以下代码:

        // Configuring Swagger 2 support
        Swagger2SpecificationRestlet swagger2SpecificationRestlet
                = new Swagger2SpecificationRestlet(this);
        swagger2SpecificationRestlet.setBasePath("http://localhost:8080/api-docs");
        swagger2SpecificationRestlet.attach(router);
    

    并将SwaggerUI指向/swagger. json

    匿名用户

    Swagger需要找到你的API操作。我不确定Restlet,在泽西岛,你用@Api注释你的REST资源类,用@Api注释你的方法。在swagger文档中阅读更多。