mirror of
https://github.com/continew-org/continew-starter.git
synced 2026-01-07 00:57:12 +08:00
feat(api-doc): 增加基础枚举处理器支持枚举插件显示
- pom.xml 中添加 nextdoc4j-plugin-enums 依赖 - 在 SpringDocAutoConfiguration 中新增 BaseEnumProcessor Bean - 实现 BaseEnumProcessor 用于 nextdoc4j 枚举插件支持 - BaseEnumProcessor 判断枚举类型并关联 BaseEnum 接口
This commit is contained in:
@@ -28,5 +28,11 @@
|
||||
<artifactId>nextdoc4j-springboot3-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--nextdoc4j - 枚举插件-->
|
||||
<dependency>
|
||||
<groupId>top.nextdoc4j</groupId>
|
||||
<artifactId>nextdoc4j-plugin-enums</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -31,6 +31,7 @@ import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import top.continew.starter.apidoc.processor.BaseEnumProcessor;
|
||||
import top.continew.starter.core.autoconfigure.application.ApplicationProperties;
|
||||
import top.continew.starter.core.util.GeneralPropertySourceFactory;
|
||||
|
||||
@@ -74,6 +75,17 @@ public class SpringDocAutoConfiguration implements WebMvcConfigurer {
|
||||
return openApi;
|
||||
}
|
||||
|
||||
/**
|
||||
* 基础枚举处理器
|
||||
*
|
||||
* @return {@link BaseEnumProcessor }
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public BaseEnumProcessor baseEnumProcessor() {
|
||||
return new BaseEnumProcessor();
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
log.debug("[ContiNew Starter] - Auto Configuration 'ApiDoc' completed initialization.");
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
* <p>
|
||||
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.gnu.org/licenses/lgpl.html
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.continew.starter.apidoc.processor;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
import top.continew.starter.core.enums.BaseEnum;
|
||||
import top.nextdoc4j.enums.resolver.EnumMetadataResolver;
|
||||
|
||||
/**
|
||||
* 基础枚举处理器 - nextdoc4j 枚举插件展示枚举值
|
||||
*
|
||||
* @author echo
|
||||
* @since 2.15.0
|
||||
*/
|
||||
@Component
|
||||
public class BaseEnumProcessor implements EnumMetadataResolver {
|
||||
@Override
|
||||
public boolean supports(Class<?> aClass) {
|
||||
return aClass != null && aClass.isEnum() && ClassUtil.isAssignable(BaseEnum.class, aClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getEnumInterfaceType() {
|
||||
return BaseEnum.class;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user