使用扬鞭春REST API文档 [英] Spring REST API Documentation using Swagger

查看:255
本文介绍了使用扬鞭春REST API文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找一个工具,它可以帮助我产生的RESTful API文档。我的服务器是用Java编写,并使用Spring MVC框架。我没有在我的服务器看法。这是一个100%的RESTful服务以及所有它确实是消耗JSON和吐出JSON。

I am looking for a tool which could help me generate RESTful API documentation. My server is written in Java and uses Spring MVC framework. I do not have VIEWS in my server. It's a 100% RESTful service and all it does is consumes JSON and spits out JSON.

我在想,如果扬鞭是与Spring的注解兼容?

I was wondering if Swagger is compatible with Spring annotations?

推荐答案

有当前不可用(从Wordnik至少),但在一般的Spring MVC招摇模块,可实现对基于JVM的REST服务招摇是pretty简单。

There currently is not a Spring MVC swagger module available (from Wordnik at least) but in general, enabling swagger on a JVM-based REST service is pretty simple.

扬鞭服务器支持被分成两部分 - 在核心服务器和REST服务的整合。请参阅扬鞭GitHub库。扬鞭核心定义重新presents REST服务,参数,允许值,HTTP操作等服务器集成电线以此文献给REST框架结构的文档。 Wordnik使用泽西通过JAX-RS和发布招摇,JAXRS做这种整合。也有将被释放到播放模块扬鞭播放模块不久库

Swagger server support is divided into two parts--the core server and the integration with the REST service. See the Swagger github repo. Swagger core defines the document that represents the REST service, parameters, allowable values, HTTP operations, etc. The server integration wires this document to the structure of the REST framework. Wordnik uses Jersey via JAX-RS and released swagger-jaxrs to do this integration. There is also a Swagger-Play module which will be released to the Play module repository shortly.

如果您想要启用另一个REST框架(如Spring MVC)招摇,请按照下列步骤:

If you want to enable swagger on another REST framework (like Spring MVC), you follow these steps:

1)生成一个API阅读器来生成com.wordnik.swagger.core.Documentation对象。请参阅<一个href=\"https://github.com/wordnik/swagger-core/blob/master/modules/swagger-jaxrs/src/main/scala/com/wordnik/swagger/jaxrs/JaxrsApiReader.scala\">JAX-RS版以及一个用于<一href=\"https://github.com/wordnik/swagger-core/blob/master/modules/swagger-play/src/play/modules/swagger/PlayApiReader.scala\">play.

1) Generate an API Reader to generate a com.wordnik.swagger.core.Documentation object. See the JAX-RS version as well as the one for play.

2)创建一个REST端点返回文档对象的JSON / XML版本客户端。同样,<一个href=\"https://github.com/wordnik/swagger-core/blob/master/modules/swagger-jaxrs/src/main/scala/com/wordnik/swagger/jaxrs/ApiListingResource.scala\">JAX-RS和<一个href=\"https://github.com/wordnik/swagger-core/blob/master/modules/swagger-play/src/play/modules/swagger/ApiHelpInventory.scala\">play.

2) Create a REST endpoint which returns a JSON/XML version of the Documentation object to the client. Again, JAX-RS and play.

3)添加过滤器拦截请求强制执行资源或对象级别的访问。

3) Add a filter to intercept requests to enforce resource or object-level access.

因此​​,在短期,它可以很容易地放在一起pretty。

So in short, it could be put together pretty easily.

这篇关于使用扬鞭春REST API文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆