0

I'm new to developing rest web services and now, I'm trying to add authenication via this url: http://developers-blog.helloreverb.com/enabling-oauth-with-swagger/

Unfortunately, I'm stuck on the first step, when it says to edit the resource listing, which I believe is the api-docs, right? So, how am I supposed to edit that if its generated by the service and not stored as a file anywhere?

My Swagger version is 1.2

Don Kane
  • 3
  • 3

2 Answers2

1

The link you provided refers to Swagger 1.2 but the latest version is Swagger 2.0

As a starting point, you may consider using editor.swagger.io and reviewing the petstore example, which contains authentication-related setting

William Cheng
  • 10,137
  • 5
  • 54
  • 79
  • My swagger version is 1.2 – Don Kane Jul 24 '15 at 02:25
  • If using Swagger Spec 1.2 is a must, then please refer to the [Authorization Objects](https://github.com/swagger-api/swagger-spec/blob/master/versions/1.2.md#514-authorizations-object) section of the specification. – William Cheng Jul 24 '15 at 06:12
0

Take a look at the pet store sample from the 1.3.12 tag which was the last version producing Swagger 1.2 - https://github.com/swagger-api/swagger-core/tree/v1.3.12/samples/java-jaxrs.

Specifically, you need to add the definitions to something like your Bootstrap class:

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);
  }
}
Ron
  • 14,160
  • 3
  • 52
  • 39