Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix List certificate templates API docs: parameter name is fleet_id, not fleet (#45969)#45978

Merged
sharon-fdm merged 4 commits into
mainfrom
fix-45969-list-certificate-templates-null
May 21, 2026
Merged

Fix List certificate templates API docs: parameter name is fleet_id, not fleet (#45969)#45978
sharon-fdm merged 4 commits into
mainfrom
fix-45969-list-certificate-templates-null

Conversation

@sharon-fdm
Copy link
Copy Markdown
Collaborator

@sharon-fdm sharon-fdm commented May 21, 2026

Closes #45969

Summary

The List certificate templates API endpoint returned null for certificates because the API docs documented the wrong query parameter name. The docs said fleet but the code accepts fleet_id (or the deprecated team_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.

  • Docs fix: Changed the parameter name from fleet (string) to fleet_id (integer) in the REST API docs, matching how all other list endpoints document this parameter.
  • API quality fix: Initialize the templates slice in GetCertificateTemplatesByTeamID so 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 as fleet (string), but the request struct accepts fleet_id or team_id:

type listCertificateTemplatesRequest struct {
    TeamID uint `query:"team_id,optional" renameto:"fleet_id"`
}

When the customer used ?fleet=11 (as documented), the parameter was unrecognized and silently ignored. The endpoint defaulted to team_id=0 (unassigned), which had no certificates. The nil Go slice then serialized to JSON null.

Credit to Andrey Kizimenko for identifying the docs mismatch.

Changes

  • docs/REST API/rest-api.md -- Fix parameter name from fleet (string) to fleet_id (integer)
  • server/datastore/mysql/certificate_templates.go:174 -- Initialize slice to avoid null in JSON
  • server/datastore/mysql/certificate_templates_test.go:489 -- Add require.NotNil regression test

Testing

All tests run locally against a real MySQL (Docker) and Redis instance:

Test suite Command Result
Datastore integration (all certificate tests) MYSQL_TEST=1 go test -run TestCertificates ./server/datastore/mysql/... 11 suites, 33 subtests, all PASS
Service unit tests go test -run "TestCreateCertificateTemplate|TestApplyCertificateTemplateSpecs|..." 4 suites, all PASS
Enterprise integration (full HTTP) MYSQL_TEST=1 REDIS_TEST=1 go test -run "TestIntegrationsEnterprise/TestCertificatesSpecs" PASS
Enterprise integration (team delete) MYSQL_TEST=1 REDIS_TEST=1 go test -run "TestIntegrationsEnterprise/TestDeleteTeamCertificateTemplates" PASS
Static analysis go build, go vet Clean

Andrey's reproduction confirmed via screenshots:

  • ?fleet_id=11 returns certificates correctly
  • ?fleet=11 (the documented param) returns null -- the bug
  • No param returns results when "unassigned" team has certificates

QA steps

  1. Follow the API docs to list certificate templates using ?fleet_id=<id>
  2. Verify the response contains "certificates": [...] with the correct data
  3. Call without fleet_id and verify "certificates": [] (not null) for a team with no templates

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the "List certificate templates" API documentation with the correct query parameter name, enabling proper filtering of results.

Review Change Stack

…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.
@sharon-fdm sharon-fdm changed the title Fix List certificate templates API returning null instead of empty array Fix List certificate templates API docs: parameter name is fleet_id, not fleet (#45969) May 21, 2026
@sharon-fdm sharon-fdm marked this pull request as ready for review May 21, 2026 13:49
@sharon-fdm sharon-fdm requested review from a team, eashaw and rachaelshaw as code owners May 21, 2026 13:49
Copilot AI review requested due to automatic review settings May 21, 2026 13:49
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sharon-fdm sharon-fdm marked this pull request as draft May 21, 2026 13:49
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.78%. Comparing base (a829900) to head (c18004b).
⚠️ Report is 1 commits behind head on main.

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           
Flag Coverage Δ
backend 68.60% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of fleet).
  • Updated the MySQL datastore implementation to return an empty slice (so JSON encodes [] instead of null) 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.

Comment thread docs/REST API/rest-api.md Outdated
| 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. |
@sharon-fdm sharon-fdm marked this pull request as ready for review May 21, 2026 13:53
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 97d376b6-cd98-4acd-a77a-24265803fabc

📥 Commits

Reviewing files that changed from the base of the PR and between a829900 and a4148ab.

⛔ Files ignored due to path filters (1)
  • docs/REST API/rest-api.md is excluded by !**/*.md
📒 Files selected for processing (3)
  • changes/45969-list-certificate-templates-null
  • server/datastore/mysql/certificate_templates.go
  • server/datastore/mysql/certificate_templates_test.go

Walkthrough

This pull request fixes issue #45969, which reported that the List certificate templates API endpoint returned null for the certificates field instead of an empty array. The fix addresses two issues: the API documentation listed an incorrect query parameter name (fleet instead of fleet_id), and the implementation initialized the templates result slice as nil, causing JSON marshalling to produce null. The changes initialize templates as an empty slice in the implementation, update the corresponding test assertion to validate non-nil behavior, and correct the API documentation parameter reference.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing the API docs parameter name from 'fleet' to 'fleet_id' and referencing the issue #45969.
Description check ✅ Passed The PR description is comprehensive and follows the template structure with summary, root cause, changes, testing, and QA steps included.
Linked Issues check ✅ Passed The PR directly addresses issue #45969 by fixing the docs parameter mismatch, initializing the slice for proper JSON serialization, and adding regression tests.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the API documentation parameter name and the JSON serialization edge case related to issue #45969; no unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-45969-list-certificate-templates-null

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

dantecatalfamo
dantecatalfamo previously approved these changes May 21, 2026
eashaw
eashaw previously approved these changes May 21, 2026
@sharon-fdm sharon-fdm dismissed stale reviews from eashaw and dantecatalfamo via c18004b May 21, 2026 14:10
@sharon-fdm sharon-fdm merged commit 8bb59b7 into main May 21, 2026
43 checks passed
@sharon-fdm sharon-fdm deleted the fix-45969-list-certificate-templates-null branch May 21, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List certificate templates API endpoint returns null value for certificates

5 participants