Swagger编辑api-docs?

时间:2015-07-24 00:51:45

标签: web-services rest swagger swagger-ui api-doc

我是开发其他网络服务的新手,现在,我尝试通过此网址添加身份验证: http://developers-blog.helloreverb.com/enabling-oauth-with-swagger/

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

My Swagger版本为1.2

2 个答案:

答案 0 :(得分:1)

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

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

的petstore示例

答案 1 :(得分:0)

查看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);
  }
}