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 2022/01/13 09:36:15 UTC

[GitHub] [servicecomb-java-chassis] yhs0092 opened a new issue #2694: 同一个REST接口类中存在两个类名相同包名不同的参数, Java-Chassis生成的契约中只有一个类型的definition信息

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


   ## 问题场景
   
   同一个REST接口类中有类名相同而包名不同的两个参数类型, 生成的契约在`definitions`字段里只会呈现其中一个类的信息.
   
   根因`Swagger`对象的`definitions`参数是一个`LinkedHashMap`类型. 而对于 Java 对象类型的参数, Java-Chassis是依赖Swagger的工具类生成`io.swagger.models.ModelImpl`模型信息的, 根据`ModelImpl#getName`作为key保存到`definitions` map中. 这里的`ModelImpl#getName`默认返回的是参数类型的简单类名, 因此同名不同包的类在这个`definitions` map中相互覆盖, 最终只有一个类型的信息留在 `definitions` 里面.
   
   ## 规避手段
   
   在参数类型信息上可以打上`io.swagger.annotations.ApiModel`注解, 如
   ```java
   @ApiModel(value = "personAnother")
   public class Person {
     // ...
   }
   ```
   可以覆盖`ModelImpl#getName`的返回值, 让`definitions`中的类型信息区分开来.
   但不足之处在于, 一方面此问题比较隐晦, 启动阶段不会报错, 在运行时出了问题业务才能察觉. 二来对业务的代码有一定的要求, 如果参数类型来自一个公共包, 可能业务无法在上面打注解.
   
   ## 建议和诉求
   
   最好的结果是 Java-Chassis 优化一下契约生成逻辑, 用全限定类名之类的做`io.swagger.models.Swagger#definitions` 的 key.
   如果实在做不到, 最好也要实现一个查重逻辑, 一旦遇到这种问题场景立即报错, 让业务感知, 不能带病上线.


-- 
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] yhs0092 commented on issue #2694: 同一个REST接口类中存在两个类名相同包名不同的参数, Java-Chassis生成的契约中只有一个类型的definition信息

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


   Java-Chassis 1.5.0 分支麻烦也带一下这个优化项, 多谢了~


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