Fix List certificate templates API docs: parameter name is fleet_id, not fleet (#45969)#45978
Conversation
…ray (#45969) Initialize the templates slice so JSON marshaling produces `[]` instead of `null` when no certificate templates exist for a team.
…leet The docs incorrectly documented the query parameter as `fleet` (string) but the endpoint accepts `fleet_id` (integer) or the deprecated `team_id`. This caused customers to use the wrong parameter name, which was silently ignored, defaulting to team 0 (unassigned) and returning no results.
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #45978 +/- ##
=======================================
Coverage 66.77% 66.78%
=======================================
Files 2751 2752 +1
Lines 219876 219892 +16
Branches 10969 10969
=======================================
+ Hits 146833 146849 +16
Misses 59772 59772
Partials 13271 13271
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a documentation mismatch for the List certificate templates endpoint and ensures the API returns a consistent JSON shape when no certificate templates exist.
Changes:
- Updated REST API docs to document the correct query parameter name:
fleet_id(instead offleet). - Updated the MySQL datastore implementation to return an empty slice (so JSON encodes
[]instead ofnull) when no templates are found. - Added a regression test asserting the returned slice is non-nil when empty.
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| server/datastore/mysql/certificate_templates.go | Initializes the returned slice to avoid null JSON serialization when there are no templates. |
| server/datastore/mysql/certificate_templates_test.go | Adds a regression assertion that the returned slice is non-nil when empty. |
| docs/REST API/rest-api.md | Fixes the documented query parameter name to fleet_id for the list endpoint. |
| changes/45969-list-certificate-templates-null | Adds a changelog entry describing the docs fix and its impact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| | Name | Type | In | Description | | ||
| | ----------| ------- | ---- | -------------------------------------------------------------- | | ||
| | fleet | string | query | _Available in Fleet Premium_. The fleet ID to filter profiles. | | ||
| | fleet_id | integer | query | _Available in Fleet Premium_. The fleet ID to filter certificates. | |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
WalkthroughThis pull request fixes issue 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #45969
Summary
The
List certificate templatesAPI endpoint returnednullfor certificates because the API docs documented the wrong query parameter name. The docs saidfleetbut the code acceptsfleet_id(or the deprecatedteam_id). Customers following the docs used?fleet=11, which was silently ignored, causing the endpoint to default to team 0 (unassigned) -- which typically has no certificates.fleet(string) tofleet_id(integer) in the REST API docs, matching how all other list endpoints document this parameter.templatesslice inGetCertificateTemplatesByTeamIDso that when no templates exist, the JSON response returns"certificates": []instead of"certificates": null.Root cause
In
docs/REST API/rest-api.md, the "List certificate templates" endpoint documented the query parameter asfleet(string), but the request struct acceptsfleet_idorteam_id:When the customer used
?fleet=11(as documented), the parameter was unrecognized and silently ignored. The endpoint defaulted toteam_id=0(unassigned), which had no certificates. The nil Go slice then serialized to JSONnull.Credit to Andrey Kizimenko for identifying the docs mismatch.
Changes
docs/REST API/rest-api.md-- Fix parameter name fromfleet(string) tofleet_id(integer)server/datastore/mysql/certificate_templates.go:174-- Initialize slice to avoidnullin JSONserver/datastore/mysql/certificate_templates_test.go:489-- Addrequire.NotNilregression testTesting
All tests run locally against a real MySQL (Docker) and Redis instance:
MYSQL_TEST=1 go test -run TestCertificates ./server/datastore/mysql/...go test -run "TestCreateCertificateTemplate|TestApplyCertificateTemplateSpecs|..."MYSQL_TEST=1 REDIS_TEST=1 go test -run "TestIntegrationsEnterprise/TestCertificatesSpecs"MYSQL_TEST=1 REDIS_TEST=1 go test -run "TestIntegrationsEnterprise/TestDeleteTeamCertificateTemplates"go build,go vetAndrey's reproduction confirmed via screenshots:
?fleet_id=11returns certificates correctly?fleet=11(the documented param) returnsnull-- the bugQA steps
?fleet_id=<id>"certificates": [...]with the correct datafleet_idand verify"certificates": [](notnull) for a team with no templatesSummary by CodeRabbit