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/07/27 09:51:16 UTC

[GitHub] [servicecomb-java-chassis] yhs0092 opened a new issue, #3232: Java-Chassis生成的契约无法反映hibernate参数校验注解

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

   ## 框架版本
   
   Java-Chassis 1.3.7
   
   ## 复现demo
   
   REST 接口方法如下:
   ```java
       @Path("/test")
       @POST
       public Person test(@QueryParam("query") String query, @Valid Person person) {
           person.setName(person.getName() + query);
           return person;
       }
   ```
   
   body参数类型定义如下:
   ```java
   public class Person {
       @Length(min = 4,max = 5) // org.hibernate.validator.constraints.Length
       private String name;
   
       @Range(min = 20,max=30 ) // org.hibernate.validator.constraints.Range
       private int age;
       
       // 省略后面的 getter setter 方法
   }
   ```
   
   启动服务后调用 `test` 接口方法, 确认参数校验的逻辑是生效的.
   但是契约中显示的 `Person` 类型字段信息不会包含参数限制信息.
   
   Swagger 2.0 本身的数据模型是有对参数校验字段的表达的支持的, 参考[Swagger 2.0 文档](https://swagger.io/specification/v2/), 包含 `maximum`/`exclusiveMaximum`/`minimum`/`exclusiveMinimum`/`maxLength`/`minLength`/`pattern` 等元素.
   
   Swagger 本身的工具类已经支持了 `javax.validation` 包中的注解. 但对于 hibernate 的注解则不支持:
   ![image](https://user-images.githubusercontent.com/22049770/181217637-d17e2890-b4b8-44c7-b20c-27274e364477.png)
   
   相关代码逻辑在 `io.swagger.jackson.ModelResolver#applyBeanValidatorAnnotations` 方法中.
   
   请问 Java-Chassis 能否扩展一下, 增加对 hibernate 注解的支持?


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