Make API OPTIONS report actual controller capabilities - #4645
Open
ammad-elev8ai wants to merge 2 commits into
Open
ammad-elev8ai wants to merge 2 commits into
ammad-elev8ai wants to merge 2 commits into
Conversation
The root/tools OPTIONS response listed a hand-maintained, static set of controllers that had already drifted from what's actually routable: "customers" was a fully working tools sub-resource (Tools_controller::define_tools_controllers()) but missing from the list, and the "circuits" controller wasn't listed at all. Generate the tools/* portion of the list from the real subcontroller registry instead of a hand-written array, so it can't drift again, and add the top-level "circuits" entry.
Small follow-up now that the CircuitsLogical controller exists (see the feature/api-circuitslogical-controller branch/PR). This commit has a soft dependency on that one landing - the href is just documentation, so merging this first won't break anything, but the entry won't be genuinely accurate until both are in.
This was referenced Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #4642 (context/overview for a set of 4 related API fixes).
Gap
OPTIONS /api/{app_id}/is supposed to describe what the API supports, but thecontrollerslist is missing entries for functionality that's fully working androutable - most notably
customers(a workingtools/sub-resource) andcircuits(aworking top-level controller):
{ "code": 200, "success": true, "data": { "permissions": "Write", "controllers": [ {"rel": "sections", "href": "/api/my_app/sections/"}, {"rel": "subnets", "href": "/api/my_app/subnets/"}, {"rel": "folders", "href": "/api/my_app/folders/"}, {"rel": "addresses", "href": "/api/my_app/addresses/"}, {"rel": "vlans", "href": "/api/my_app/vlan/"}, {"rel": "vrfs", "href": "/api/my_app/vrf/"}, {"rel": "nameservers", "href": "/api/my_app/tools/nameservers/"}, {"rel": "scanAgents", "href": "/api/my_app/tools/scanagents/"}, {"rel": "locations", "href": "/api/my_app/tools/locations/"}, {"rel": "racks", "href": "/api/my_app/tools/racks/"}, {"rel": "nat", "href": "/api/my_app/tools/nat/"}, {"rel": "tools", "href": "/api/my_app/tools/"} ] } }No
customers, nocircuits- despite both being usable today. This ambiguity is alsovisible in #4560, where a user couldn't tell circuits had a controller at all.
Root cause
Tools_controller::OPTIONS()(the handler used for bothOPTIONS /api/{app}/andOPTIONS /api/{app}/tools/..., sinceindex.phpforcescontroller=Toolswhenever anOPTIONS request has none) builds
controllersfrom a hand-maintained static array that'sdisconnected from
$this->subcontrollers, the actual registry of what's dispatchable undertools/. It had already drifted.Fix
Generate the
tools/*portion of the list from$this->subcontrollersdirectly, so itcan't silently drift out of sync again, and add the missing top-level
circuitsentry(and
circuitsLogical, once #4646 also lands - see note below). Per-controllerOPTIONS()methods (e.g.Circuits::OPTIONS(), which already correctly reportsverb-level capabilities for its own routes) are untouched - this is specifically about the
root/tools discovery list being wrong, not a broader OPTIONS redesign.
Related to #4560 (contributed to the confusion about whether a circuits controller
existed).
Tested with
Verified
OPTIONS /api/{app_id}/now listscustomersandcircuits, and everytools/*sub-resource entry matches whatTools_controlleractually dispatches(including the URL-segment quirks, e.g.
ipTags→tools/tags/,vrf→tools/vrfs/).Tested against PHP 8.2, 8.3, and 8.4 - lint clean and passing on each, no new PHP errors.
Suggested merge order: independent, can merge in any order. This branch already adds
a
circuitsLogicalentry to the list in anticipation of #4646 (CircuitsLogicalcontroller) - harmless if this merges first (the href just won't resolve to anything
until #4646 also lands), but ideally merge together or #4646 first.