Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

scala - Swagger API documentation in Play application with Gradle

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")
}
question from:https://stackoverflow.com/questions/65682063/swagger-api-documentation-in-play-application-with-gradle

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...