From 7cf545bf447dab80f85c472472d45b119188d15e Mon Sep 17 00:00:00 2001 From: clay Date: Mon, 7 Apr 2025 21:16:24 +0800 Subject: [PATCH] build: swagger --- pom.xml | 41 ++++++++++++------- .../java/com/metis/config/SwaggerConfig.java | 31 ++++++++++++++ src/main/resources/application.yml | 28 ++++++++++++- 3 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 src/main/java/com/metis/config/SwaggerConfig.java diff --git a/pom.xml b/pom.xml index 42f8bcd..dbb661b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,6 +8,12 @@ metis 1.0.0-SNAPSHOT + + org.springframework.boot + spring-boot-starter-parent + 3.3.4 + + 17 17 @@ -91,6 +97,16 @@ lombok-mapstruct-binding 0.2.0 + + org.springdoc + springdoc-openapi-starter-webmvc-api + 2.2.0 + + + com.github.xiaoymin + knife4j-openapi3-jakarta-spring-boot-starter + 4.4.0 + @@ -99,7 +115,6 @@ org.springframework.boot spring-boot-maven-plugin - 3.3.4 @@ -107,7 +122,18 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + 17 + 17 + UTF-8 + + -parameters + @@ -129,19 +155,6 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - - 17 - 17 - UTF-8 - - -parameters - - - diff --git a/src/main/java/com/metis/config/SwaggerConfig.java b/src/main/java/com/metis/config/SwaggerConfig.java new file mode 100644 index 0000000..77c541f --- /dev/null +++ b/src/main/java/com/metis/config/SwaggerConfig.java @@ -0,0 +1,31 @@ +package com.metis.config; + +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 org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class SwaggerConfig { + @Bean + public OpenAPI customOpenAPI() { + Contact contact = new Contact(); + contact.setEmail("wlddhj@163.com"); + contact.setName("huangjian"); + contact.setUrl("http://doc.xiaominfo.com"); + return new OpenAPI() + // 增加swagger授权请求头配置 +// .components(new Components().addSecuritySchemes(CommonConstant.X_ACCESS_TOKEN, +// new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme(CommonConstant.X_ACCESS_TOKEN))) + .info(new Info() + .title("Shi9 后台服务API接口文档") + .version("1.0") + .contact(contact) + .description("Knife4j集成springdoc-openapi示例") + .termsOfService("http://doc.xiaominfo.com") + .license(new License().name("Apache 2.0") + .url("http://www.apache.org/licenses/LICENSE-2.0.html"))); + } +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4f78bf9..6a91192 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -28,4 +28,30 @@ mybatis-plus: configuration: map-underscore-to-camel-case: true cache-enabled: false - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl \ No newline at end of file + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl + +springdoc: + swagger-ui: + tags-sorter: alpha + group-configs: + - group: bis + display-name: "业务接口文档" + paths-to-match: '/**' + packages-to-scan: org.shi9.module.bis + - group: system + display-name: "业务接口文档" + paths-to-match: '/**' + packages-to-scan: com.metis.controller + default-flat-param-object: true +knife4j: + # 开启增强配置 + enable: true + # 开启生产环境屏蔽(如果是生产环境,需要把下面配置设置true) + # production: true + setting: + language: zh_cn + swagger-model-name: 实体类列表 + basic: # 开始授权认证 + enable: true + username: admin + password: 123456