mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-13 22:09:00 +08:00
♻️ Refactoring code. 使用openapi3 替代swagger2
This commit is contained in:
1 parent
032c1b54d3
commit
eb3387da9f
165 files changed
+1188
-1635
No files matched your search
@@ -20,7 +20,6 @@
|
||||
package com.pig4cloud.pigx.gateway;
|
||||
|
||||
import com.pig4cloud.pigx.common.gateway.annotation.EnablePigxDynamicRoute;
|
||||
import com.pig4cloud.pigx.common.swagger.annotation.EnablePigxSwagger2;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
@@ -29,7 +28,6 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
* @author lengleng
|
||||
* @date 2018年06月21日 网关应用
|
||||
*/
|
||||
@EnablePigxSwagger2
|
||||
@EnablePigxDynamicRoute
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.pig4cloud.pigx.gateway.config;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.Data;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.GroupedOpenApi;
|
||||
import org.springdoc.core.SwaggerUiConfigParameters;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2022/3/26
|
||||
* <p>
|
||||
* swagger 3.0 展示
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
public class SpringDocConfiguration {
|
||||
|
||||
private final DiscoveryClient discoveryClient;
|
||||
|
||||
@Bean
|
||||
@Lazy(false)
|
||||
@ConditionalOnProperty(name = "springdoc.api-docs.enabled", matchIfMissing = true)
|
||||
public List<GroupedOpenApi> apis(SwaggerUiConfigParameters swaggerUiConfigParameters) {
|
||||
List<GroupedOpenApi> groups = new ArrayList<>();
|
||||
|
||||
for (String serviceId : discoveryClient.getServices()) {
|
||||
for (ServiceInstance instance : discoveryClient.getInstances(serviceId)) {
|
||||
String doc = instance.getMetadata().get("spring-doc");
|
||||
if (StrUtil.isNotBlank(doc)){
|
||||
swaggerUiConfigParameters.addGroup(doc,serviceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
@Component
|
||||
@ConfigurationProperties("swagger")
|
||||
public class SwaggerDocProperties {
|
||||
|
||||
private Map<String, String> services;
|
||||
|
||||
/**
|
||||
* 认证参数
|
||||
*/
|
||||
private SwaggerBasic basic = new SwaggerBasic();
|
||||
|
||||
@Data
|
||||
public class SwaggerBasic {
|
||||
|
||||
/**
|
||||
* 是否开启 basic 认证
|
||||
*/
|
||||
private Boolean enabled;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -78,7 +78,7 @@ public class PigxRequestGlobalFilter implements GlobalFilter, Ordered {
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return -1000;
|
||||
return 10;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,16 @@ spring:
|
||||
server-addr: ${NACOS_HOST:pigx-register}:${NACOS_PORT:8848}
|
||||
config:
|
||||
server-addr: ${spring.cloud.nacos.discovery.server-addr}
|
||||
gateway:
|
||||
routes:
|
||||
# 固定路由转发配置 无修改
|
||||
- id: openapi
|
||||
uri: lb://pigx-gateway
|
||||
predicates:
|
||||
- Path=/v3/api-docs/**
|
||||
filters:
|
||||
- RewritePath=/v3/api-docs/(?<path>.*), /$\{path}/$\{path}/v3/api-docs
|
||||
config:
|
||||
import:
|
||||
- optional:nacos:application-@profiles.active@.yml
|
||||
- optional:nacos:${spring.application.name}-@profiles.active@.yml
|
||||
- optional:nacos:${spring.application.name}-@profiles.active@.yml
|
||||
Reference in new issue
Block a user