pom文件:
- "1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0modelVersion>
-
- <parent>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-parentartifactId>
- <version>2.7.2version>
- <relativePath/>
- parent>
-
- <groupId>com.examplegroupId>
- <artifactId>demoartifactId>
- <version>0.0.1-SNAPSHOTversion>
- <name>2023_demoname>
- <description>2023_demodescription>
-
- <properties>
- <java.version>11java.version>
- properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starterartifactId>
- dependency>
-
- <dependency>
- <groupId>org.projectlombokgroupId>
- <artifactId>lombokartifactId>
- <optional>trueoptional>
- dependency>
-
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-testartifactId>
- <scope>testscope>
- dependency>
-
- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-webartifactId>
- dependency>
-
- <dependency>
- <groupId>org.springdocgroupId>
- <artifactId>springdoc-openapi-uiartifactId>
- <version>1.6.11version>
- dependency>
- <dependency>
- <groupId>com.github.xiaoymingroupId>
- <artifactId>knife4j-springdoc-uiartifactId>
- <version>3.0.3version>
- dependency>
-
-
- dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-maven-pluginartifactId>
- <configuration>
- <excludes>
- <exclude>
- <groupId>org.projectlombokgroupId>
- <artifactId>lombokartifactId>
- exclude>
- excludes>
- configuration>
- plugin>
- plugins>
- build>
-
- <repositories>
- <repository>
- <id>aliyun-repoid>
- <name>aliyunname>
- <url>http://maven.aliyun.com/nexus/content/groups/public/url>
- repository>
- repositories>
-
- project>
yum文件:
- server:
- port: 18080
-
- springdoc:
- swagger-ui:
- enabled: true # 开关
- doc-expansion: none #关闭展开
- api-docs:
- enabled: true # 开关
- package com.example.demo.config;
-
- import io.swagger.v3.oas.annotations.OpenAPIDefinition;
- import io.swagger.v3.oas.annotations.info.Info;
- import io.swagger.v3.oas.models.parameters.Parameter;
- import org.springdoc.core.GroupedOpenApi;
- import org.springdoc.core.customizers.OperationCustomizer;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
-
- /**
- * @description
-
- * @author
- * @since 2023/8/31
- */
- @Configuration
- @OpenAPIDefinition(info = @Info(title = "springDoc + knife 集成测试", version = "1.0",
- description = "swagger基础项目脚手架")
- )
- public class SwaggerConfig {
-
- @Bean
- public GroupedOpenApi usercApi() {
- return GroupedOpenApi.builder()
- .group("用户管理")
- .packagesToScan("com.example.demo.system")
- .pathsToMatch("/**")
- .build();
- }
-
- @Bean
- public GroupedOpenApi biApi(OperationCustomizer operationCustomizer) {
- return GroupedOpenApi.builder()
- .group("报表管理")
- .packagesToScan("com.example.demo.bi")
- .pathsToMatch("/**")
- .addOperationCustomizer(operationCustomizer)
- .build();
- }
-
- @Bean
- public OperationCustomizer operationCustomizer() {
- return (operation, handlerMethod) -> operation.addParametersItem(
- new Parameter()
- .in("header")
- .required(true)
- .description("token 验证")
- .name("token"));
- }
-
- // @Bean
- // public OpenApiCustomiser customerGlobalHeaderOpenApiCustomise() {
- // Parameter passwordParameter = new Parameter().name("password").description("密码").in(ParameterIn.QUERY.toString()).schema(new Schema<>().type("string"));
- // Parameter usernameParameter = new Parameter().name("username").description("用户名").in(ParameterIn.QUERY.toString()).schema(new Schema<>().type("string"));
- // ApiResponse apiResponse = new ApiResponse().content(new Content().addMediaType("*/*", new MediaType()));
- // PathItem pathItem = new PathItem().post(new Operation().summary("登录").tags(CollUtil.newArrayList("system/auth")).description("系统管理/鉴权接口").responses(new ApiResponses()
- // .addApiResponse("default", apiResponse))
- // .parameters(CollUtil.newArrayList(usernameParameter, passwordParameter)));
- // return openApi -> openApi.path("/auth/login", pathItem);
- //
- // }
- }
访问swagger-ui:
访问doc.html: http://localhost:18080/doc.html