parent
25eb223fc4
commit
511785edf0
8 changed files with 162 additions and 95 deletions
@ -0,0 +1,22 @@ |
||||
package cc.bnblogs.swagger_study.config; |
||||
|
||||
import lombok.Data; |
||||
import org.springframework.boot.context.properties.ConfigurationProperties; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
/** |
||||
* @description: |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/5 21:15 |
||||
*/ |
||||
@Data |
||||
@Component |
||||
@ConfigurationProperties(prefix = "doc-info") |
||||
public class DocInfo { |
||||
|
||||
private String title = "SpringBoot集成SpringDoc"; |
||||
private String description = "简单使用入门"; |
||||
private String version = "1.0"; |
||||
private String websiteName = "blog"; |
||||
private String websiteUrl = "https://hugo.bnblogs.cc"; |
||||
} |
@ -0,0 +1,57 @@ |
||||
package cc.bnblogs.swagger_study.config; |
||||
|
||||
|
||||
import io.swagger.v3.oas.models.ExternalDocumentation; |
||||
import io.swagger.v3.oas.models.OpenAPI; |
||||
import io.swagger.v3.oas.models.info.Info; |
||||
import org.springdoc.core.GroupedOpenApi; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
|
||||
|
||||
/** |
||||
* @description: SpringDoc配置 |
||||
* @author: zfp@bnblogs.cc |
||||
* @date: 2023/3/5 20:25 |
||||
*/ |
||||
@Configuration |
||||
public class SpringDocConfig { |
||||
@Autowired |
||||
private DocInfo docInfo; |
||||
@Bean |
||||
public OpenAPI myOpenAPI() { |
||||
return new OpenAPI() |
||||
.info(new Info().title(docInfo.getTitle()) |
||||
.description(docInfo.getDescription()) |
||||
.version(docInfo.getVersion())) |
||||
.externalDocs(new ExternalDocumentation().description(docInfo.getWebsiteName()) |
||||
.url(docInfo.getWebsiteUrl())); |
||||
} |
||||
|
||||
|
||||
@Bean |
||||
public GroupedOpenApi allApi() { |
||||
return GroupedOpenApi.builder() |
||||
.group("all") |
||||
.pathsToMatch("/**") |
||||
.build(); |
||||
} |
||||
|
||||
@Bean |
||||
public GroupedOpenApi DemoApi() { |
||||
return GroupedOpenApi.builder() |
||||
.group("demo") |
||||
.pathsToMatch("/demo/**") |
||||
.build(); |
||||
} |
||||
|
||||
@Bean |
||||
public GroupedOpenApi helloApi() { |
||||
return GroupedOpenApi.builder() |
||||
.group("hello") |
||||
.pathsToMatch("/hello/**") |
||||
.build(); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue