You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/09/08 03:40:20 UTC

[GitHub] [servicecomb-java-chassis] five111 opened a new issue #2556: path的参数解析

five111 opened a new issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556


   接口定义如下
   `
       @GetMapping("/getPathParam/{path}")
       public String getPathParam(@PathVariable("path") String[] path){
           return path.toString();
       }
   `
   在spring的体系中 path参数可以传  aaa,bbb 这样 path数组会接收成 {"aaa","bbb"}
   cse解析的时候 无论参数怎么传 都会整体识别为一个字符串 即 path数组会接收成 {"aaa,bbb"}
   


-- 
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



[GitHub] [servicecomb-java-chassis] wujimin commented on issue #2556: path的参数解析

Posted by GitBox <gi...@apache.org>.
wujimin commented on issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556#issuecomment-915344237


   正确的方式是通过collectionFormat声明格式  
   spring的处理是有歧义的,需要是一个数组,那么传递来了`q=a,b,c`,实际应该是一个数组有三个元素,还是一个数组有一个元素呢?  
   只有声明collectionFormat 为csv,才是明确表示一个数组有三个元素
   如果collectionFormat 为multi,这是表示一个数组有一个元素,此时想要表示一个数组有三个元素,应该传递`q=a&q=b&q=c`
   
   扩展机制参考:org.apache.servicecomb.common.rest.codec.query.QueryCodecCsv


-- 
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



[GitHub] [servicecomb-java-chassis] five111 commented on issue #2556: path的参数解析

Posted by GitBox <gi...@apache.org>.
five111 commented on issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556#issuecomment-915128337


   如果当前机制支持的话 很乐意为社区做出一点贡献


-- 
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



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2556: path的参数解析

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556#issuecomment-914892418


   感觉spring体系的语义也是不明确的。 建议业务代码不要将path参数映射为数组, 避免语义差异。 
   定义为数组应该有完整的语义声明,比如query是可以通过 collection format 声明, 而path则没有。 


-- 
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



[GitHub] [servicecomb-java-chassis] five111 commented on issue #2556: path的参数解析

Posted by GitBox <gi...@apache.org>.
five111 commented on issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556#issuecomment-914982267


   spring在处理path参数的时候
   通过HandlerMethodArgumentResolverComposite装载PathVariableMethodArgumentResolver这个类
   对传参类型和目标参数类型进行判断 最后通过StringToArrayConverter 中的convert方法 实现将参数由含“,”的字符串改造成目标的数组
   `
   	@Override
   	@Nullable
   	public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
   		if (source == null) {
   			return null;
   		}
   		String string = (String) source;
                   // 这一步做的转化
   		String[] fields = StringUtils.commaDelimitedListToStringArray(string);
   		TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
   		Assert.state(targetElementType != null, "No target element type");
   		Object target = Array.newInstance(targetElementType.getType(), fields.length);
   		for (int i = 0; i < fields.length; i++) {
   			String sourceElement = fields[i];
   			Object targetElement = this.conversionService.convert(sourceElement.trim(), sourceType, targetElementType);
   			Array.set(target, i, targetElement);
   		}
   		return target;
   	}
   
   }
   `
   servicecomb中有没有类似的机制去处理这些参数?
   我在 swagger-invocation-core中看到了类似的的 Converter的类,例如FileToPartConverter, 是否有可以拓展的机制?


-- 
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



[GitHub] [servicecomb-java-chassis] liubao68 edited a comment on issue #2556: path的参数解析

Posted by GitBox <gi...@apache.org>.
liubao68 edited a comment on issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556#issuecomment-915051661


   应该是可以扩展的。 参考 [query 参数处理的例子](https://github.com/apache/servicecomb-java-chassis/blob/master/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamWithListSchema.java) 以及 [测试代码](https://github.com/apache/servicecomb-java-chassis/blob/master/demo/demo-jaxrs/jaxrs-client/src/main/java/org/apache/servicecomb/demo/jaxrs/client/TestQueryParamWithListSchema.java) 
   
   你可以提供一个PR增加这个特性吗? 
   


-- 
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



[GitHub] [servicecomb-java-chassis] liubao68 commented on issue #2556: path的参数解析

Posted by GitBox <gi...@apache.org>.
liubao68 commented on issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556#issuecomment-915051661


   应该是可以扩展的。 参考 [query 参数处理的例子](https://github.com/apache/servicecomb-java-chassis/blob/master/demo/demo-jaxrs/jaxrs-server/src/main/java/org/apache/servicecomb/demo/jaxrs/server/QueryParamWithListSchema.java). 
   
   你可以提供一个PR增加这个特性吗? 
   


-- 
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



[GitHub] [servicecomb-java-chassis] five111 edited a comment on issue #2556: path的参数解析

Posted by GitBox <gi...@apache.org>.
five111 edited a comment on issue #2556:
URL: https://github.com/apache/servicecomb-java-chassis/issues/2556#issuecomment-914982267


   spring在处理path参数的时候
   通过HandlerMethodArgumentResolverComposite装载PathVariableMethodArgumentResolver这个类
   对传参类型和目标参数类型进行判断 最后通过StringToArrayConverter 中的convert方法 实现将参数由含“,”的字符串改造成目标的数组
   `
   	@Override
   	@Nullable
   	public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
   		if (source == null) {
   			return null;
   		}
   		String string = (String) source;
                   // 这一步做的转化
   		String[] fields = StringUtils.commaDelimitedListToStringArray(string);
   		TypeDescriptor targetElementType = targetType.getElementTypeDescriptor();
   		Assert.state(targetElementType != null, "No target element type");
   		Object target = Array.newInstance(targetElementType.getType(), fields.length);
   		for (int i = 0; i < fields.length; i++) {
   			String sourceElement = fields[i];
   			Object targetElement = this.conversionService.convert(sourceElement.trim(), sourceType, targetElementType);
   			Array.set(target, i, targetElement);
   		}
   		return target;
   	}
   
   }
   `
   servicecomb中有没有类似的机制去处理这些参数,或者说请求在调用过程中 是如何处理这些参数的?
   我在 swagger-invocation-core中看到了类似的的 Converter的类,例如FileToPartConverter, 是否有可以拓展的机制?


-- 
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