Forum Discussion

wally's avatar
New Contributor
5 years ago

Swagger to generate docs from Java API code

I need to automatically generate documentation from Java API code written by someone else using the Jersey framework. The project is built using Gradle. I'm trying to figure out how to use Swagger for this purpose but can't. I found a page ( where it says I need to add some lines to the build.gradle file but I don't know where and also the page is for the Spring API.

How can I use Swagger here?

6 Replies

  • The tutorial you linked is using springfox and as you mention it allows to generate Swagger documentation analyzing Spring based APIs impementation code.


    swagger-core (wiki) provides a similar functionality for JAX-RS based code (e.g your Jersey based API code), supporting recommended OpenAPI 3.0.0 as well as previous Swagger/OpenAPI 2.0 format (in the 1.5 branch , refer to this wiki page)



    • sonya_m's avatar
      SmartBear Alumni (Retired)

      Thank you frantuma!


      Hi wally , does this information help?

      • wally's avatar
        New Contributor

        I'm reading through those documents and trying to understand

    • wally's avatar
      New Contributor

      After going through the articles I'm still not sure how to include Swagger in my project. I understand I need to add the dependency to the Swagger package but I don't know how exactly. I've tried adding these lines to the build.gradle file but can't see any effects:

      plugins {
        id "io.swagger.core.v3.swagger-gradle-plugin" version "2.1.1"
      • frantuma's avatar

        This depends on what you want to achieve. The gradle config you shared ( I believe gotten from swagger-gradle-plugin README ) makes me think you want to build an OpenAPI specification out of JAX-RS based code as a file added to your project during build time. If this is the case you would define a gradle `resolve` task as described in README and execute it in your gradle build. 


        If your goal is instead exposing an OpenAPI specification at runtime at an URI like https://<yourserver>/../openapi.json, you would follow the main wiki (the only difference being declaring the dependencies in your gradle file instead of the maven POM