All Projects β†’ Yelp β†’ Swagger Gradle Codegen

Yelp / Swagger Gradle Codegen

Licence: apache-2.0
πŸ’« A Gradle Plugin to generate your networking code from Swagger

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Swagger Gradle Codegen

gradle-libraries-plugin
No description or website provided.
Stars: ✭ 29 (-91.21%)
Mutual labels:  gradle, gradle-plugin
change-tracker-plugin
A Gradle plugin to help analyse the dependency between modules and run tasks only on modules impacted by specific set of changes.
Stars: ✭ 103 (-68.79%)
Mutual labels:  gradle, gradle-plugin
plugin-yml
A Gradle plugin that generates plugin.yml for Bukkit/BungeeCord/Nukkit plugins based on the Gradle project
Stars: ✭ 42 (-87.27%)
Mutual labels:  gradle, gradle-plugin
SetupBuilder
Gradle plugin for building setups for different platforms.
Stars: ✭ 75 (-77.27%)
Mutual labels:  gradle, gradle-plugin
Protein
πŸ’Š Protein is an IntelliJ Plugin to generate Kotlin code for Retrofit 2 and RxJava 2 based on a Swagger definition
Stars: ✭ 273 (-17.27%)
Mutual labels:  swagger, retrofit2
sonatype-publish-plugin
Gradle Plugin for publishing artifacts to Sonatype and Nexus
Stars: ✭ 17 (-94.85%)
Mutual labels:  gradle, gradle-plugin
gradle-console-reporter
Gradle plugin to report various kinds of summaries to console.
Stars: ✭ 49 (-85.15%)
Mutual labels:  gradle, gradle-plugin
gradle-localization-plugin
Gradle plugin for automating the download process of localization files.
Stars: ✭ 19 (-94.24%)
Mutual labels:  gradle, gradle-plugin
Gradle Aws Plugin
Gradle plugin to manage Amazon Web Services
Stars: ✭ 269 (-18.48%)
Mutual labels:  gradle, gradle-plugin
Openapi.tools
A collection of Editors, Linters, Parsers, Code Generators, Documentation, Testing
Stars: ✭ 257 (-22.12%)
Mutual labels:  swagger, swagger2
gradle-helm-plugin
A Gradle plugin for building, publishing and managing Helm charts.
Stars: ✭ 42 (-87.27%)
Mutual labels:  gradle, gradle-plugin
Gradle Code Quality Tools Plugin
Gradle plugin that generates ErrorProne, Findbugs, Checkstyle, PMD, CPD, Lint, Detekt & Ktlint Tasks for every subproject.
Stars: ✭ 282 (-14.55%)
Mutual labels:  gradle, gradle-plugin
gatling-gradle-plugin-demo
Showcase of the Gatling Plugin for Gradle
Stars: ✭ 17 (-94.85%)
Mutual labels:  gradle, gradle-plugin
RocketXPlugin
πŸ”₯πŸ”₯ android η«―ηΌ–θ―‘εŠ ι€Ÿζ’δ»ΆπŸš€ θ‡ͺεŠ¨θ―†εˆ«ζœͺζ”ΉεŠ¨ module εΉΆεœ¨ηΌ–θ―‘ζ΅η¨‹δΈ­ζ›Ώζ’δΈΊ aar ,εͺηΌ–θ―‘ζ”ΉεŠ¨ζ¨‘ε—οΌŒεŠ ι€Ÿ Android apk ηš„ηΌ–θ―‘ι€ŸεΊ¦γ€‚
Stars: ✭ 408 (+23.64%)
Mutual labels:  gradle, gradle-plugin
gradle-build-info-plugin
Gradle plugin to include build information such as Git commit ID to your JAR. It can be used to show Git commit information with Spring Boot Actuator.
Stars: ✭ 33 (-90%)
Mutual labels:  gradle, gradle-plugin
jooq-plugin
Plugin for generating jOOQ classes using dockerized databases
Stars: ✭ 55 (-83.33%)
Mutual labels:  gradle, gradle-plugin
gradle-cleaner-intellij-plugin
Force clear delaying & no longer needed Gradle tasks.
Stars: ✭ 26 (-92.12%)
Mutual labels:  gradle, gradle-plugin
sphinx-gradle-plugin
Sphinx site generation plugin for Gradle
Stars: ✭ 19 (-94.24%)
Mutual labels:  gradle, gradle-plugin
schema-registry-plugin
Gradle plugin to interact with Confluent Schema-Registry.
Stars: ✭ 60 (-81.82%)
Mutual labels:  gradle, gradle-plugin
Gradle Unused Resources Remover Plugin
Gradle Plugin that removes unused resources in Android projects.
Stars: ✭ 282 (-14.55%)
Mutual labels:  gradle, gradle-plugin

Swagger Gradle Codegen

Plugin Portal Pre Merge Checks License Join the chat at https://kotlinlang.slack.com Twitter

A Gradle plugin to generate networking code from a Swagger spec file.

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).

If you're using the Groovy Gradle files:

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "com.yelp.codegen:plugin:<latest_version>"
    }
}

apply plugin: "com.yelp.codegen.plugin"

generateSwagger {
    platform = "kotlin"
    packageName = "com.yelp.codegen.samples"
    inputFile = file("./sample_specs.json")
    outputDir = file("./src/main/java/")
}

If you're using the Kotlin Gradle files:

plugins {
    id("com.yelp.codegen.plugin") version "<latest_version>"
}

generateSwagger {
    platform.set("kotlin")
    packageName.set("com.yelp.codegen.samples")
    inputFile.set(file("./sample_specs.json"))
    outputDir.set(project.layout.buildDirectory.dir("./src/main/java/"))
}

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.

Requirements

In order to run this gradle plugin you need to fulfill the following requirements:

  • Gradle 5.x - This plugin uses Gradle 5 features, and you will need to setup your Gradle wrapper to use 5.4.1 or more.
  • Java 8+

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 and Moshi for serialization
kotlin-coroutines Generates Kotlin code and Retrofit interfaces, with Kotlin Coroutines for async calls and Moshi for serialization

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.

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

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

  • samples/kotlin-coroutines Contains an example of an Android Library configured to output Kotlin Coroutines capable code.

  • samples/junit-tests This sample contains specs used to test edge cases and scenarios that have been reported in the issue tracker or that are worth testing. Tests are executed using moshi-codegen. It does also contains all the generated code inside the /scr/main/java folder. You can use this example to see how the generated code will look like (like here).

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.

generateSwagger {
    platform.set("kotlin")
    packageName.set("com.yelp.codegen.integrations")
    specName.set("integration")
    specVersion.set("1.0.0")
    inputFile.set(file("../sample_specs.json"))
    outputDir.set(project.layout.buildDirectory.dir("./src/main/java/"))
    features {
        headersToRemove.add("Accept-Language")
    }
}

And here a table with all the properties and their default values:

Property Description Default
inputFile Defines the path to the Swagger spec file REQUIRED
platform Defines the platform/templates that will be used. See Supported platforms for a list of them. "kotlin"
packageName Defines the fully qualified package name that will be used as root when generating the code. "com.codegen.default"
specName Defines the name of the service that is going to be built. "defaultname"
specVersion Defines the version of the spec that is going to be used. If not provided, the version will be read from the specfile. If version is missing will default to "0.0.0"
outputDir Defines the output root folder for the generated files. $buildDir/gen
extraFiles Defines a folder with extra files that will be copied over after the generation (e.g. util classes or overrides). not set by default

Please note that all those properties can be configured with command line flags that mirrors 1:1 the property name. E.g.:

./gradlew generateSwagger --inputFile=./sample/specs.json

Extra Features

You can use the features { } block to specify customization or enabled/disable specific features for your generator.

Here a list of all the supported features:

Feature Description Command line
headersToRemove List of headers that needs to be ignored for every endpoints. The headers in this list will be dropped and not generated as parameters for the endpoints. -ignoreheaders=

Building

To contribute or to start developing the Swagger Codegen Plugin, you need to set up your environment.

Make sure you have:

  • Python (needed for pre-commit hook)
  • Java/Kotlin (needed for compiling the plugin code)

We also recommend you set up:

  • aactivator To correctly manage your venv connected to this project
  • IntelliJ IDEA Either the Community or the Ultimate edition are great to contribute to the plugin.

Before starting developing, please run:

./gradlew installHooks

This will take care of installing the pre-commit hooks to keep a consistent style in the codebase.

While developing, you can build, run pre-commits, checks & tests on the plugin using:

./gradlew preMerge

Make sure your tests are all green βœ… locally before submitting PRs.

NOTE: If you don't have the Android SDK you can skip the Android related tasks by setting SKIP_ANDROID enviromental variable (tests will be run on the CI anyway).

Contributing/Support

Support for this project is offered in the #swagger-gradle-codegen channel on the Kotlinlang slack (request an invite here).

We're looking for contributors! Feel free to open issues/pull requests to help me improve this project.

If you found a new issue related to incompatible Swagger specs, please attach also the spec file to help investigate the issue.

License πŸ“„

This project is licensed under the Apache 2.0 License - see the License file for details

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].