Make the deploy key example responses match what the API returns

What does this MR do and why?

Every deploy key response carries last_used_at and usage_type. API::Entities::DeployKey inherits both from API::Entities::SSHKey, where they are exposed with no condition, so they are on every response of every endpoint on this page. last_used_at appeared nowhere on the page and usage_type appeared in exactly one of the example responses.

This adds both to every example response on the page, eight of them with ten deploy key objects in total. I put last_used_at next to expires_at, where the entity exposes it, and usage_type next to key, for the same reason. There are no response attribute tables on this page, only request parameter tables, so the examples are the only place on it that needed the two fields.

While editing the examples I also fixed two keys that had lost their name and were left as "", both of them fingerprint_sha256: one in "List all deploy keys" and one in "List deploy keys for project". They parse as valid JSON, so nothing complains, but anyone copying the example gets an object with an empty key and no SHA256 fingerprint.

"List project deploy keys for user" had two example responses: an unlabelled one between the parameter table and the example request, and the labelled one after the request. I removed the unlabelled one, which also carried a third empty key. It came up in review as fine for a follow-up, but this MR already edits that block, so a follow-up removing it would conflict with this one.

Values: usage_type is auth_and_signing in every example, because that is the only value a deploy key can have. keys.usage_type defaults to 0, which Key maps to auth_and_signing, and no deploy key create or update path accepts usage_type: only user SSH keys choose one. The auth example on the entity comes from API::Entities::SSHKey, which deploy keys share with user SSH keys, so it does not describe a deploy key. last_used_at is a timestamp after each key's created_at, and before its expires_at where it has one, except in the response to POST /deploy_keys, which always creates the key and so answers with null. POST /projects/:id/deploy_keys can join a key that already exists, so its example keeps a timestamp.

doc/api/keys.md had the same usage_type mistake in "Retrieve user by deploy key fingerprint": its example response showed auth and its response table gave auth as a possible value. I fixed both here, so the two pages describe a deploy key's usage_type the same way.

The "Add a deploy key for a project", "Update a deploy key" and "Enable a deploy key" examples also left out fingerprint and fingerprint_sha256. API::Entities::DeployKey exposes fingerprint_sha256 on every key and fingerprint whenever the key has an MD5 one, and API::Entities::DeployKeysProject merges that entity, so both are on those responses too. The two keys those examples show get fingerprints of their own, since no two keys can share one. The keys page's deploy key response table and example lacked both as well; its example now carries the fingerprints its example requests use, which are the ones of the key it shows.

Every fingerprint_sha256 on both pages also carried a SHA256: prefix the API does not return: Key#generate_fingerprint strips it before saving, and the entity exposes the stored Base64 value as it is. I removed the prefix from the examples, and the attribute descriptions now say it is absent, since a lookup with GET /keys?fingerprint= needs it added back.

The two project access lists are correct as they stand and I left them alone. They are exposed under if: ->(_, options) { options[:include_projects_with_write_access] } and its readonly twin, and GET /deploy_keys is the only route that passes those options, which is why they appear in the instance list example and in none of the project ones.

I found this while adding the same two fields to the Go API client, in gitlab-org/api/client-go!3049 (merged).

MR acceptance checklist

This change is documentation only. No endpoint, parameter or behavior changes. I parsed every JSON block on both pages after editing: the eight on the deploy keys page and the three on the keys page all parse, all ten deploy key objects on the deploy keys page carry last_used_at, usage_type, fingerprint and fingerprint_sha256, every deploy key usage_type on either page is auth_and_signing, and no fingerprint_sha256 value carries the SHA256: prefix.

Edited by José M. Requena Plens

Merge request reports

Loading
Loading