We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
目前还没有可用的 Spring MVC swagger 模块(至少来自 Wordnik),但一般来说,在基于 JVM 的 REST 服务上启用 swagger 非常简单。
Swagger 服务器支持分为两部分——核心服务器和与 REST 服务的集成。请参阅 Swagger github 存储库。 Swagger 核心定义了表示 REST 服务、参数、允许值、HTTP 操作等的文档。服务器集成将此文档连接到 REST 框架的结构。 Wordnik 通过 JAX-RS 使用 Jersey 并发布了 swagger-jaxrs 来进行此集成。还有一个 Swagger-Play 模块,它将很快就会发布到 Play 模块存储库。
如果您想在另一个 REST 框架(如 Spring MVC)上启用 swagger,请按照以下步骤操作:
1) 生成 API Reader 以生成 com.wordnik.swagger.core.Documentation 对象。请参阅 JAX-RS 版本以及 播放 。
2) 创建一个 REST 端点,将文档对象的 JSON/XML 版本返回给客户端。再次, JAX-RS 和 播放 。
3) 添加过滤器来拦截请求以强制执行资源或对象级别的访问。
简而言之,它可以很容易地组合在一起。
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.
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.
If you want to enable swagger on another REST framework (like Spring MVC), you follow these steps:
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) Create a REST endpoint which returns a JSON/XML version of the Documentation object to the client. Again, JAX-RS and play.
3) Add a filter to intercept requests to enforce resource or object-level access.
So in short, it could be put together pretty easily.
此处正在实施 Swagger-SpringMVC 和示例这里。
规范 v1.2 已完全实现和支持(即生成模型,并完全支持泛型),并且正在积极开发中。
There is a Swagger-SpringMVC implementation in progress here and examples here.
The spec v1.2 is fully implemented and supported (ie., models are generated, with full support for generics), and it's under active development.
Spring MVC 的 Swagger 的另一个实现是 swagger4spring-web。
它类似于 Swagger-SpringMVC,支持所有 Swagger 注释并为返回类型和参数生成 JSON 架构。它也可以在没有 swagger 注释的情况下工作。
Another implementation of Swagger for Spring MVC is swagger4spring-web.
It's similar to Swagger-SpringMVC and supports all Swagger annotations and generates JSON schema for return types and parameters. It also works without swagger annotations.
如果您只是在生成交互式 API 文档之后(不需要 wiki 风格的协作),I/O Docs 将是一个更好的解决方案,需要更少的精力来设置、使用和定制,恕我直言。
它运行在nodejs 和Redis 上。您只需编写 API 的 JSON 模式,它就会生成一个 HTML/JS 站点来描述您的 API,并让开发人员可以通过浏览器实时使用它。
我计划在我的服务器上托管我的 API(因为要求任何人安装另外 2 个软件只是为了查看 API 会很疯狂),但 JSON 模式本身已经具有良好的可读性和紧凑的结构,我认为这足以与其他人协作程序员。这是一个小项目。
有一个类似的问题< /a> 您可能想查看一下。
If you are only after generating an interactive API document (without the need for wiki style collaboration), I/O Docs would be a better solution requires much less effort to set up, use and customise, IMHO.
It's running on nodejs and Redis. You only need to write a JSON schema of your API and it generates a HTML/JS site that describes your API and lets developers to play with it live from their browser.
I plan to host my API on my server (as requiring anyone to install 2 other softwares just to view the API would be crazy) but the JSON schema itself already has a nice readable and compact structure which I think would be sufficient for collaboration with other programmers. It's a small project.
There is a similar question you may want to check out.
Swagger 2.0 是 Swagger 的最新版本。
现在有不同版本的 Swagger 可满足不同的需求。
io.swagger 是 swagger 库的包,您需要单独的 spring jar 将其与 Spring 耦合。这是 swagger 的第二版。
io.springfox 是 Springfox Swagger2,其中 swagger 与 Spring 集成。
com.mangofactory
是与 Spring Web MVC 框架集成的 swagger。Swagger 2.0 is the latest version of Swagger.
There are different variations of Swagger now available for differing needs.
io.swagger
is the package for swagger libraries and you need separate spring jars to couple it with Spring. This is version 2 of swagger.io.springfox
is Springfox Swagger2, wherein swagger comes integrated with Spring.com.mangofactory
is swagger integrated with Spring Web MVC framework.