mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #6411] [Question]: should an empty allLinks response return an empty array or null? #4342
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4342
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @LineGM on GitHub (Sep 4, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6411
What are you trying to do?
I am trying to clarify the intended response contract of:
GET /panel/api/inbounds/allLinksWhen no links are available, should a successful response contain
"obj": nullor"obj": []?A consistent array response would be easier for generated SDKs and strictly typed API clients. However, changing
nullto[]would technically alter the existing wire response for the empty case, so I would like to confirm the intended behavior first.If
[]is preferred, I am happy to prepare a small PR with the implementation, regression tests, and an explicit OpenAPIstring[]response schema.What have you already tried?
mainbranch after #6409.getAllInboundLinks,GetAllInboundLinks, andLinksForInbounds.LinksForInboundscurrently starts with a nil Go slice, so an empty successful result is serialized asnull.objis currently unconstrained.3x-ui version
main @
ed6bc1dHow did you install 3x-ui?
Manual build from source
Operating system
No response
Screenshots or config snippets
Relevant implementation:
https://github.com/MHSanaei/3x-ui/blob/main/internal/sub/links.go#L44-L50
Before submitting
@github-actions[bot] commented on GitHub (Sep 4, 2026):
Your trace is correct, and the
nullyou observed is not specific toallLinks— it is the panel-wide envelope behaviour, so the answer is that the current wire shape is intended and should staynull. The gap actually worth closing is the one you named second: the unconstrained OpenAPI schema forobj. The repo already has an established pattern for exactly that case.Why
nullis the envelope's behaviour, not anallLinksquirkobjisanywith noomitempty, so it is always present and always nullable:Every error response already emits
"obj": null—jsonMsgpasses a nil object unconditionally (internal/web/controller/util.go:121-123):So a strictly typed client already has to tolerate
obj: nullon/panel/api/inbounds/allLinksregardless of what the success path does.And the nil-slice-in,
null-out shape is uniform across list endpoints, not an oversight in one:internal/sub/links.go:46—var out []string(the line you quoted)internal/sub/service.go:376—return nilon the client-fetch error, and:381var out []stringinternal/web/service/inbound.go:168—var inbounds []*model.Inbound, soGET /panel/api/inbounds/listreturns"obj": nullfor a user with zero inboundsinternal/logger/logger.go:221—var output []string, soPOST /panel/api/server/logs/:countreturnsnullwhen nothing in the buffer matches the levelChanging
LinksForInboundsalone tomake([]string, 0)would makeallLinksthe single endpoint in the API that behaves differently, without removing theobj: nullcase a generated SDK has to handle anyway. The only in-tree consumer already defends against it (frontend/src/pages/inbounds/InboundsPage.tsx:398):For the record, the empty case is reachable: no inbounds, inbounds with no clients, or only protocols with no URL form (socks/http/mixed/wireguard/dokodemo/tunnel).
The schema, which is the part that is genuinely missing
frontend/scripts/build-openapi.mjs:234supports a raw schema forobj:and both halves of what you need are already used in-tree. A plain string array —
frontend/src/pages/api-docs/endpoints.ts:712:and
nullable: truefor arrays that are Go nil slices at runtime —frontend/src/pages/api-docs/websocket-events.ts:95and:129:Those two combined describe
allLinksaccurately without touching the wire:Two things to fold into such a PR:
POST /panel/api/server/logs/:counthas the same mismatch — it is documented as a non-nullablestring[]atendpoints.ts:712, butlogger.GetLogs(internal/logger/logger.go:221) returns a nil slice when nothing matches. Its schema is pinned bytoEqualinfrontend/src/test/openapi-runtime-contracts.test.ts:131-134, so addingnullable: truethere means updating that assertion too.CLAUDE.md's fourth route-contract step still applies:make gen, then copyfrontend/public/openapi.json→docs/public/openapi.jsonand runcd docs && pnpm gen:api, sincedocs-ci.ymlfires only ondocs/**.I could not find any commit, comment or test that states a deliberate nil-vs-empty policy either way —
git logoninternal/sub/links.goshows only439245d4,709b332dand41645255, none of which touch the empty case. What I can point at is that your own #6409 (ed6bc1d8) changed response types only in wire-preserving ways (map[string]any→ typed structs with identical JSON keys, plusexample:tags) and left every empty-collection serialization alone. The final call on whether anil→[]runtime change is wanted is the maintainer's; I am leaving this open for that, since the docs-only change stands on its own either way.Verdict: Not a bug (expected behaviour)
This reply was generated automatically; a maintainer may follow up.