首页 文章

Swagger编辑api-docs?

提问于
浏览
0

我'm new to developing rest web services and now, I' m试图通过此网址添加身份验证:http://developers-blog.helloreverb.com/enabling-oauth-with-swagger/

不幸的是,当我说要编辑资源列表时,我就停留在第一步,我相信它是api-docs,对吗?那么,如果由服务生成并且不作为文件存储在任何地方,我应该如何编辑?

我的Swagger版本是1.2

2 回答

  • 0

    您提供的链接指的是Swagger 1.2,但最新版本是Swagger 2.0

    作为起点,您可以考虑使用editor.swagger.io并查看petstore示例,其中包含authentication-related setting

  • 1

    看看1.3.12标签中的宠物商店样本,这是 生产环境 Swagger 1.2的最后一个版本 - https://github.com/swagger-api/swagger-core/tree/v1.3.12/samples/java-jaxrs .

    具体来说,您需要将定义添加到类似Bootstrap类的内容:

    public class Bootstrap extends HttpServlet {
      static {
        // do any additional initialization here, such as set your base path programmatically as such:
        // ConfigFactory.config().setBasePath("http://www.foo.com/");
    
        ApiInfo info = new ApiInfo(
          "Swagger Sample App",                             /* title */
          "This is a sample server Petstore server.  You can find out more about Swagger " + 
          "at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger.  For this sample, " + 
          "you can use the api key \"special-key\" to test the authorization filters", 
          "http://helloreverb.com/terms/",                  /* TOS URL */
          "apiteam@wordnik.com",                            /* Contact */
          "Apache 2.0",                                     /* license */
          "http://www.apache.org/licenses/LICENSE-2.0.html" /* license URL */
        );
    
        List<AuthorizationScope> scopes = new ArrayList<AuthorizationScope>();
        scopes.add(new AuthorizationScope("email", "Access to your email address"));
        scopes.add(new AuthorizationScope("pets", "Access to your pets"));
    
        List<GrantType> grantTypes = new ArrayList<GrantType>();
    
        ImplicitGrant implicitGrant = new ImplicitGrant(
          new LoginEndpoint("http://petstore.swagger.wordnik.com/oauth/dialog"), 
          "access_code");
    
        grantTypes.add(implicitGrant);
    
        AuthorizationType oauth = new OAuthBuilder().scopes(scopes).grantTypes(grantTypes).build();
    
        ConfigFactory.config().addAuthorization(oauth);
        ConfigFactory.config().setApiInfo(info);
      }
    }
    

相关问题