You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by "JedrekWang (via GitHub)" <gi...@apache.org> on 2023/12/25 02:39:18 UTC

[I] 从CSE 1.X 升级到 CSE 2.X后,接口配置的swagger注解@ApiImplicitParams 参数失效 [servicecomb-java-chassis]

JedrekWang opened a new issue, #4166:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4166

   ### 问题背景:
   从CSE 1.X 升级到 CSE 2.X后,接口配置的swagger注解@ApiImplicitParams 参数失效
   接口定义如下:
   ```java
   @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,报错如下:
   ```json
   {
       "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保持兼容以及其他类似注解是否有相同问题
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] 从CSE 1.X 升级到 CSE 2.X后,接口配置的swagger注解@ApiImplicitParams 参数失效 [servicecomb-java-chassis]

Posted by "liubao68 (via GitHub)" <gi...@apache.org>.
liubao68 commented on issue #4166:
URL: https://github.com/apache/servicecomb-java-chassis/issues/4166#issuecomment-1868714768

   Validation是针对method的, 这个机制是一直未变化的。 
   
   1.x之所有发生了校验, 应该是swagger生成代码导致的, 这个刚刚撞上了。 不应该作为兼容性问题处理。 业务使用的时候,如果需要参数校验,一定需要注意参数校验是针对 method 声明来的,非声明的参数是不会发生校验的。 
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@servicecomb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org