apache / apache/servicecomb-java-chassis

Java-Chassis生成的契约无法反映hibernate参数校验注解

Open
#3,232 0 comments 0 reactions 0 assignees View on GitHub
Proposal
Dominant language
Java
Stars
1.9k
Forks
814
Avg merge
8d 23h
Merged PRs (30d)
1

Description

## 框架版本

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 注解的支持?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at io.swagger.jackson.ModelResolver#applyBeanValidatorAnnotations and inspect the generated contract for the REST test method's Person body. Compare the existing javax.validation handling with Hibernate @Length and @Range, then verify that the contract exposes the corresponding length and range constraints.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.