feat(api-doc): support request parameter parsing for RPC types (Dubbo/SOFA/TARS/gRPC)#6339
feat(api-doc): support request parameter parsing for RPC types (Dubbo/SOFA/TARS/gRPC)#6339eye-gu wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends ShenYu’s API document generation so RPC-style services (Dubbo/SOFA/TARS/gRPC, including Dubbo protobuf) can produce request parameter schemas in generated API docs, and it aligns document field naming across protocols.
Changes:
- Add RPC-aware document generation in
OpenApiUtils(RPC + gRPC request parsing, RPC-specific response generation, protobuf message field reflection). - Route API doc registrars/listeners to the new unified
requestParameters/responseParametersdocument structure. - Add/adjust tests and example annotations; update build/checkstyle config to support generated protobuf test sources.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/utils/OpenApiUtils.java | Adds RPC/gRPC/protobuf-aware doc building and unifies document fields |
| shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImpl.java | Switches document generation to RPC-type dispatch via OpenApiUtils.buildDocumentJson |
| shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/AbstractApiDocRegistrar.java | Uses new unified document builder for generated docs |
| shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/client/AbstractContextRefreshedEventListener.java | Threads RPC type into doc generation for annotation-based docs |
| shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java | Refactors SOFA listener into the shared refreshed-event flow to enable API doc pipeline |
| shenyu-client/shenyu-client-sofa/src/test/java/org/apache/shenyu/client/sofa/SofaServiceEventListenerTest.java | Updates test to align with the new path-building flow |
| shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/utils/OpenApiUtilsTest.java | Adds extensive unit coverage for RPC/gRPC/protobuf parsing and dispatch |
| shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/registrar/NoHttpApiDocRegistrarTest.java | Adds coverage that RPC/gRPC docs include request/response parameter fields |
| shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImplTest.java | Validates registrar document output uses unified field names across RPC types |
| shenyu-client/shenyu-client-core/src/test/proto/test.proto | Adds proto used by protobuf reflection tests |
| shenyu-client/shenyu-client-core/pom.xml | Adds test-only protobuf/grpc deps and proto generation for tests |
| shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ApiServiceImpl.java | Parses doc JSON when present (not only SWAGGER source) to populate request/response parameter lists |
| shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ApiServiceTest.java | Adds coverage for findById behavior with blank/non-blank document |
| shenyu-examples/.../DubboProtobufServiceImpl.java (3 files) | Adds @ApiModule/@ApiDoc annotations to protobuf Dubbo examples |
| pom.xml | Excludes generated sources from checkstyle to accommodate generated protobuf test code |
Comments suppressed due to low confidence (1)
shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/utils/OpenApiUtils.java:135
generateRequestDocParameterscurrently parses either query parameters (when any@RequestParam/@RequestPartis present) or path template variables, but not both due to theif (...) { ... } else { ... }structure. This will drop{var}path parameters for endpoints that also have query params. Consider always parsing path segments and then merging/deduplicating with any query-derived parameters.
List<Parameter> list = new ArrayList<>();
Pair<Boolean, Annotation[][]> query = isQuery(method);
if (query.getLeft()) {
for (Annotation[] annotations : query.getRight()) {
if (annotations.length > 0 && isQueryName(annotations[0].annotationType().getName(), QUERY_CLASSES)) {
for (Annotation annotation : annotations) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| apiVO.setResponseParameters(docItem.getResponseParameters()); | ||
| apiVO.setBizCustomCodeList(docItem.getBizCodeList()); | ||
| } | ||
| } |
There was a problem hiding this comment.
@moremind I think when document is blank or docItem is null, it means the API has no document data, so the page simply won't display any API Doc content — which is the expected behavior. The null checks (StringUtils.isNotBlank + Objects.nonNull) added in this PR already make the code safer than before. No additional else branch is needed here.
close #6338
Previously, API document generation only supported Spring Web annotation-based parameter parsing (
@RequestParam,@RequestPart, path variables), which only works for HTTP/WebSocket/Spring Cloud. RPC types (Dubbo, SOFA, TARS, gRPC) had no request parameter information in generated documents.Changes
OpenApiUtils - RPC-aware document generation
buildDocumentJson()that dispatches by RPC type:StreamObservermethod patternrequestParameters/responseParametersSOFA - enable API document support
SofaServiceEventListenerto extendAbstractContextRefreshedEventListenercommon flowhandler()/onApplicationEvent()with standardgetCorrectedClass()+buildApiPath()hooksExamples
@ApiModule/@ApiDocannotations to Dubbo protobuf example servicesImpact
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.