Giter VIP home page Giter VIP logo

swagger-codegen-gradle-plugin's Introduction

swagger-codegen-gradle-plugin

Build Status

A Gradle plugin to support the swagger code generation project

[DEPRECATED] !!!

see the swagger-codegen-gradle-plugin-example for creating a Gradle task to generate code with Swagger Codegen.

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.7.4'
    id 'java'
}

apply plugin: 'org.detoeuf.swagger-codegen'

repositories {
    mavenCentral()
    jcenter()
}

swagger {
    inputSpec = 'http://petstore.swagger.io/v2/swagger.json'
    outputDir = file('build/swagger')
    lang = 'java'

    additionalProperties = [
            'invokerPackage'   : 'io.swagger.petstore.client',
            'modelPackage'     : 'io.swagger.petstore.client.model',
            'apiPackage'       : 'io.swagger.petstore.client.api',
            'dateLibrary'      : 'java8'
    ]
    importMappings = [
            'Dog': 'io.swagger.petstore.client.model.Dog'
    ]
}

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

classes.dependsOn('swagger')

ext {
    spring_boot_version = '1.5.6.RELEASE'
    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:$spring_boot_version"
    swaggerCompile 'io.swagger:swagger-annotations:1.5.16'
    swaggerCompile 'com.squareup.okhttp:okhttp:2.7.5'
    swaggerCompile 'com.squareup.okhttp:logging-interceptor:2.7.5'
    swaggerCompile 'com.google.code.gson:gson:2.8.1'

    compile sourceSets.swagger.output

    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"
    compile 'io.swagger:swagger-codegen:2.2.3'

    testCompile "junit:junit:$junit_version"

    runtime 'com.squareup.okhttp:okhttp:2.7.5'
    runtime 'com.squareup.okhttp:logging-interceptor:2.7.5'
    runtime 'com.google.code.gson:gson:2.8.1'
}

Launch with:

gradle swagger

Configuration parameters

the swagger {} configuration is passed to CodegenConfigurator.java

Dynamic properties

Some Swagger codegen configurations will contain extra properties that are not part of the io.swagger.codegen.CodegenConfig interface. For example there is the sourceFolder property that is only applicable if using jaxrs-spec as the value of the lang property. In order to set such properties, we should use the dynamicProperty method inside the swagger {} configuration as shown below.

swagger {
    lang = 'jaxrs-spec'

    addDynamicProperty 'sourceFolder', 'src/swagger/java'

    additionalProperties = [
        ...
    ]
    systemProperties = [
        ...
    ]
}

… 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, configured by configuring the task directly:
    tasks.getByName("swagger") {
        cleanOutputDir = false
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.