TongchengOpenSource / smart-doc

Smart-doc is a java restful api document generation tool. Smart-doc is based on interface source code analysis to generate interface documentation, completely zero-injection.
https://smart-doc-group.github.io/#/
Apache License 2.0
1.41k stars 277 forks source link

Currently, the parameters are generated by traversing fields. Is it possible to change this to generate them by traversing set methods instead? #510

Open LeeMeo opened 1 year ago

LeeMeo commented 1 year ago

Your Environment(您的使用环境)

Expected Behavior(您期望的结果)

The parameters should be: aName, aCode, bName, bCode. 入参应该是:aName, aCode, bName, bCode

Current Behavior(当前结果)

The current result's parameters are: testA.aName, testA.aCode, testB.bName, testB.bCode. 当前结果的入参是:testA.aName, testA.aCode, testB.bName, testB.bCode image

Possible Solution(bug解决建议)

In Spring MVC, parameter assignment actually calls the set method, not directly setting the field's value. However, Smart-Doc generates documentation by traversing the fields of the parameters, which is inconsistent with how it actually runs.

spring mvc 的入参赋值,其实是调用的set方法,并不是直接设置field的值,而smart-doc则是遍历入参的field并生成文档,这与实际运行情况不符。

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

eg: image image

Context(Bug影响描述)

shalousun commented 1 year ago

@LeeMeo This has nothing to do with Spring MVC. The native Java parsing is correct. Your approach mainly uses Lombok's @Delegate for forced delegation, which modifies the code during compilation. Smart-Doc currently does not support these kinds of changes made by Lombok to the source code. The community hasn't had the capacity to work on this recently. If you're interested, you could submit a PR to enhance it. 这个和springmvc没什么关系,原生java写法这样解析是对的,你们这个主要是用了lombok的@delegate强制委派,代码编译的时候被修改了,smart-doc目前是不支持lombok这些对源代码的改变的。社区最近没有精力搞,有兴趣可以提pr增强下

LeeMeo commented 1 year ago

@shalousun It's not about using or not using Lombok; the result is the same even without Lombok. The example code is as follows: image Spring MVC automatically sets parameters through set methods, which is slightly different from the way Smart-Doc does it.

This has been verified; actually, there are two request methods that can be used, for example:

http://localhost:8080/testConstants2?testA.aName=a
http://localhost:8080/testConstants2?aName=a

If you're interested, you can submit a PR to support the second method. It's rare not to use delegation when writing set methods separately, and currently, JSON is the mainstream for parameter input.