servicecomb-java-chassis icon indicating copy to clipboard operation
servicecomb-java-chassis copied to clipboard

从CSE 1.X 升级到 CSE 2.X后,接口配置的swagger注解@ApiImplicitParams 参数失效

Open JedrekWang opened this issue 7 months ago • 2 comments

问题背景:

从CSE 1.X 升级到 CSE 2.X后,接口配置的swagger注解@ApiImplicitParams 参数失效 接口定义如下:

@RequestMapping(path = "/v1/test", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParams(value = {
        @ApiImplicitParam(name = "x-test-header", dataType = "string", required = false,
            paramType = "header", value = "xxx",
            allowableValues = "true,false")})
    public String testV1(HttpServletRequest request) {
        return "ok";
    }

使用CSE 1.X时,如果传入的header不是true或者false,报错如下:

{
    "message": "Parameter is not valid for operation [XXX.XXX.testV1]. Parameter is [x-test-header]. Processor is [header]."
}

使用CSE 3.X时,接口无报错

问题分析:

通过对比CSE 1.X和2.X的代码,发现org.apache.servicecomb.common.rest.codec.RestCodec#restToArgs将request请求转发为请求对象的过程中,org.apache.servicecomb.common.rest.definition.RestOperationMeta#init中创建Type的代码进行了调整 从

    Method method = operationMeta.getMethod();
    Type[] genericParamTypes = method.getGenericParameterTypes();

调整为

(Type)operationMeta.getSwaggerProducerOperation().getSwaggerParameterTypes().get(parameter.getName())

导致type丢失了枚举信息

请帮忙确认是否需要跟CSE 1.X保持兼容以及其他类似注解是否有相同问题

JedrekWang avatar Dec 25 '23 02:12 JedrekWang