templates.service.SpringDocConfig.ftl Maven / Gradle / Ivy
package ${packageName}.service.config;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ${packageName}.common.constants.Constants;
/**
* SpringDoc API文档相关配置
* Created by macro on 2022/3/4.
*/
@Configuration
public class SpringDocConfig {
private static final String SECURITY_SCHEME_NAME = "Authorization";
@Bean
public OpenAPI mallTinyOpenAPI() {
return new OpenAPI()
.info(new Info().title("榆晟 API")
.description("farm API")
.version("v1.0.0")
.license(new License().name("Apache 2.0").url("https://www.yesaiot.com")))
.externalDocs(new ExternalDocumentation()
.description("Springboot3.0")
.url("https://www.yesaiot.com"))
.addSecurityItem(new SecurityRequirement().addList(SECURITY_SCHEME_NAME))
.components(new Components()
.addSecuritySchemes(SECURITY_SCHEME_NAME,
new SecurityScheme()
.name(SECURITY_SCHEME_NAME)
.type(SecurityScheme.Type.HTTP)
.scheme("bearer")
.bearerFormat("JWT")));
}
@Bean
public GroupedOpenApi partyApi() {
return GroupedOpenApi.builder()
.group("party")
<#if isSpringCloud == 1>
.pathsToMatch("/party/**")
<#else>
.pathsToMatch("api/party/**")
#if>
.packagesToScan("${packageName}.service.party")
.build();
}
<#if projectItemBos?? && (projectItemBos?size > 0)>
<#list projectItemBos as bo>
@Bean
public GroupedOpenApi ${bo.dbName}Api() {
return GroupedOpenApi.builder()
.group("${bo.dbName}")
<#if isSpringCloud == 1>
.pathsToMatch("/${bo.dbName}/**")
<#else>
.pathsToMatch("api/${bo.dbName}/**")
#if>
.packagesToScan("${packageName}.service.${bo.dbName}.controller")
.build();
}
#list>
#if>
}