1. Introduction
The Springfox suite of java libraries are all about automating the generation of machine and human readable specifications for JSON APIs written using the spring family of projects. Springfox works by examining an application, once, at runtime to infer API semantics based on spring configurations, class structure and various compile time java Annotations.
1.1. History
Springfox has evolved from a project originally created by Marty Pitt and was named swagger-springmvc. Much kudos goes to Marty.
1.2. Goals
- To extend support for a number of the evolving standards targeted at JSON API specification and documentation such as:swagger, RAML and jsonapi.
- To extend support for spring technologies other thanspring webmvc
- Philosophically, we want to discourage using (swagger-core) annotations that are not material to the service description at runtime. For e.g. the jackson annotations should always trump or have more weight than
@ApiModelProperty
or for e.g. @NotNull
or specifying @RequestParam#required should always win. Annotations are to to be used only to supplement documentation or override/tweak the resulting spec in cases where its not possible to infer service/schema characteristics.
1.3. What it’s not
Endorsed or approved by the Spring Framework Contributors
1.4. Development Environment
- File >> open >> build.gradle
- Make sure to check the 'use the default gradle wrapper' option.
- First time build
./gradlew cleanIdea idea
- To get more output from any gradle commands/tasks append a
-i
(info) or -d
(debug) e.g.
./gradlew build -i
- To publish to local maven repository
./gradlew clean build publishToMavenLocal -i
| This build is optimized for releasing software to bintray/sonatype. In order for gradle to figure out the version the gradle plugin relies on local folder being a cloned git repository. Downloading the source archive and building will NOT work! |
1.4.1. Pre-Commit Build
- Code quality (code coverage, checkstyle)
./gradlew check
1.4.2. Building reference documentation
To view the docs in a browser run:
./gradlew docs
When frequently generating the docs use the Gradle daemon as follows
./gradlew asciidoc --daemon
1.4.3. CI Environment
Circle CI
1.5. Releasing
To release a non-snapshot version of Springfox:
- Execute the the release commands: The below properties are required to run a release:
-
GITHUB_TOKEN
-
BINTRAY_USERNAME
-
BINTRAY_PASSWORD
Recommend using [autoenv](https://github.com/kennethreitz/autoenv) with a .env
file at the root of the repo.
./gradlew release publishDocs -PbintrayUsername=$BINTRAY_USERNAME -PbintrayPassword=$BINTRAY_PASSWORD
-PreleaseType=<MAJOR|MINOR|PATCH> -i
The release steps are as follows: - check that the git workspace is clean - check that the local git branch is master - check that the local git branch is the same as origin - gradle test - gradle check - upload (publish) all artifacts to Bintray - Bumps the project version in version.properties
- Git tag the release - Git push
1.5.1. Snapshot
This is normally done by the CI server
./gradlew snapshot -PbintrayUsername=<bintrayUsername> -PbintrayPassword=<bintrayPassword>
1.5.2. Override deploy
To bypass the standard release flow and upload directly to bintray use the following task - manually set the version in version.properties
./gradlew clean build bintrayUpload -PbintrayUsername=$BINTRAY_USERNAME -PbintrayPassword=$BINTRAY_PASSWORD -PreleaseType=<MAJOR|MINOR|PATCH>
--stacktrace
1.5.3. Updating documentation
To update the docs for an existing release pass the updateMode
switch
./gradlew publishDocs -PupdateMode
1.5.4. Contributing
Please see the wiki for some guidelines
1.6. Support
If you find issues or bugs please submit them via the Springfox Github project
2. Getting Started
2.1. Dependencies
The Springfox libraries are hosted on bintray and jcenter. The artifacts can be viewed accessed at the following locations:
- Release:
- https://jcenter.bintray.com/io/springfox/
- http://jcenter.bintray.com/io/springfox/
- Snapshot
- http://oss.jfrog.org/simple/oss-snapshot-local/io/springfox/
- http://oss.jfrog.org/oss-snapshot-local/io/springfox/
Springfox has multiple modules and the dependencies will vary depending on the desired API specification standard. Below outlines how to include the springfox-swagger2 module which produces Swagger 2.0 API documentation.
2.1.1. Gradle
Release
repositories {
jcenter()
}
dependencies {
compile "io.springfox:springfox-swagger2:2.6.1"
}
Snapshot
repositories {
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
dependencies {
compile "io.springfox:springfox-swagger2:2.6.2-SNAPSHOT"
}
2.1.2. Maven
Release
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
Snapshot
<repositories>
<repository>
<id>jcenter-snapshots</id>
<name>jcenter</name>
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
</repository>
</repositories>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.2-SNAPSHOT</version>
</dependency>
2.1.3. Springfox-swagger2 with Spring MVC and Spring Boot
1 | /* |