Skip to content

[BUG] Admin Swagger pull assumes registered contextPath is the backend servlet path #8410

Closed

Description

@vip-pan

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.2 release)
  • 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

  1. 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.
  2. Register the backend with ShenYu using contextPath=/mcp, without setting a backend servlet context path.
  3. Confirm that direct GET /v3/api-docs returns 200 and direct GET /mcp/v3/api-docs returns 404.
  4. Enable the Admin API documentation feature and trigger upstream discovery/update so that Admin pulls the document.
  5. Observe Admin requesting /mcp/v3/api-docs and logging add 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-docs at 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

  1. added a commit that references this issue on Nov 17, 2026
    1ef9eb9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions