Forum Discussion

d12548's avatar
d12548
New Member
2 years ago

Create Swagger Spec Json From Spring Projects Automatically using a Terminal / Shell Based Tool

Problem 

 

We have a bunch of existing REST Services written in Java in a framework written on top of Springboot.

 

In CI/CD Pipeline, we want to check if the Spec in Swagger Hub for a given Service matches with current HEAD of the branch.

 

One way to do this is to get the current API Specs in Swagger (which we can easily do using Swagger APIs), auto generate Swagger Spec Json from current Project Repo and compare two.

 

For second part, what we really need is a tool that can auto-scan the current Project for (Spring) API Annotations, generate Swagger Spec in Json format, and dump it to some file. i.e.

 

./gradlew autoGenerateSwaggerSpec > spec.txt

 

Our Projects are using Gradle, so anything based on Maven would not work for us.

 

Note that this question comes because we prefer not to involve Swagger UI (hosted in an Embedded Server), because CI / Build Tools might not allow embedded Servers to run in Build Pipelines.

 

If we were fine with Swagger UI, we can just as easily curl the Spec.

 

What I have tried 

 

  1. Springfox says that it is "all about automating the generation of machine and human readable specifications for JSON APIs written using the spring family of projects. " I have tried their Demo Project, but its not clear of it can auto-generate Swagger Spec on Terminal / shell. It enables Swagger UI for current Project in an embedded Server on Localhost from where we can download Swagger Spec, but that is not CI friendly.
  2. SpringDoc seems to have a support for a Gradle Plugin, but this plugin seems to only curl the API Spec. It seems to require / assume that the Swagger UI is already up and running.

 

Just wanted to check if someone knows a solution for this.

No RepliesBe the first to reply