Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Retrofit client generator #465

Closed
futurely opened this issue Mar 4, 2015 · 12 comments
Closed

Add a Retrofit client generator #465

futurely opened this issue Mar 4, 2015 · 12 comments

Comments

@futurely
Copy link

futurely commented Mar 4, 2015

Retrofit is a very popular "type-safe REST client for Android and Java by Square, Inc".

Smartbear developed an example for GitHub API.

https://github.com/olensmar/github-retrofit-client/tree/master/src/main/java/com/olensmar/apis/github

They didn't use template. Instead, the generator is hard coded in Groovy. It should be possible to implement the same functionality with pure templates.

https://github.com/olensmar/soapui-retrofit-plugin/blob/e40722ebbb4c9c97017aa72c04d184e5cd65c4a6/src/main/groovy/com.smartbear.soapui.plugin.retrofit/RetrofitGenerator.groovy

@webron
Copy link
Contributor

webron commented Mar 4, 2015

Sounds like a great idea! Maybe @olensmar would like to contribute it? ;)

@olensmar
Copy link
Contributor

olensmar commented Mar 4, 2015

awesome - I'll definitely have a look!

just FYI - the plugin referred to above generates Retrofit interfaces for any REST API, i.e. the API doesn't have to be defined with a swagger spec

@Panthro
Copy link

Panthro commented Oct 19, 2015

Any news on that guys?

I use swagger for all my apis, but like retrofit better for the client side.

It would be awesome to be able to generate the client automagically!

@wing328
Copy link
Contributor

wing328 commented Oct 19, 2015

The latest Java API client supports different HTTP client including Retrofit. To use Retrofit, please create a config.json file as follows:

{
  "library": "retrofit"
}

and pass config.json via -c in the command line

You can run java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l java for more information on customizing the Java API client.

Would that meet your requirement?

@fehguy
Copy link
Contributor

fehguy commented Oct 25, 2015

Please reopen if you need help on this. It's now supported as an option when generating java clients.

@fehguy fehguy closed this as completed Oct 25, 2015
@fehguy fehguy modified the milestone: v2.1.4 Oct 26, 2015
@Panthro
Copy link

Panthro commented Oct 26, 2015

I just generated a cli based using the following command:

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar  generate -i http://localhost:8080/v2/api-docs -l java -o myapi/client/java --library retrofit

It all went well and seemed to work, I explored the code and liked what I saw, with Oauth authentication flow and everything in place, but when I tried a mvn package this happened:

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[10,30] error: cannot find symbol
[ERROR]  package io.swagger.client.model
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[52,10] error: cannot find symbol
[ERROR]  interface BuildrequestresourceApi
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[65,10] error: cannot find symbol
[ERROR]  interface BuildrequestresourceApi
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[10,30] error: cannot find symbol
[ERROR]  package io.swagger.client.model
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[53,10] error: cannot find symbol
[ERROR]  interface UserresourceApi
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[66,10] error: cannot find symbol
[ERROR]  interface UserresourceApi
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[3,0] error: package com.fasterxml.jackson.annotation does not exist
[ERROR] /Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[4,0] error: package com.fasterxml.jackson.databind does not exist
[ERROR] /Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[5,0] error: package com.fasterxml.jackson.datatype.joda does not exist
[ERROR] /Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[11,10] error: cannot find symbol
[ERROR]  class JSON
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[14,17] error: cannot find symbol
[ERROR]  class JSON
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[15,48] error: package JsonInclude does not exist
[ERROR] /Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[16,21] error: cannot find symbol
[ERROR]  class JSON
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[17,19] error: cannot find symbol
[ERROR]  class JSON
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[18,18] error: cannot find symbol
[ERROR]  class JSON
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[19,18] error: cannot find symbol
[ERROR]  class JSON
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[20,30] error: cannot find symbol
[ERROR]  class JSON
/Users/panthro/swagger/swagger-codegen/myclient/client/java/src/main/java/io/swagger/client/JSON.java:[45,4] error: cannot find symbol
[INFO] 18 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.287 s
[INFO] Finished at: 2015-10-26T10:25:00+01:00
[INFO] Final Memory: 16M/301M
[INFO] ------------------------------------------------------------------------

I don't know if it's anything related to the retrofit or just a common bug.

my git is pointing to the latest commit, which is 6b7ceab

@wing328
Copy link
Contributor

wing328 commented Oct 26, 2015

@Panthro I could repeat the issue. Let me look into it and get back to you.

@wing328
Copy link
Contributor

wing328 commented Oct 27, 2015

@Panthro the issue has been addressed by @xhh via #1444

Please pull the latest master and give it another try.

@Panthro
Copy link

Panthro commented Oct 27, 2015

So, I tried.

[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[10,30] error: cannot find symbol
[ERROR]  package io.swagger.client.model
/Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[53,10] error: cannot find symbol
[ERROR]  interface BuildrequestresourceApi
/Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[66,10] error: cannot find symbol
[ERROR]  interface BuildrequestresourceApi
/Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[10,30] error: cannot find symbol
[ERROR]  package io.swagger.client.model
/Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[53,10] error: cannot find symbol
[ERROR]  interface UserresourceApi
/Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[66,10] error: cannot find symbol
[INFO] 6 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.211 s
[INFO] Finished at: 2015-10-27T15:43:57+01:00
[INFO] Final Memory: 16M/297M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project swagger-java-client: Compilation failure: Compilation failure:
[ERROR] /Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[10,30] error: cannot find symbol
[ERROR] package io.swagger.client.model
[ERROR] /Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[53,10] error: cannot find symbol
[ERROR] interface BuildrequestresourceApi
[ERROR] /Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/BuildrequestresourceApi.java:[66,10] error: cannot find symbol
[ERROR] interface BuildrequestresourceApi
[ERROR] /Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[10,30] error: cannot find symbol
[ERROR] package io.swagger.client.model
[ERROR] /Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[53,10] error: cannot find symbol
[ERROR] interface UserresourceApi
[ERROR] /Users/panthro/swagger/swagger-codegen/myapi/client/java/src/main/java/io/swagger/client/api/UserresourceApi.java:[66,10] error: cannot find symbol

@wing328
Copy link
Contributor

wing328 commented Oct 27, 2015

@Panthro do you mind sharing the spec with us (privately via my personal email address or publicly) so that we can use it to reproduce the issue?

@Panthro
Copy link

Panthro commented Oct 27, 2015

shared with you by email.
I believe if you generate a jhipster project with oauth as authentication method and give it a try as your specs you will have the same issue

@olegivo
Copy link

olegivo commented May 29, 2019

Please reopen if you need help on this. It's now supported as an option when generating java clients.

Is it possible to make option to use retrofit with kotlin and android?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants