daodao97 / apidog

Api Watch Dog, Hyperf 框架的 Api参数校验 和 swagger 生成组件
MIT License
150 stars 29 forks source link

required的判定 #31

Closed jobinli closed 4 years ago

jobinli commented 4 years ago

https://github.com/daodao97/apidog/blob/32be225c5c3d253cf953a774b3ca59c652d01605/src/Annotation/Param.php#L35-L40

此处的 required 判定是否加上 | 符号比较好?因为像 required_if 之类的规则,会在 swagger-ui 前端就被拦截提交,不好做测试。不知 swagger 是否能实现这种关联检测的判定。

daodao97 commented 4 years ago

确实有这个情况, 可以这样改动下,

 public function setRequire() 
 { 
     $this->required = in_array("required", explode($this->rule, '|')); 

     return $this; 
 } 

仅判断 strpos($this->rule, 'required|') !== false 会在仅有 required 约束时失效

daodao97 commented 4 years ago

已更新在 1.5.8 版本