Skip to content
Switch branches/tags

SpringFox Grails Integration

Download CircleCI codecov Codacy code quality FOSSA Status

SpringFox Grails integration library that produces grails specific documentation.

Development Environment

IDE setup

IntelliJ IDEA

  • 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 clean build -i
  • To publish to local maven repository

./gradlew clean build publishToMavenLocal -i

Getting Started

The SpringFox Grails integration library depends on Springfox



The Springfox libraries are hosted on bintray and jcenter. The artifacts can be viewed accessed at the following locations:

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.

Refer the main documentation on how to include springfox bundled swagger-ui dependencies
Please refer the main documentation on how to include the springfox-swagger2 dependencies which are required for this integration library to work.


repositories {

dependencies {
    compile "io.springfox.grails:springfox-grails:1.0.0" //(1)


repositories {
   maven { url '' }

dependencies {
    compile "io.springfox.grails:springfox-grails:1.0.1-SNAPSHOT" //(1)


In your Application (GrailsAutoConfiguration) startup entry-point follow the steps below

// 1. Enable SpringFox on your project
// 2. Import the springfox grails integration configuration
class Application extends GrailsAutoConfiguration {
  static void main(String[] args) {, args)

  // 3. **Optionally** define a custom docket or omit this step to use the default
  // For grails it is preferrable to use use the following settings.
  Docket api() {
    new Docket(DocumentationType.SWAGGER_2)

   // 4. **Optionally** in the absense of asset pipeline configure the swagger-ui webjar to serve the scaffolded
   swagger UI
   static WebMvcConfigurerAdapter webConfigurer() {
     new WebMvcConfigurerAdapter() {
       void addResourceHandlers(ResourceHandlerRegistry registry) {
         if (!registry.hasMappingForPattern("/webjars/**")) {
         if (!registry.hasMappingForPattern("/swagger-ui.html")) {

Swagger UI integration

In order to use the bundled swagger UI as explained in step 4 above. The following library needs to be included in the build.gradle
repositories {

dependencies {
    compile "compile "io.springfox:springfox-swagger-ui:2.7.0" //(1)
The latest released version is Springfox Version


The library comes with intelligent defaults imeplemented by DefaultGrailsAlternateTypeRuleConvention. However the defaults can be tweaked using one of these extensibility mechanisms. The following classes can be implemented and registered as a bean to augment default behavior.

  • AlternateTypeRuleConvention - for adding custom conventions for replacing grails types

  • GrailsPropertySelector - for overriding the selection of grails properties by the default convention

  • GrailsPropertyTransformer - for overriding the transformer of the grails property

  • GeneratedClassNamingStrategy - for naming the generated class mixins

Demo application

The demo application is available in this repository. You can see a live demo running or heroku here.


If you get an exception when you try to run your app, this might be because of the chosen profile for your application. If you use the rest-api profile, everything should be fine, but if you’ve chosen the web profile, it is likely that you have to add something like this.

grails.serverURL: http://localhost:8080

to your application.yml for the plugin to render absolute links.


FOSSA Status