Aias00 opened a new issue, #7587:
URL: https://github.com/apache/shenyu/issues/7587

   ## Summary
   
   `GET /apidoc/getDocMenus` (admin UI "API document" menu) **always returns an 
empty list**, even after API documents have been successfully registered.
   
   `DocManagerImpl.DOC_DEFINITION_MAP` is a `static final HashMap` that is 
**never written to** — the class contains exactly two references to it: the 
declaration and `listAll()`. There is no `put` anywhere in the class or the 
repository.
   
   ## Evidence
   
   
`shenyu-admin/src/main/java/org/apache/shenyu/admin/service/manager/impl/DocManagerImpl.java`
   
   ```java
   71:    private static final Map<String, DocInfo> DOC_DEFINITION_MAP = new 
HashMap<>();
   182:        return DOC_DEFINITION_MAP.values();
   ```
   
   `git grep -n "DOC_DEFINITION_MAP" HEAD` returns only those two lines — the 
map is dead state.
   
   
`shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ApiDocController.java:62`
   
   ```java
   Collection<DocInfo> docInfos = docManager.listAll();
   ```
   
   so the controller always builds an empty `menuProjectList`.
   
   `addDocInfo(...)` (line 85) does the real work — it parses the Swagger JSON, 
computes the md5, and persists each item through 
`registerApiDocService.registerApiDocument(build)` — but never records anything 
in `DOC_DEFINITION_MAP`. The `callback.accept(docInfo)` at the end is the only 
remaining consumer of the parsed `DocInfo`.
   
   ## Root cause
   
   Commit `327bf65c` — *"[ISSUE #4848] Storage adjustment for swagger type API 
documents: change from local cache to database. (#4849)"* (2023-07-18) 
intentionally moved API-doc storage from the in-memory cache to the database, 
but left the cache field and `listAll()` reading from it.
   
   ## Impact
   
   - The admin "API document" menu is permanently empty; users cannot browse 
aggregated Swagger docs.
   - Any code that treats `listAll()` as the source of truth for registered 
docs is silently wrong.
   
   ## Suggested fix
   
   Pick one of:
   
   1. **Read from the database.** Make `listAll()` query the persisted API 
documents (the same store `registerApiDocService.registerApiDocument` writes 
to) and rebuild `DocInfo`/`DocModule` from it. This matches the intent of #4849.
   2. **Restore the cache.** Have `addDocInfo()` also 
`DOC_DEFINITION_MAP.put(docInfo.getTitle(), docInfo)` (and remove stale entries 
on upstream removal), and switch the map to `ConcurrentHashMap` since 
`addDocInfo` is reached from discovery/data-change threads while `listAll()` 
runs on an HTTP request thread.
   
   Either way, please delete the dead field if option 1 is chosen, and add a 
regression test asserting that a registered doc appears in `listAll()`.
   
   ## Environment
   
   - Branch: `master` @ `a7d80b7`
   - Affected since: 2.6.0 (#4849), still present on master
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to