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

[v4.5.0]Get/Delete参数是否可以默认勾选,如图所示 #742

Open
805728578 opened this issue Feb 27, 2024 · 14 comments
Open

[v4.5.0]Get/Delete参数是否可以默认勾选,如图所示 #742

805728578 opened this issue Feb 27, 2024 · 14 comments

Comments

@805728578
Copy link

805728578 commented Feb 27, 2024

Describe the bug
A clear and concise description of what the bug is.
image

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.
image

Screenshots
If applicable, add screenshots to help explain your problem.
image

Knife4j Version (please complete the following information):
v4.5.0
Additional context
Add any other context about the problem here.

@xiaoymin
Copy link
Owner

参数配置require=true 就勾选了

@805728578
Copy link
Author

@xiaoymin 在哪里配置,properties文件里面配吗?

@xiaoymin
Copy link
Owner

对于form请求,用OpenAPI3规范的注解,标注require

例如:

@Parameter(name = "id", description = "主键id", required = true, in = ParameterIn.QUERY)
@GetMapping("/getById")
public Result<List<String>> getById(@RequestParam(value = "id") Integer id) {
      //...
}

@805728578
Copy link
Author

@xiaoymin 能否优化一下,默认勾选啊。如果参数特别多,配置太麻烦了

@xiaoymin
Copy link
Owner

@xiaoymin 能否优化一下,默认勾选啊。如果参数特别多,配置太麻烦了

ui解析是根据规范来的,如果required设置为true,默认就是勾选的,为false,就代表可传可不传。不勾选是合理的

@805728578
Copy link
Author

805728578 commented Feb 27, 2024

image

image

@805728578
Copy link
Author

@xiaoymin 实际上我是以对象方式呈现的,而且原生/swagger-ui/index.html是支持的

@xiaoymin
Copy link
Owner

@805728578

@Schema注解,有设置requiredMode属性的

@805728578
Copy link
Author

@xiaoymin 感觉和这个勾选含义和requiredMode含义不同,勾选是为了表达向后端传递不传递这个参数,requiredMode是为了表达是否必须包含内容片段

举个例子:后端需要接收字段参数其值可以为null,和后端接收不到参数是两个概念

@xiaoymin
Copy link
Owner

xiaoymin commented Feb 28, 2024

@xiaoymin 感觉和这个勾选含义和requiredMode含义不同,勾选是为了表达向后端传递不传递这个参数,requiredMode是为了表达是否必须包含内容片段

举个例子:后端需要接收字段参数其值可以为null,和后端接收不到参数是两个概念

前端组件交互没有null和空字符的概念,如果body不含参数,就是null,勾选了,传递一个空字符串,也是有值的

默认全部勾选,然后传递一个空字符串过去,后端JSR303验证就会不通过。所以这里和require这个属性绑定,我觉得还是合理的

@805728578
Copy link
Author

@xiaoymin 就是操作起来比较繁琐,如果【参数】是非必须字段,【参数值】填完之后还要打勾才能提交给后端

同一套代码,使用原生/swagger-ui/index.html和/doc.html操作完全不一致。

个人觉得【参数】前面的复选框都可以去掉,保持【参数值】对应文本框或下拉框和requiredMode配置保持一致

@xiaoymin
Copy link
Owner

@805728578 非必填字段没有你说的填完之后还要打勾这个操作吧

如果是非必填,但是在输入框输入的时候,就会默认打勾了

https://doc.xiaominfo.com/demo/doc.html#/Knife4j%E7%A4%BA%E4%BE%8B/%E7%94%A8%E6%88%B7%E6%A8%A1%E5%9D%97/createOne1

@805728578
Copy link
Author

image
image

@xiaoymin 针对以上情况,有默认样例值就要打勾

@805728578
Copy link
Author

805728578 commented Feb 28, 2024

@805728578 非必填字段没有你说的填完之后还要打勾这个操作吧

如果是非必填,但是在输入框输入的时候,就会默认打勾了

https://doc.xiaominfo.com/demo/doc.html#/Knife4j%E7%A4%BA%E4%BE%8B/%E7%94%A8%E6%88%B7%E6%A8%A1%E5%9D%97/createOne1

@xiaoymin 针对没有默认值的确实输入时就勾选了,针对有默认值的需要二次勾选

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants