I would like to import API definition files created with the swagger gradle plugin. I have a spring boot mvc app. I don't seem to be able to get the resolve settings correct to generate the openAPI.json. The gradle resolve task creates an empty file with just the "openapi" : "3.0.1" tag and value. The resolve task is not picking up the swagger and mvc api annotations. Can you point me in the right direction to find the right configuration settings for the swagger gradle resolve task?
The application displays the Spring-UI documentation without a problem when the app is running and I view the swagger-ui endpoint. The issue is during the gradle build there is a separate gradle task to generate the openAPI.json file that I would like to import into SwaggerHub as part of the application API catalog.
I have been unable to find any documentation anywhere on how to configure the swagger gradle plugin resolve task to pick up the Spring MVC API annotations. I can get it to work fine on another application that uses the jax-rs annotations so I am certain that it is a resolve task configuration issue.
A copy of my gradle.build file:
buildscript {
ext {
springBootVersion = '1.4.1.RELEASE'
}
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("io.spring.gradle:dependency-management-plugin:0.5.6.RELEASE")
// SwaggerHub Plugin Dependency
classpath("gradle.plugin.io.swagger:swaggerhub:1.0.1")
// Swagger Gradle Plugin Dependency
classpath("io.swagger.core.v3:swagger-gradle-plugin:2.0.5")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'jacoco'
// Required to upload swagger api doc to swaggerhub
apply plugin: 'io.swagger.swaggerhub'
// Required to generate swagger api doc file to upload to swaggerhub
apply plugin: 'io.swagger.core.v3.swagger-gradle-plugin'
jar {
baseName = 'service-framework'
version = '0.0.1-SNAPSHOT'
}
javadoc {
source = sourceSets.main.allJava
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-aop')
compile('org.springframework.boot:spring-boot-starter-jersey')
compile('org.springframework.boot:spring-boot-starter-web')
// Swagger Dependencies to generate the api documentation
compile('io.swagger:swagger-annotations:1.5.20')
compile('io.springfox:springfox-swagger2:2.8.0')
compile('io.springfox:springfox-swagger-ui:2.8.0')
runtime('com.h2database:h2')
runtime('org.postgresql:postgresql')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
testCompile group: 'junit', name: 'junit-dep', version: '4.10'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
}
// Command to the swagger gradle plugin to generate the api file for upload
// to swaggerhub
//
//
// Create the directory for output of the api document
File path = new File("${buildDir}/doc")
//
// The Swagger Core Task to create the json output file required to upload
// to SwaggerHub
//
resolve {
outputFileName = 'openAPI'
outputFormat = 'JSON'
prettyPrint = 'TRUE'
classpath = sourceSets.main.runtimeClasspath
resourcePackages = ['test.serviceframework']
outputPath = path.getAbsolutePath();
}
The resulting output in the openAPI.json file:
{
"openapi" : "3.0.1"
}