Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm developing a Play application in Scala as a hobby project. I'm using Gradle as a building tool.

I want to generate API documentation using swagger. My goal is to generate swagger.json file containing my REST API documentation in JSON format with Gradle task during build of the project.

To generate the swagger file I'm using swagger-gradle-plugin. I have annotated controllers and methods in the controllers with proper annotations from swagger.io.swagger_play library.

Unfortunately, play annotations are not recognized by the plugin. File swagger.json generated using Gradle resolve task only picks up JAX-RS annotations I put in the controllers when trying to make plugin work.

For example, when I annotated a controller with

@Api(value="testController", tags = Array("Test controller")

annotation, the resolve task produced empty swagger.json file.

When I annotated the controller with JAX-RS annotation

@Path("/")

and then added JAX-RS annotations to the method inside the controller

@GET
@Path("testEndPoint1")

resolve task generated documentation for /testEndPoints1. But annotations from swagger.io.swagger_play are still ignored so there is not much information in the generated documentation.

I saw there are some plugins for sbt, but I want to make it work using Gradle.

Is there any way I can generate swagger REST API documentation in Play application while using Gradle building tool?

Versions of the tools in the project:

  • Play 2.8
  • Gradle 6.5.1
  • Scala 2.12
  • io.swagger.core.v3.swagger-gradle-plugin 2.1.6
  • io.swagger:swagger.play_2.12:1.7.1

EDIT:

Gradle configuration of the plugin:

resolve {
outputFileName = "swagger"
outputDir = "build/swagger_doc"
classpath = sourceSets.main.runtimeClasspath
readAllResources = true
openApiFile = file("openapi_config.yaml")
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
426 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...