How to generate java client code for swagger REST API documentation

后端 未结 6 509
谎友^
谎友^ 2020-12-05 09:58

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, li

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-05 10:44

    For your scenario your command should look like this

    java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate
     -i http://petstore.swagger.io/v2/swagger.json
     -l java
     -o samples/server/petstore/spring-mvc
    

    Other options to convert swagger to jave are:

    • swagger-codegen
    • generator.swagger.io
    • editor.swagger.io
    • Restlet
    • APIMATIC

    Though with the GitHub project it's up to you to decide which library (jersey, jersey2, okhttp-gson, etc.) to use when converting swagger to Java client or server code. With generator.swagger.io you can also decide which library to use. There might be an enhancement to editor.swagger.io to be able to select the library to use as well. To consider is that the swagger.io options are completely free, whereas Restlet and APIMATIC are freemium.

提交回复
热议问题