zoukankan      html  css  js  c++  java
  • Swagger的应用

    一、介绍

    • 一个规范和完整的框架,用于生成、描述、调用和可视化 RESTful 风格的 Web 框架。

    二、依赖

    <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-swagger2</artifactId>
          <version>2.9.2</version>
    </dependency>
    <dependency>
         <groupId>io.springfox</groupId>
         <artifactId>springfox-swagger-ui</artifactId>
         <version>2.9.2</version>
    </dependency>
    package com.guli.edu.config;
    
    @Configuration
    @EnableSwagger2
    public class Swagger2Config {
    
        @Bean
        public Docket webApiConfig(){
    
            return new Docket(DocumentationType.SWAGGER_2)
                    .groupName("webApi")
                    .apiInfo(webApiInfo())
                    .select()
                    .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                    .paths(Predicates.not(PathSelectors.regex("/error.*")))
                    .build();
    
        }
    
        @Bean
        public Docket adminApiConfig(){
    
            return new Docket(DocumentationType.SWAGGER_2)
                    .groupName("adminApi")
                    .apiInfo(adminApiInfo())
                    .select()
                    .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                    .build();
    
        }
    
        private ApiInfo webApiInfo(){
    
            return new ApiInfoBuilder()
                    .title("网站-课程中心API文档")
                    .description("本文档描述了课程中心微服务接口定义")
                    .version("1.0")
                    .contact(new Contact("Helen", "http://atguigu.com", "55317332@qq.com"))
                    .build();
        }
    
        private ApiInfo adminApiInfo(){
    
            return new ApiInfoBuilder()
                    .title("后台管理系统-课程中心API文档")
                    .description("本文档描述了后台管理系统课程中心微服务接口定义")
                    .version("1.0")
                    .contact(new Contact("Helen", "http://atguigu.com", "55317332@qq.com"))
                    .build();
        }
    }
    View Code

    三、注解

       参考:springboot集成swagger2 

    四、配置(可以使用配置类或者配置文件)

    swagger:
      title: TMax API接口文档
      description: TMax Api Documentation
      version: 1.0.0
      termsOfServiceUrl: https://www.sscai.club
      contact:
        name: niceyoo
        url: https://www.sscai.club
        email: apkdream@163.com

     五、两款美化插件

    1、swagger-mg-ui
            <dependency>
                <groupId>com.zyplayer</groupId>
                <artifactId>swagger-mg-ui</artifactId>
                <version>1.0.6</version>
            </dependency>
    
    2、knife4j
            <dependency>
                <groupId>com.github.xiaoymin</groupId>
                <artifactId>knife4j-spring-ui</artifactId>
                <version>2.0.4</version>    
            </dependency>
  • 相关阅读:
    ROS中.launch文件的remap标签详解
    宝宝刷 leetcode
    ROS rosrun 调用 sudo 命令
    在moveit编译时找不到manipulation_msgsConfig.cmake manipulation_msgs-config.cmake文件
    CMake error with move_base_msgs问题解决
    VIVE pro和hololens购买调研
    /usr/bin/ld: 找不到 -lmsc----解决方案
    ubuntu16.04安装kinetic调用gazebo_control解决方案
    tomcat http协议与ajp协议
    GC日志分析
  • 原文地址:https://www.cnblogs.com/flame540/p/12870780.html
Copyright © 2011-2022 走看看