This plugin wraps swagger-codegen, and exposes a configurable generateSwagger gradle task that you can plug inside your gradle build/workflows.

Getting Started

Swagger Gradle Codegen is distributed through Gradle Plugin Portal. To use it you need to add the following dependency to your gradle files. Please note that those code needs to be added the gradle file of the module where you want to generate the code (not the top level build.gradle[.kts] file).

Please note that the generateSwagger { } block is needed in order to let the plugin work.

Once you setup the plugin correctly, you can call the :generateSwagger gradle task, that will run the code generation with the configuration you provided.

Supported platforms

The Swagger Gradle Codegen is designed to support multiple platforms. For every platform, we provide templates that are tested and generates opinionated code.

Here the list of the supported platforms:

Platform

Description

kotlin

Generates Kotlin code and Retrofit interfaces, with RxJava2 for async calls, Moshi for serialization and ThreeTenABP for Data management

We're looking forward to more platforms to support in the future. Contributions are more than welcome.

Examples

You can find some examples in this repository to help you set up your generator environment.

sample-generated-code Contains an example of an Android Library where the code is generated inside the /scr/main/java folder. You can use this example to see how the generated code will look like (like here)

sample-groovy-android Contains an example of an Android Library configured with a build.gradle file, using the classical Gradle/Groovy as scripting language.

sample-kotlin-android Contains an example of an Android Library configured with a build.gradle.kts file, using Kotlin as scripting language.

How the generated code will look like

Here you can find some examples of how the generated code will look like in your project.

Configuration

To configure the generator, please use the generateSwagger { } block. Here an example of this block with all the properties.