Skip to content
🧩 A library that generates kotlin code for Retrofit 2 based on a Swagger endpoint. Includes an Annotation Processor to configure and generate the code on build time.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
app
config first commit Mar 6, 2019
docs
generator Correct pom generation Mar 6, 2019
gradle/wrapper first commit Mar 6, 2019
media Added logo Mar 6, 2019
scripts first commit Mar 6, 2019
.gitignore
.travis.yml Added secure for bintray Mar 7, 2019
CODE_OF_CONDUCT.md first commit Mar 6, 2019
CONTRIBUTING.md
LICENSE Initial commit Mar 6, 2019
PULL_REQUEST_TEMPLATE.md
README.md Jcenter on readme Mar 7, 2019
build.gradle
gradle.properties first commit Mar 6, 2019
gradlew
gradlew.bat
settings.gradle first commit Mar 6, 2019
version.properties first commit Mar 6, 2019

README.md

A library that generates kotlin code for Retrofit 2 based on a Swagger endpoint; includes an Annotation Processor to generate and export the code



Features | Download | Who Made This | Contribute | Bugs and Feedback | License


Features

  • Easy interface
  • Model and DataSource auto-generated
  • Swagger v2 integration: create Data Sources based on swagger documentation

Download

Include the jcenter repository in your top build.gradle:

Enabled by default on AndroidStudio projects

allprojects {
    jcenter()
}

It requires kapt in order to make it run. You need to add this line on the build.gradle of the module where you want use it.

apply plugin: "kotlin-kapt"
kapt "com.schibsted.spain:retroswagger:1.0.0"
annotationProcessor "com.schibsted.spain:retroswagger:1.0.0"
implementation "com.schibsted.spain:retroswagger:1.0.0"

In order for your project recognizes the generated code you will need to include it into your sources path, like this:

android {
  ...

  sourceSets {
    main.java.srcDirs += "${buildDir.absolutePath}/tmp/kapt3/incrementalData/debug/path/to/your/generated/code"
  }

  ...
}

How to use it

You can use your own file creator or use the annotation comes with the library that generates the files for you. On the class you want to include the generated code you need to add this annotation "@Retroswagger()".

@Retroswagger(
    "Swagger URL",
    "Name of the api interface you want to have",
    "Cache policy in Days",
    "Remove trailing slash on the interface methods")
class MyClass() {
}

Trailing slash example:

  • option to "true": @GET("pet/findByStatus")
  • option to "false": @GET("/pet/findByStatus")

Example:

@Retroswagger("http://petstore.swagger.io/v2/swagger.json", "PetStore", 1, true)
class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

You need to take into account that this will generate all the files on the same package you include this annotation. For example, if you include it on the class "MyActivity" that is on the package "com.company.mymodule.myfeature.views" it will assign the package for all the generated files to this package.

Android

If you are using it on an Android project and you use Proguard, you will need to add this proguard rules:

-dontwarn org.yaml.snakeyaml.**
-dontwarn org.slf4j.**
-dontwarn io.swagger.**
-dontwarn com.google.common.**
-dontwarn com.google.auto.**
-dontwarn javax.xml.datatype.**
-dontwarn com.fasterxml.jackson.**
-dontwarn com.squareup.kotlinpoet.**
-dontwarn com.schibsted.spain.**

Beware, if you are using one of these package maybe one or more of these rule will not be needed. Also, it's possible that you will need to add more rules.

If you are using using a test framework it will be needed to add a explicit dependency in order to use it on your tests

androidTestAnnotationProcessor "com.schibsted.spain:retroswagger:1.0.0"

Who made this

Ferran Pons
Ferran Pons

Contribute

  1. Create an issue to discuss about your idea
  2. [Fork it] (https://github.com/SchibstedSpain/retroswagger/fork)
  3. Create your feature branch (git checkout -b my-new-feature)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request
  7. Profit!

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

License

Copyright 2019 Schibsted Classified Media Spain S.L.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

You can’t perform that action at this time.