• This repository has been archived on 20/Jul/2023
  • Stars
    star
    274
  • Rank 150,274 (Top 3 %)
  • Language
    Kotlin
  • License
    Apache License 2.0
  • Created about 6 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

💊 Protein is an IntelliJ Plugin to generate Kotlin code for Retrofit 2 and RxJava 2 based on a Swagger definition

* IntelliJ Kotlin code generator for Retrofit2 and RxJava2 based on Swagger *

Version Downloads

Protein is a plugin for intelliJ that automates the build of Retrofit "Interfaces" and "models" for Android in Kotlin. It generates the code for Retrofit based on a Swagger endpoint.


Background | Features | Download | Who Made This | Apps using Protein | Contribute | Bugs and Feedback | License


Background

Protein: A large molecule composed of one or more chains of amino acids in a specific order; the order is determined by the base sequence of nucleotides in the gene coding for the protein. Proteins are required for the structure, function, and regulation of the body’s cells, tissues, and organs, and each protein has unique functions. Examples are hormones, enzymes, and antibodies.

This scientific definition defines quite good the objective of this Plugin in an abstract way. For many time at Adevinta Spain we struggled with the idea of making a good and maintainable architecture for Android. It's been some time until we got one that fits with our needs but we still have a lot of errors and issues that human beings do every time we make manual work. That's were we came to the idea of automatization and make new components with all we need.

Protein is our approach to work better, be more productive and reliable.

NOTE: Protein is based on the library Retroswagger that is the core for the kotlin builder that parses swagger json and generates the kotlin code.

Features

  • Easy interface
  • Interface and Models auto-generated
  • Swagger integration: create code based on swagger documentation
  • IntelliJ and Android Studio compatible

Requirements

To use it you need a Swagger schema endpoint (example: http://petstore.swagger.io/v2/swagger.json).

Example

Swagger json code
{
  "swagger":"2.0",
  "info":{
    "version":"1"
  },
  "host":"localhost:8000",
  "basePath":"/",
  "tags":[
    {
      "name":"favorites-controller",
      "description":"Favorites Controller"
    }
  ],
  "paths":{
    "/favorites":{
      "get":{
        "tags":[
          "favorites-controller"
        ],
        "summary":"Get all favorites for this user",
        "operationId":"getFavorites",
        "consumes":[
          "application/json"
        ],
        "produces":[
          "application/json;charset=UTF-8"
        ],
        "parameters":[
          {
            "name":"Authorization",
            "in":"header",
            "description":"Authorization",
            "required":true,
            "type":"string"
          }
        ],
        "responses":{
          "200":{
            "description":"OK",
            "schema":{
              "$ref":"#/definitions/GetFavoritesResponse"
            }
          },
          "401":{
            "description":"Unauthorized"
          },
          "403":{
            "description":"Forbidden"
          },
          "404":{
            "description":"Not Found"
          }
        }
      }
    },
    "/favorites/{adId}":{
      "put":{
        "tags":[
          "favorites-controller"
        ],
        "summary":"Save favorite",
        "operationId":"saveFavorite",
        "consumes":[
          "application/json"
        ],
        "produces":[
          "application/json;charset=UTF-8"
        ],
        "parameters":[
          {
            "name":"adId",
            "in":"path",
            "description":"adId",
            "required":true,
            "type":"string"
          },
          {
            "name":"Authorization",
            "in":"header",
            "description":"Authorization",
            "required":true,
            "type":"string"
          }
        ],
        "responses":{
          "200":{
            "description":"OK"
          },
          "201":{
            "description":"Created"
          },
          "401":{
            "description":"Unauthorized"
          },
          "403":{
            "description":"Forbidden"
          },
          "404":{
            "description":"Not Found"
          }
        }
      },
      "delete":{
        "tags":[
          "favorites-controller"
        ],
        "summary":"Delete favorite",
        "operationId":"deleteFavorite",
        "consumes":[
          "application/json"
        ],
        "produces":[
          "application/json;charset=UTF-8"
        ],
        "parameters":[
          {
            "name":"adId",
            "in":"path",
            "description":"adId",
            "required":true,
            "type":"string"
          },
          {
            "name":"Authorization",
            "in":"header",
            "description":"Authorization",
            "required":true,
            "type":"string"
          }
        ],
        "responses":{
          "200":{
            "description":"OK"
          },
          "204":{
            "description":"No Content"
          },
          "401":{
            "description":"Unauthorized"
          },
          "403":{
            "description":"Forbidden"
          }
        }
      }
    }
  },
  "definitions":{
    "FavoriteAd":{
      "type":"object",
      "properties":{
        "adId":{
          "type":"string"
        },
        "userId":{
          "type":"string"
        }
      }
    },
    "GetFavoritesResponse":{
      "type":"object",
      "properties":{
        "favorites":{
          "type":"array",
          "items":{
            "$ref":"#/definitions/FavoriteAd"
          }
        }
      }
    },
    "Single«ResponseEntity«GetFavoritesResponse»»":{
      "type":"object"
    }
  }
}
Retrofit2 + RxJava2 Interface generated in Kotlin

It will generate the interface and the models related to that interface.

package com.mycompany.mylibrary

import io.reactivex.Completable
import io.reactivex.Single
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.PUT
import retrofit2.http.Path

interface componentNameApiInterface {
    @GET("/favorites")
    fun getFavorites(): Single<GetFavoritesResponse>

    @PUT("/favorites/{adId}")
    fun saveFavorite(@Path("adId") adId: String): Completable

    @DELETE("/favorites/{adId}")
    fun deleteFavorite(@Path("adId") adId: String): Completable
}

Download

RELEASE

You can download it through the intelliJ/AndroidStudio plugin interface or you can check: https://plugins.jetbrains.com/plugin/10206-protein--android-component-builder

Build it yourself!

  1. If you want to build it locally you need download the latest version of IntelliJ Community https://www.jetbrains.com/idea/download/#section=mac
  2. Clone this repository ([email protected]:AdevintaSpain/protein.git)
  3. Execute "RunIdea" gradle task

Who made this

Ferran Pons
Ferran Pons

Apps using Protein

The following is a list of some of the public apps using Protein and are published on the Google Play Store.

Want to add your app? Found an app that no longer works or no longer uses Protein? Please submit a pull request on GitHub to update this page!

vibbo Fotocasa

Contribute

  1. Create an issue to discuss about your idea
  2. [Fork it] (https://github.com/AdevintaSpain/protein/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 2018 Adevinta 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.

More Repositories

1

Barista

☕ The one who serves a great Espresso
Kotlin
1,703
star
2

Parallax-Layer-Layout

Layered parallax effect to any Android views
Java
957
star
3

Leku

🌍 Map location picker component for Android. Based on Google Maps. An alternative to Google Place Picker.
Kotlin
763
star
4

RxPager

RxPager is an Android library that helps handling paginated results in a reactive way
Java
56
star
5

Sencha

A library to facilitate UI tests using EarlGrey, with a more developer-friendly API.
Swift
47
star
6

Retroswagger

🧩 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.
Kotlin
38
star
7

Prado

Your images, your art gallery
Kotlin
17
star
8

TaggingViewer

Visualize live on-screen all the tagging that is occurring in your application
Kotlin
8
star
9

ms-test--hello-twitch

🌍 MicroServices Hello World Live from Twitch!
Kotlin
7
star
10

SwiftAdditions

A swift library for syntax sugar, dependency injection and a controlled startup process
Swift
6
star
11

wonderful-freshair-app

🦄 Wonderful FreshAir Application - Kotlin & Arrow sample
Kotlin
6
star
12

ms-test--factoriaf5-testing

🏫 Testing Workshop for Factoria F5 Bootcamp
Java
4
star
13

SUI-Components

Schibsted Spain UI Components
4
star
14

formacion-factoriaf5-databases

Java
3
star
15

ms-test--factoriaf5-helloworld

🏫 HelloWorld Workshop for Factoria F5 Bootcamp
Kotlin
3
star
16

advent-of-code-kotlin

🎄 Advent of Code in Kotlin
Kotlin
1
star
17

AWSEnums

Python module that contains a list of enums useful for your applications.
Python
1
star
18

ms-test--krakend-twitch

🐙 MicroServices KrakenD ApiGateway Live from Twitch!
Shell
1
star
19

htransformation

Header transformation plugin for traefik
Go
1
star