|
@@ -4,6 +4,13 @@ import cn.hfln.framework.knife4j.doc.base.BaseSwaggerConfig;
|
|
import cn.hfln.framework.knife4j.doc.base.SwaggerProperties;
|
|
import cn.hfln.framework.knife4j.doc.base.SwaggerProperties;
|
|
import cn.hfln.framework.knife4j.doc.properties.DocProperties;
|
|
import cn.hfln.framework.knife4j.doc.properties.DocProperties;
|
|
import io.swagger.v3.oas.models.OpenAPI;
|
|
import io.swagger.v3.oas.models.OpenAPI;
|
|
|
|
+import io.swagger.v3.oas.models.info.Contact;
|
|
|
|
+import io.swagger.v3.oas.models.info.Info;
|
|
|
|
+import io.swagger.v3.oas.models.info.License;
|
|
|
|
+import io.swagger.v3.oas.models.Components;
|
|
|
|
+import io.swagger.v3.oas.models.security.SecurityRequirement;
|
|
|
|
+import io.swagger.v3.oas.models.security.SecurityScheme;
|
|
|
|
+import io.swagger.v3.oas.models.servers.Server;
|
|
import org.springdoc.core.SpringDocConfiguration;
|
|
import org.springdoc.core.SpringDocConfiguration;
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
@@ -13,6 +20,8 @@ import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Import;
|
|
import org.springframework.context.annotation.Import;
|
|
import org.springframework.context.annotation.Primary;
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @USER: YangLiu
|
|
* @USER: YangLiu
|
|
* knife4j 接口文档配置
|
|
* knife4j 接口文档配置
|
|
@@ -33,7 +42,41 @@ public class DocAutoConfigure extends BaseSwaggerConfig {
|
|
@Primary
|
|
@Primary
|
|
@ConditionalOnMissingBean
|
|
@ConditionalOnMissingBean
|
|
public OpenAPI customOpenAPI() {
|
|
public OpenAPI customOpenAPI() {
|
|
- return createOpenAPI(swaggerProperties());
|
|
|
|
|
|
+ OpenAPI openAPI = new OpenAPI()
|
|
|
|
+ .info(new Info()
|
|
|
|
+ .title(properties.getTitle())
|
|
|
|
+ .description(String.format("<div style='font-size:%spx;color:%s;'>%s</div>",
|
|
|
|
+ properties.getDescriptionFontSize(), properties.getDescriptionColor(), properties.getDescription()))
|
|
|
|
+ .version(properties.getVersion())
|
|
|
|
+ .contact(new Contact()
|
|
|
|
+ .name(properties.getName())
|
|
|
|
+ .url(properties.getUrl())
|
|
|
|
+ .email(properties.getEmail()))
|
|
|
|
+ .license(new License()
|
|
|
|
+ .name(properties.getLicense())
|
|
|
|
+ .url(properties.getLicenseUrl()))
|
|
|
|
+ .termsOfService(properties.getTermsOfServiceUrl()));
|
|
|
|
+
|
|
|
|
+ // 只使用 yml 配置的 servers 字段,不设置默认 server
|
|
|
|
+ if (properties.getServers() != null && !properties.getServers().isEmpty()) {
|
|
|
|
+ openAPI.setServers(properties.getServers().stream()
|
|
|
|
+ .map(cfg -> new Server().url(cfg.getUrl()).description(cfg.getDescription()))
|
|
|
|
+ .collect(Collectors.toList()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (properties.isEnableSecurity()) {
|
|
|
|
+ openAPI.addSecurityItem(new SecurityRequirement().addList("Bearer"))
|
|
|
|
+ .components(new Components()
|
|
|
|
+ .addSecuritySchemes("Bearer",
|
|
|
|
+ new SecurityScheme()
|
|
|
|
+ .type(SecurityScheme.Type.HTTP)
|
|
|
|
+ .scheme("bearer")
|
|
|
|
+ .bearerFormat("JWT")
|
|
|
|
+ .in(SecurityScheme.In.HEADER)
|
|
|
|
+ .name("Authorization")));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return openAPI;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|