【问题标题】:Swagger not working招摇不工作
【发布时间】:2016-02-21 09:10:23
【问题描述】:

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

检查 api-docs 它只显示:

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

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

【问题讨论】:

    标签: java swagger restlet


    【解决方案1】:

    你可以看看这篇文章:

    Restlet 的 Swagger 扩展支持 Swagger1 和 2:

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

    【讨论】:

      【解决方案2】:

      解决方法是添加这段代码:

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

      并将 Swagger UI 指向 /swagger.json

      【讨论】:

        【解决方案3】:

        Swagger 需要找到您的 API 操作。我不确定Restlet,在泽西岛,你用@Api注释你的REST资源类,用@ApiOperation注释你的方法。在此处阅读更多信息in the swagger docs

        【讨论】:

        • 您也可以使用/api-docs/resource浏览到相应的资源
        • 这对您有帮助吗?那么请将答案标记为正确。
        猜你喜欢
        • 2018-09-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多