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
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.
- Easy interface
- Interface and Models auto-generated
- Swagger integration: create code based on swagger documentation
- IntelliJ and Android Studio compatible
To use it you need a Swagger schema endpoint (example: http://petstore.swagger.io/v2/swagger.json).
{
"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"
}
}
}
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
}
You can download it through the intelliJ/AndroidStudio plugin interface or you can check: https://plugins.jetbrains.com/plugin/10206-protein--android-component-builder
- If you want to build it locally you need download the latest version of IntelliJ Community https://www.jetbrains.com/idea/download/#section=mac
- Clone this repository (git@github.com:AdevintaSpain/protein.git)
- Execute "RunIdea" gradle task
Ferran Pons |
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 |
- Create an issue to discuss about your idea
- [Fork it] (https://github.com/AdevintaSpain/protein/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Profit! ✅
For bugs, questions and discussions please use the Github Issues.
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.