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>
  • 相关阅读:
    试题 E: 迷宫
    对拍程序
    人群中钻出个光头
    HDU-魔咒词典(字符串hash)
    第八集 你明明自己也生病了,却还是要陪着我
    智力问答 50倒计时
    数据结构
    LeetCode刷题 fIRST MISSING POSITIVE
    LeetCode Best to buy and sell stock
    LeetCode Rotatelmage
  • 原文地址:https://www.cnblogs.com/flame540/p/12870780.html
Copyright © 2011-2022 走看看