10

I want to generate sdk using swagger codegen which can give me generated sdk with Observable as callback like below :

@POST("oauth/token")
Observable < TokenResponse> getRepository(@Query("grant_type") String grantType);

William Cheng
  • 10,137
  • 5
  • 54
  • 79
rcde0
  • 4,192
  • 3
  • 21
  • 31
  • take a look from here https://github.com/saveendhiman/SampleApp/blob/master/app/src/main/java/com/sampleapp/api/RestService.java – Saveen Dec 08 '16 at 13:45
  • And the question is ... – Selvin Dec 08 '16 at 13:47
  • @Saveen Thank you,but I guess you did not get my question.I want to create a sdk using Swagger codegen which creates an interface like above for every api calls made..I want to know about the command actually which for java is : java -jar swagger-codegen-cli-2.1.4.jar generate -i http://localhost:8080/v2/api-docs -l java -o retrofit/ -c config.json – rcde0 Dec 09 '16 at 06:11
  • @Selvin And the question is what I asked. – rcde0 Dec 09 '16 at 06:13

3 Answers3

17

You can generate a Java Retrofit API client with RxJava enabled using the following command as an example:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
-l java -i http://petstore.swagger.io/v2/swagger.json \
-c /var/tmp/retrofit2rx/java-petstore-retrofit2rx.json \
-o /var/tmp/retrofit2rx 

and the JSON config file (/var/tmp/retrofit2rx/java-petstore-retrofit2rx.json) defines the following:

{
  "library": "retrofit2",
  "artifactId": "swagger-petstore-retrofit2-rx",
  "useRxJava": true,
  "hideGenerationTimestamp": true
}

You can then find the auto-generated code under the /var/tmp/retrofit2rx folder.

Please use the latest stable version of Swagger Codegen instead: https://github.com/swagger-api/swagger-codegen/releases, or pull the latest master of swagger-codegen to enjoy the enhancements and bug fixes.

To get a list of options for customizing the Java API client, please run the following command:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java

UPDATE: On May 2018, about 50 top contributors and template creators of Swagger Codegen decided to fork Swagger Codegen to maintain a community-driven version called OpenAPI Generator. Please refer to the Q&A for more information.

William Cheng
  • 10,137
  • 5
  • 54
  • 79
1

I would recommend Swagger Gradle Codegen, Generates Kotlin code and Retrofit interfaces, with RxJava2 for async calls, Moshi for serialization and ThreeTenABP for Data management

Chathura Wijesinghe
  • 3,310
  • 3
  • 25
  • 41
-1

For codegen you can use this for the JSON config file, is very similar that above response but I had to use useRxJava2 instead of useRxJava, like this: :

 {
    "library": "retrofit2",
    "artifactId": "swagger-petstore-retrofit2-rx",
    "useRxJava2": true,
    "hideGenerationTimestamp": true,
 }
dicarlomagnus
  • 576
  • 4
  • 17