mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-09-17 10:56:39 +08:00
更新枚举类swagger注解ApiModelPropertyEnum -增加是否隐藏属性hidden默认展示
This commit is contained in:
parent
3e95e29b15
commit
68015d3e7f
@ -26,6 +26,18 @@ public @interface ApiModelPropertyEnum {
|
|||||||
|
|
||||||
String example() default "";
|
String example() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否隐藏
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
boolean hidden() default false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否必须
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
boolean required() default true;
|
boolean required() default true;
|
||||||
|
|
||||||
String dataType() default "";
|
String dataType() default "";
|
||||||
|
@ -45,22 +45,23 @@ public class SmartSwaggerApiModelEnumPlugin implements ModelPropertyBuilderPlugi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(ModelPropertyContext context) {
|
public void apply(ModelPropertyContext context) {
|
||||||
Optional<ApiModelPropertyEnum> annotation = Optional.absent();
|
Optional<ApiModelPropertyEnum> enumOptional = Optional.absent();
|
||||||
|
|
||||||
if (context.getAnnotatedElement().isPresent()) {
|
if (context.getAnnotatedElement().isPresent()) {
|
||||||
annotation = annotation.or(findApiModePropertyAnnotation(context.getAnnotatedElement().get()));
|
enumOptional = enumOptional.or(findApiModePropertyAnnotation(context.getAnnotatedElement().get()));
|
||||||
}
|
}
|
||||||
if (context.getBeanPropertyDefinition().isPresent()) {
|
if (context.getBeanPropertyDefinition().isPresent()) {
|
||||||
annotation = annotation.or(findPropertyAnnotation(context.getBeanPropertyDefinition().get(), ApiModelPropertyEnum.class));
|
enumOptional = enumOptional.or(findPropertyAnnotation(context.getBeanPropertyDefinition().get(), ApiModelPropertyEnum.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (annotation.isPresent()) {
|
if (enumOptional.isPresent()) {
|
||||||
Class<? extends BaseEnum> aClass = annotation.get().value();
|
ApiModelPropertyEnum anEnum = enumOptional.get();
|
||||||
String enumInfo = BaseEnum.getInfo(aClass);
|
String enumInfo = BaseEnum.getInfo(anEnum.value());
|
||||||
String enumDesc = annotation.get().enumDesc();
|
context.getBuilder()
|
||||||
context.getBuilder().required(annotation.transform(toIsRequired()).or(false))
|
.required(enumOptional.transform(toIsRequired()).or(false))
|
||||||
.description(enumDesc +":"+enumInfo)
|
.description(anEnum.enumDesc() + ":" + enumInfo)
|
||||||
.example(annotation.transform(toExample()).orNull());
|
.example(enumOptional.transform(toExample()).orNull())
|
||||||
|
.isHidden(anEnum.hidden());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user