All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.willingxyz.restdoc.spring.parameter.parser.SpringPathVariableParameterParser Maven / Gradle / Ivy

There is a newer version: 0.2.1.4
Show newest version
package cn.willingxyz.restdoc.spring.parameter.parser;

import cn.willingxyz.restdoc.core.models.ParameterModel;
import cn.willingxyz.restdoc.core.parse.RestDocParseConfig;
import cn.willingxyz.restdoc.core.parse.impl.AbstractMethodParameterParser;
import lombok.var;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.web.bind.annotation.PathVariable;

import java.lang.reflect.Parameter;
import java.lang.reflect.Type;

public class SpringPathVariableParameterParser extends AbstractMethodParameterParser {
    public SpringPathVariableParameterParser(RestDocParseConfig configuration) {
        super(configuration);
    }

    @Override
    protected ParameterModel.ParameterLocation getParameterLocation(Parameter parameter, Type actualParamType) {
        return ParameterModel.ParameterLocation.PATH;
    }

    @Override
    protected boolean isRequired(Parameter parameter, Type actualParamType) {
        return true;
    }

    @Override
    public boolean isSupport(Parameter parameter) {
        return AnnotatedElementUtils.hasAnnotation(parameter, PathVariable.class);
    }

    @Override
    protected String getParameterName(Parameter parameter) {
        var paramName = super.getParameterName(parameter);
        var requestParamAnno = AnnotatedElementUtils.getMergedAnnotation(parameter, PathVariable.class);
        if (requestParamAnno != null)
        {
            return requestParamAnno.name();
        }
        return paramName;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy