A Gradle plugin to support the swagger code generation project
Groovy
#30 Compare This branch is 59 commits ahead of garethjevans:master.
Latest commit c6ae830 Dec 21, 2016 @thebignet committed on GitHub Feature/eliminate swagger plugin extension in favour of codegen confi…
…gurator passed to gradle (#28)

* simply eleminate the SwaggerPluginExtension in favour of the Swagger CodegenConfigurator

* add some documentation about how drastic this has been changed

README.md

swagger-codegen-gradle-plugin

Build Status

A Gradle plugin to support the swagger code generation project

Usage

see the swagger-codegen-gradle-plugin-example, or:

Here is an example of how to use the plugin in a build.gradle file

plugins {
    id 'org.detoeuf.swagger-codegen' version '1.6.3'
    id 'java'
}

repositories {
    jcenter()
}

swagger {
    inputSpec = 'http://petstore.swagger.io/v2/swagger.json'

    outputDir = 'build/swagger'
    lang = 'spring-mvc'

    additionalProperties = [
            'invokerPackage'   : 'io.swagger.petstore.client.jersey1',
            'modelPackage'     : 'io.swagger.petstore.client.jersey1.model',
            'apiPackage'       : 'io.swagger.petstore.client.jersey1.api',
            'dateLibrary'      : 'java8'
    ]
    systemProperties = [
        'apis' : '',
        'models' = ''
    ]
}

sourceSets {
    swagger {
        java {
            srcDir file("${project.buildDir.path}/swagger/src/main/java")
        }
    }
}

ext {
    jackson_version = '2.4.2'
    jersey_version = '1.18'
    jodatime_version = '2.3'
    junit_version = '4.8.1'
}

dependencies {
    swaggerCompile 'org.springframework.boot:spring-boot-starter-web'

    compile "com.sun.jersey:jersey-client:$jersey_version"
    compile "com.sun.jersey.contribs:jersey-multipart:$jersey_version"
    compile "com.fasterxml.jackson.core:jackson-core:$jackson_version"
    compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
    compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:2.1.5"
    compile "joda-time:joda-time:$jodatime_version"

    testCompile "junit:junit:$junit_version"
}

Launch with:

gradle swagger

Configuration parameters

the swagger {} configuration is passed to CodegenConfigurator.java

… to be documented …

deprecation warning

the old behaviour had a custom plugin for this swagger config as seen below

  • inputSpec - :check:
  • outputDir - was: output
  • lang - was: language
  • additionalProperties - sets additional properties that can be referenced by the mustache templates in the format of name=value,name=value. See Customizing the generator for list of parameters

new settings possible

no longer included

  • models - have a look at the systemProperties section
  • apis - selective generation of apis. Leave blank to generate apis only
  • supportingFiles - selective generation of supporting files. Leave blank to generate supporting files only

no substituion for:

  • cleanOutputDir - now, build / output dir is cleaned before every build, you can't any longer disable this