Skip to content
Advertisement

How to generate java client code for swagger REST API documentation

My scenario is the following.

I have a swagger .json eg.: http://petstore.swagger.io/v2/swagger.json I want to use a generated java client for the REST API above, like:

JavaScript

Expexted output: cica and the new pet is stored according to the REST API implmentation.

I have successfully generated server stub for the petstore with the command:

JavaScript

But this maven project code is a server code. It has annotations like @RequestMapping in PetApi.java and also has a WebMvcConfiguration.class.

I do not want to have a server-stub. I want to have a client-library for the petstore REST API.

Is there a tool which can generate the appropriate client library for me? Should I modify the server-stub, hence it has all the models or should I use a simple springRestTemplate?

Thanks for the answers!

Advertisement

Answer

I think that you don’t use the right value for the parameter -l of Swagger Codegen (you use spring-mvc which is a server-side technology). You could try to use the value java.

You could also notice that there is a tool, the Restlet Studio, that allows to generate code from Swagger content. For Java, it mainly relies on the Restlet framework but I think that it could suit your needs.

Hope it helps you, Thierry

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement