天天看点

在网关gateway聚合swagger文档

jar包支持

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

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-spring-webflux</artifactId>
            <version>3.0.0</version>
        </dependency>

        <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>swagger-bootstrap-ui</artifactId>
            <version>1.9.6</version>
        </dependency>
           

配置类SwaggerAggregationConfig

package com.fms.gateway.config;

import com.google.common.collect.Lists;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebFlux;

import java.util.List;

/**
 * create by uking on 2020/7/28
 */
@Data
@Primary
@Component
@RefreshScope
@EnableSwagger2WebFlux
@ConfigurationProperties(prefix = "swagger.resource")
public class SwaggerAggregationConfig implements SwaggerResourcesProvider {

    private List<SwaggerResource> list = Lists.newArrayList();

    @Override
    public List<SwaggerResource> get() {
        return list;
    }

}

           

网关需要放开的地址

http
            		.authorizeExchange()
            		.pathMatchers(
						"/*/v2/api-docs",
                     	"/doc.html",
                     	"/webjars/**",
                     	"/swagger-ui.html",
                     	"/swagger-resources/configuration/ui",
                    	 "/swagger-resources"
                    ).permitAll()
           

最后yml 文件配置

swagger:
  resource:
    list:
    - {name: 管理平台, location: /cloud-fms/v2/api-docs, swaggerVersion: 1.0}
    - {name: 视频服务, location: /cloud-video/v2/api-docs, swaggerVersion: 1.0}
           

访问地址:http://localhost:8080/doc.html