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