Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The parameters in the POST request body include attributes declared with the @Null annotation. #608

Closed
129duckflew opened this issue Sep 16, 2023 · 5 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@129duckflew
Copy link

129duckflew commented Sep 16, 2023

Your Environment(您的使用环境)

  • smart-doc version: 2.7.7
       <plugin>
            <groupId>com.github.shalousun</groupId>
            <artifactId>smart-doc-maven-plugin</artifactId>
            <version>2.7.7</version>
            <configuration>
              <!--指定生成文档的使用的配置文件-->
              <configFile>${basedir}/src/main/resources/smart-doc.json</configFile>
              <!--指定项目名称-->
              <projectName>rms</projectName>
            </configuration>
            <executions>
              <execution>
                <phase>compile</phase>
                <goals>
                  <goal>html</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
  • plugin version (e.g. smart-doc-maven-plugin or smart-doc-gradle-plugin): 2.7.7
  • build tool version(maven or gradle): maven:3.6.3
  • JDK17 SpringBoot: 2.5.3

Expected Behavior(您期望的结果)

It is desired that the generated HTML documentation does not include parameters in the POST request body that are declared with the @null annotation.
希望生成的HTML文档中,POST请求体中的参数不包含被@null注解声明的属性

Current Behavior(当前结果)

Even when using the @null annotation on the request parameter's attributes, the parameters still appear in the generated HTTP interface request body.
即使用@null注解注明在请求参数的属性上,生成的Http接口请求体重仍然出现参数

Possible Solution(bug解决建议)

Steps to Reproduce (Bug产生步骤,请尽量提供用例代码)

  1. RequestBody:
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ReportParamVo {

  /**
   * 统计的日志类型
   */
  @Null(message = "不允许指定runningLogType")
  private Integer runningLogType;
  /**
   * 电梯类型
   * @mock 0
   */
  @Max(value = 2,message = "elevatorType参数不合法")
  @Min(value = 0,message = "elevatorType参数不合法")
  private Integer elevatorType;
  /**
   * 时间维度,支持年月日,如果按照日期分组,那么本字段不能为空|1
   * 1->YEAR,2->MONTH 3->DAY
   */
  @Max(value = 3,message = "timeUnits参数不合法")
  @Min(value = 1,message = "timeUnits参数不合法")
  private Integer timeUnits;
  /**
   * 统计的楼层,如果按楼层分组,那么这个字段不能指定
   * @mock 1
   */
  private Integer floor;
  /**
   * 统计开始时间
   */
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
  private Date calStartTime;
  /**
   * 统计结束时间
   */
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai")
  private Date calEndTime;
  /**
   * 设备的id,如果按照id分组,则不能指定unitsId
   */
  private Integer unitsId;

  /**
   * 分组条件,1->根据时间单位分组,2->根据楼层分组,3->根据电梯id进行分组,4->按照方向进行分组
   * 如果是1,则需要指定timeUnits
   */
  @NotNull(message = "分组条件不能为空")
  @Max(value = 4,message = "groupBy参数不合法,value:1~4")
  @Min(value = 1,message = "groupBy参数不合法,value:1~4")
  private Integer groupBy;


  @Null(message = "私有字段,不允许指定")
  private Integer reportDataType;

  /**
   * 呼梯方向,仅针对厅层呼梯相关的统计有效
   */
  private Boolean callUp;
}
  1. Http API
     /**
      * 平均电梯起止时间
      * @return
      */
     @PostMapping("/avg/car_call")
     public CommonResult<List<EChartsData>> carCallAvgTime(
             @RequestBody @Validated ReportParamVo reportParamVo
     )
     {
         reportParamVo.setRunningLogType(RunningLogType.CAR_CALL.getValue());
         paramPreHandle(reportParamVo);
         reportParamVo.setReportDataType(ReportDataType.AVG_TIME.getValue());
         List<EChartsData> res = reportService.selectReport(reportParamVo);
         return CommonResult.success(res,"query success");
     }
  2. EchatsData
@Data
@NoArgsConstructor
@AllArgsConstructor
public class EChartsData {
    private String groupCondition;
    private Long data;
}
  1. Common return class
import lombok.Data;
@Data
public class CommonResult <T>{
    /**
     * 状态码
     */
    private Integer  code;
    /**
     * 消息
     */
    private String msg;
    /**
     * 响应状态
     */
    private String status;
    /**
     * 数据
     */
    private T data;

    // 构造方法、getter 和 setter 省略

    // 静态方法,返回成功结果
    public static <T> CommonResult<T> success(T data) {
        CommonResult<T> response = new CommonResult<>();
        response.setCode(200);
        response.setData(data);
        response.setStatus("ok");
        return response;
    }
    public static <T> CommonResult<T> success(T data,String message) {
        CommonResult<T> res = CommonResult.success(data);
        res.setMsg(message);
        return res;
    }

    // 静态方法,返回失败结果
    public static <T> CommonResult<T> error(int code ,String message) {
        CommonResult<T> response = new CommonResult<>();
        response.setCode(code);
        response.setMsg(message);
        response.setStatus("error");
        return response;
    }
}
  1. smart-doc.json
{
  "outPath": "src/main/resources/static/doc",
  "allInOne": true,
  "serverUrl": "http://127.0.0.1:8090",
  "createDebugPage": true,
  "style": "xt256",
  "requestHeaders": [{
    "name": "satoken",
    "type": "string",
    "desc": "登录返回的Token",
    "value":"fb01175a9e004f778a8dc5c610cc35c9",
    "required": true,
    "pathPatterns": "/**",
    "excludePathPatterns":"/login"
  }]
}

Context(Bug影响描述)

When generating documentation for online access using the following commands
利用如下命令生成文档在线访问时

mvn install -DskipTests

Generate the following interface documentation:

The attributes circled in the red box were not ignored.

@129duckflew 129duckflew added the bug Something isn't working label Sep 16, 2023
@abing22333
Copy link
Contributor

abing22333 commented Sep 17, 2023

@null Annotations don't have the semantics to hide fields, do they? @129duckflew @shalousun

@129duckflew
Copy link
Author

129duckflew commented Sep 17, 2023

@null Annotations don't have the semantics to hide fields, do they? @129duckflew @shalousun

They should have this feature; I've always used it that way before.

@abing22333
Copy link
Contributor

abing22333 commented Sep 17, 2023

@null Annotations don't have the semantics to hide fields, do they? @129duckflew @shalousun

They should have this feature; I've always used it that way before.

Which version is it compatible with?

@129duckflew
Copy link
Author

129duckflew commented Sep 17, 2023

@null Annotations don't have the semantics to hide fields, do they? @129duckflew @shalousun

They should have this feature; I've always used it that way before.

Which version is it compatible with?

2.7.0

@shalousun
Copy link
Collaborator

shalousun commented Sep 17, 2023

@null Annotations don't have the semantics to hide fields, do they? @129duckflew @shalousun

Previous versions should have used the @null annotation to not display afterwards.

@shalousun shalousun self-assigned this Oct 13, 2023
@shalousun shalousun added this to the 3.0.0 milestone Oct 13, 2023
Fioooooooo pushed a commit to Fioooooooo/smart-doc that referenced this issue Nov 14, 2023
@shalousun shalousun changed the title POST请求体中的参数包含了被@Null注解声明的属性 The parameters in the POST request body include attributes declared with the @Null annotation. May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants