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

Could you provide a configuration that can disable the automatic generation of random numbers for mock values? #497

Closed
xiaoyao-jimmy opened this issue May 8, 2023 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@xiaoyao-jimmy
Copy link

RT

@xiaoyao-jimmy xiaoyao-jimmy added the enhancement New feature or request label May 8, 2023
@shalousun
Copy link
Collaborator

shalousun commented May 8, 2023

@xiaoyao-jimmy
What impact do random values have? In fact, you can use the @mock tag to specify and override them yourself. The purpose of providing JSON is for those interfacing with the API to immediately understand the structure and type of data to be filled in upon seeing your JSON structure. The example itself is meant to quickly inform about the data formats of inputs and outputs; it's not about starting to use parameters from the documentation right away. Those with some development experience know that most of the values in documentation don't make sense, even if the data is handwritten.
随机值有什么影响吗。其实你可以自己用@mock tag指定覆盖掉。给json的目的是对接接口的人一看你的json结构体和填充的类型就只知道怎么写。example本身就是为了快速知道入参和出参的数据格式,并不是拿着文档里参数就开始用,有一定开发经验的都知道,文档中的值大多数都是搞不通的,即便是手写的数据。

@xiaoyao-jimmy
Copy link
Author

xiaoyao-jimmy commented May 8, 2023

We have conducted secondary platform development. Changes in random numbers can lead the platform to think that the interface has been modified, and in most cases, filling in example parameters with random numbers doesn't serve much purpose. We hope to support leaving them unfilled when not using @mock. Since we are directly using the structure of smart-doc for communication, if configuration is not supported, we can only rewrite the logic for generating random numbers or add customized logic to the platform. Therefore, we hope to leave an opening for this part in smart-doc (ps: in fact, we could force every parameter to include @mock, which could also achieve no change records, but it would not be very user-friendly).
我们进行了二次的平台开发。随机数的变更会导致平台认为接口有变更记录,绝大多数情况下,随机数的example参数填充没有太大的作用,我们希望支持未使用@mock可以不填充。由于直接使用的smart-doc的结构体进行的通信,不支持配置的话,我们只能重写随机数生成这部分逻辑,或者在平台增加定制化逻辑,所以希望在smart-doc里面给这部分留个口子(ps 其实可以强制每个参数都增加@mock,也可以实现没有变更记录,但是会对使用者不太友好)

@shalousun
Copy link
Collaborator

shalousun commented May 8, 2023

You could also submit a pull request (PR). In fact, making basic type judgments would suffice. For instance, after toggling a switch, similar to how integers return 0 and strings return empty, as in the following format, which maintains the integrity of the JSON without affecting the judgment:
你们也可以提pr,其实做好基本类型判断就可以,比如有开关之后,类似整型返回:0,字符串返回空就可以,例如下面这种格式,保留了json的完整性,也不影响判断

{
 "id":0,
"name":"",
}

shalousun added a commit that referenced this issue May 11, 2023
@shalousun shalousun added this to the 2.6.9 milestone May 12, 2023
@shalousun shalousun changed the title 能否提供一个配置,可以关闭mock值随机数自动生成 Could you provide a configuration that can disable the automatic generation of random numbers for mock values? Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants