Repository navigation
Description
Description
In ShenYu 2.7.2, Admin's automatic Swagger document pull assumes that an upstream's registered contextPath is also its backend servlet context path. These can differ: the registered path can be a gateway prefix removed before forwarding, while the backend serves its HTTP endpoints and OpenAPI document at the root.
PullSwaggerDocServiceImpl.getSwaggerRequestUrl unconditionally appends instance.getContextPath() before /v3/api-docs. For an upstream registered with /mcp, Admin therefore requests http://<upstream>:8150/mcp/v3/api-docs, although the document is available at http://<upstream>:8150/v3/api-docs.
Environment
- Apache ShenYu 2.7.2 (based on the
v2.7.2release) - Admin automatic API documentation pulling enabled
- Spring MVC backend with SpringDoc's WebMVC API/UI starter enabled
- No
server.servlet.context-path; default SpringDoc endpoint/v3/api-docs - Registered ShenYu client context path
/mcp
Steps to reproduce
- Start a Spring MVC backend that exposes a valid OpenAPI document at
/v3/api-docs. For the MCP example, ensure the WebMVC SpringDoc starter is present; the common SpringDoc dependency alone does not expose this endpoint. - Register the backend with ShenYu using
contextPath=/mcp, without setting a backend servlet context path. - Confirm that direct GET
/v3/api-docsreturns 200 and direct GET/mcp/v3/api-docsreturns 404. - Enable the Admin API documentation feature and trigger upstream discovery/update so that Admin pulls the document.
- Observe Admin requesting
/mcp/v3/api-docsand loggingadd api document not found.
Expected behavior
Admin should support backends whose registered gateway prefix differs from their actual servlet context path, while preserving support for backends that genuinely expose documentation under that context path.
Actual behavior and impact
Admin always uses the prefixed URL and cannot import the document in this deployment. This does not by itself demonstrate a failure of normal business routing or MCP tool registration.
Proposed compatible fix
- Request
/v3/api-docsat the upstream root first. - Only on HTTP 404, retry the URL prefixed with the registered context path.
- Avoid duplicate requests for an empty/root context path and normalize boundary slashes.
- Do not fall back for authentication errors, server errors, or transport failures.
- Preserve response-body size limits, response closure, refresh state, and document-lock cleanup.
A deployment serving different OpenAPI documents at both locations would select the root document under this policy; an explicit document-path configuration could be considered if that ambiguity needs to be supported.
Candidate fix and verification
A candidate fix against our fork's 2.7.2-release branch is available at vip-pan#1 (not yet an upstream PR).
SwaggerDocManagerImplTest: 11 tests passed, including new cases for root success, 404 fallback, trailing slash normalization, both endpoints returning 404, 401/500 without fallback, and root-path deduplication. Checkstyle and Admin RAT checks passed on JDK 21. Tests were run in a local working tree containing a separate OSHI dependency upgrade; that upgrade is not included in the candidate PR. No full end-to-end Admin deployment test is claimed.
Activity
fix(admin): retry swagger pull at root after context-path 404 (apache…
test(admin): lock prefixed swagger when both urls return 200 (#8512)