3

How can I hide the allowEmptyValue description of response type on swagger-ui.html.

springfox version: 2.8.0

springfox-ui version: 2.8.0

screenshot from swagger html

1 Answer 1

2

Maybe a customized property builder plugin can help, try to set allowEmptyValue to null.

import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.introspect.AnnotatedMethod;
import com.fasterxml.jackson.databind.introspect.BeanPropertyDefinition;
import com.google.common.base.Optional;
import io.swagger.annotations.ApiModelProperty;
import springfox.documentation.builders.ModelPropertyBuilder;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.schema.ModelPropertyBuilderPlugin;
import springfox.documentation.spi.schema.contexts.ModelPropertyContext;

@Component
public class CustomizedModelPropertyBuilderPlugin implements ModelPropertyBuilderPlugin {

    @Override
    public boolean supports(final DocumentationType arg0) {
        return true;
    }

    @Override
    public void apply(final ModelPropertyContext context) {
        final ModelPropertyBuilder builder = context.getBuilder();

        final Optional<BeanPropertyDefinition> beanPropDef = context.getBeanPropertyDefinition();

        if (!beanPropDef.isPresent()) {
            return;
        }

        final BeanPropertyDefinition beanDef = beanPropDef.get();
        final AnnotatedMethod method = beanDef.getGetter();
        if (method == null) {
            return;
        }

        final ApiModelProperty apiModelProperty = method.getAnnotation(ApiModelProperty.class);
        if (apiModelProperty == null) {
            return;
        }

        builder.allowEmptyValue(null);
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Some update, it works! beanPropDef.get(); it is a guava optional. Check if it is present first!
I used to get this error in the old spring-fox version 2.8.2, when I upgraded to 2.9.2 version, I am not seeing this text (allowedEmptyValue=false) anymore :). I didn't do any other config changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.