Spring 3 和 Spring 4 的 Swagger 版本 [英] Swagger Version for Spring 3 and Spring 4

查看:69
本文介绍了Spring 3 和 Spring 4 的 Swagger 版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 Swagger 和 Spring MVC 记录 REST API,

然后我发现 Spring 3 只能使用 Swagger V1

 swagger-springmvc<version>1.0.2</version>

当我在@RequestBody 前面添加@ApiParam 时,在数据类型中不完全显示.

最后我在 Spring 4 中选择了 Swagger V2

我添加了一些依赖项并进行了更改,如下所示.

 springfox-swagger2<version>2.2.2</version><artifactId>spring-web</artifactId><artifactId>4.1.6.RELEASE</artifactId>

现在可以在需要时显示任何 API 信息,

<块引用>

  1. 但仍然不知道为什么 Spring 3 只能使用 SwaggerV1

  2. 和Spring 3 &的区别4 使用 Swagger V2 时

  3. 为什么 Spring 3 不需要 spring-web,而 Spring 4 需要

如果需要任何信息,请告诉我

如果您能提供任何帮助,我将不胜感激.

解决方案

免责声明:SpringFox 不是产品,而是一个 OSS 项目.我是该项目的维护者之一,也是目前唯一的活跃维护者.

话虽如此,让我回答您的一些问题.

<块引用>

但仍然不知道为什么 Spring 3 只能使用 SwaggerV1

作为一项政策,当前积极维护的版本是最新版本 spring 的一个次要版本.Swagger v1 已经很老了,所以当 swagger 2 发布时,我们积极地迁移到了较新版本的 spring,最后一个支持 spring 3 的版本是 1.0.2.这遵循与 spring-hateoas 等 spring 项目相同的准则.

<块引用>

以及 Spring 3 和 Spring 3 之间的区别4 使用 Swagger V2 时

不同之处在于 spring 3 并不是 springfox v2.x 真正支持的版本.spring的官方测试版本是4.1.7.RELEASE for v2.2.2.

<块引用>

为什么 Spring 3 不需要 spring-web,而 Spring 4 需要

这是因为我们spring是springfox的一个提供的依赖.所以库消费者可以提供任何版本 >4.1 和库就可以工作了.在 spring 3 中情况并非如此,因为我们随 spring 依赖项一起提供了 springfox 库.

I want to documenting a REST API with Swagger and Spring MVC,

And I find out that Spring 3 only can use Swagger V1

        <artifactId>swagger-springmvc</artifactId>
        <version>1.0.2</version>

when I add @ApiParam in front of @RequestBody , do not display completely in Data Type.

Finally I choose Swagger V2 in Spring 4

I add some dependency and change, as below .

        <artifactId>springfox-swagger2</artifactId>
        <version>2.2.2</version>
        <artifactId>spring-web</artifactId>
        <artifactId>4.1.6.RELEASE</artifactId>

Now can display any API info when I needs,

  1. But still no idea why Spring 3 only can use SwaggerV1

  2. and the difference between the Spring 3 & 4 when use Swagger V2

  3. why Spring 3 not need spring-web ,but Spring 4 need

If need any information , please tell me

I will be grateful for any help you can provide.

解决方案

DISCLAIMER: SpringFox is not a product and is an OSS project. Im one of the maintainers of the project and currently the only active maintainer.

Having said that, let me answer some of your questions.

But still no idea why Spring 3 only can use SwaggerV1

As a policy, the current actively maintained version is one minor version behind the latest version of spring. Swagger v1 is quite old, so when swagger 2 was released we actively moved to a newer version of spring and the last version that supports spring 3 is 1.0.2. This follows the same guidelines that spring projects like spring-hateoas follow.

and the difference between the Spring 3 & 4 when use Swagger V2

The difference is that spring 3 is not really a supported version for springfox v2.x. The officially tested version of spring is 4.1.7.RELEASE for v2.2.2.

why Spring 3 not need spring-web ,but Spring 4 need

This is because we spring is a provided dependency of springfox. So library consumers of can provide any version > 4.1 and the library would just work. This was not the case in spring 3 because we shipped the springfox library with the spring dependencies.

这篇关于Spring 3 和 Spring 4 的 Swagger 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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