rest服务swagger_使用Swagger轻松记录您的Play Framework REST API
生活随笔
收集整理的這篇文章主要介紹了
rest服务swagger_使用Swagger轻松记录您的Play Framework REST API
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
rest服務swagger
- 該帖子最初在http:// swag ger.io(7/30/2015)上發布
我一直在使用Play Framework作為多個項目的基于Java的,閃電般的REST后端框架。 后來,我很高興找到Swagger,并努力將其集成到幾個項目中。 當我第一次掙扎時,我認為分享經驗并撰寫一篇“如何做”的文章來描述快速成功的步驟將很有用。
為了簡化操作,我從James Ward創建的現有Play框架,Java,JPA,REST項目開始。 James的項目位于GitHub上,因此在開始此方法之前, 應先將其拉出 。
操作步驟
api.version="1.0" swagger.api.basepath="http://localhost:9000"
然后是GET和POST方法的注釋:
@ApiOperation(value = "get All Todos",notes = "Returns List of all Todos",response = Todo.class, httpMethod = "GET") public static Result getAllTodos() { return ok(toJson(models.Todo.findByUser(SecurityController.getUser()))); } @ApiOperation( nickname = "createTodo", value = "Create Todo", notes = "Create Todo record", httpMethod = "POST", response = Todo.class) @ApiImplicitParams( { @ApiImplicitParam( name = "body", dataType = "Todo", required = true, paramType = "body", value = "Todo" ) } ) @ApiResponses( value = { @com.wordnik.swagger.annotations.ApiResponse(code = 400, message = "Json Processing Exception") } ) public static Result createTodo() { Form<models.Todo> form = Form.form(models.Todo.class).bindFromRequest(); if (form.hasErrors()) { return badRequest(form.errorsAsJson()); } else { models.Todo todo = form.get(); todo.user = SecurityController.getUser(); todo.save(); return ok(toJson(todo)); } }http://localhost:9000/assets/lib/swagger-ui/index.html?/url=http://localhost:9000/api-docs
源代碼
如開始所述,我從James Ward在github上的play-rest-security開始,并在我的fork上進行了這些修改。 對于所有感興趣的人,這里是源代碼:
- https:// e.cúrity
注意:同時,James Ward批準了我的拉取請求,將這些更改添加到他的項目GitHub中,因此您應該將其拉出
翻譯自: https://www.javacodegeeks.com/2015/08/its-easy-to-document-your-play-framework-rest-api-with-swagger.html
rest服務swagger
總結
以上是生活随笔為你收集整理的rest服务swagger_使用Swagger轻松记录您的Play Framework REST API的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 非常棒的英语怎么写 非常棒的英语是什么
- 下一篇: 512的立方根是多少 512的立方根是什