swagger的使用说明

swagger的使用说明

对于swagger的使用,实际上,我们不是单独使用,都是以springfox整合swagger的方式来使用的。以下是两个springfox版本的使用说明。

1 springfox2整合swagger

  1. 访问URL: http://host:port/context-path/swagger-ui.html
    eg. http://localhost:8888/swagger-ui.html

  2. 文档接口: http://localhost:8888/v2/api-docs

  3. maven依赖

        <dependency>
            <groupId>com.spring4all</groupId>
            <artifactId>swagger-spring-boot-starter</artifactId>
            <version>1.9.0.RELEASE</version>
        </dependency>

以上依赖,实际上内部包含了以下2个swagger依赖:

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

2 springfox3整合swagger

  1. 访问URL:
    旧URL也能用:http://host:port/context-path/swagger-ui.html
    还添加了新的URL:http://host:port/context-path/swagger-ui/
    另一个新的URL:http://host:port/context-path/swagger-ui/index.html
    eg1. http://localhost:8888/swagger-ui/
    eg2. http://localhost:8888/swagger-ui/index.html

  2. 文档接口:
    旧的也能用:http://localhost:8888/v2/api-docs
    还添加了新的:http://localhost:8888/v3/api-docs

  3. maven依赖

        <!-- swagger3-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-boot-starter</artifactId>
           <version>3.0.0</version>
        </dependency>

        <!-- 防止进入swagger页面报类型转换错误,排除3.0.0中的引用,手动增加1.6.2版本 -->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.6.2</version>
        </dependency>

以上依赖,实际上内部包含了以下2个swagger依赖:

    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>3.0.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>3.0.0</version>
      <scope>compile</scope>
    </dependency>
posted @ 2022-06-04 11:06  mediocrep  阅读(346)  评论(0编辑  收藏  举报
既然选择了远方,便只顾风雨兼程!