fix(server): stop documenting device status updates the API rejects - #7078
Merged
Conversation
The `unused` path value mapped to a status the request validator refuses, so it always answered
400. Nothing lets a client move a device to `unused`, so drop it from the documented enum of both
the device and the container route (the latter is rewritten onto the former), and from the
handler's map. A request for `unused` still gets 400, now from the `required` rule instead of
`oneof`.
PATCH /admin/api/devices/{uid}/{status} was documented in the combined, cloud and enterprise specs,
but the admin router registers no such route. Remove it along with deviceStatusPath, its only
consumer. The deviceStatus schema stays, as the device and container list filters use it.
Fixes: shellhub-io/team#242
The statuses a client can set through PATCH /api/devices/{uid}/{status} were listed twice in Go,
as the handler's path-value map and as the request's `oneof` rule, and twice in the spec, as
inline enums on the device and container routes. shellhub-io/team#242 was those copies drifting
apart: `unused` sat in the map and both enums but not in `oneof`.
The handler's map is the only producer of the request's status, and it yields "" for any path
value it does not know, so `required` alone rejects everything `oneof` did. Drop `oneof` and let
the map be the list. Both spec routes now share the deviceStatusAction schema.
With the rule no longer naming the values, a route test pins which path values are accepted and
what each maps to, including the container route that is rewritten onto the device one.
Code Review CompleteThe automated review ran but did not post an updated summary — this usually means no new issues were found since the previous review. If you've pushed changes and want a fresh pass, comment |
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.
What
Brought the OpenAPI spec for device status updates back in line with what the API serves, and
collapsed the four copies of the settable-status list into one per side (Go and spec).
Why
Reported in shellhub-io/team#242, found while validating the v0.27.0 upgrade:
PATCH /api/devices/{uid}/unusedwas documented but always answered400 {"message":"invalid entity"}. The handler mappedunusedto a status the request'soneofrule refused.PATCH /admin/api/devices/{uid}/{status}was documented in the combined, cloud and enterprisespecs, but the admin router registers only
GET /devicesandGET /devices/:uid.No documented accept/reject/pending flow changes behaviour.
Changes
unusedfrom the status path enum on both the device and the container route./api/containers/*is rewritten onto/api/devices/$1, so the container route had the samedefect. Removed the admin route and
deviceStatusPath.yaml, its only consumer. ThedeviceStatusschema stays; the list filters use it.unusedfrom the handler's path-value map. A request forunusedstill gets400, now from
requiredinstead ofoneof.oneofdrifting apart. The map is the onlyproducer of the request's status and yields
""for unknown values, sorequiredalone rejectseverything
oneofdid. Droppedoneof, making the map the single list. Both spec routes nowshare a
deviceStatusActionschema instead of inline enums.TestUpdateDeviceStatuspins which path values are accepted and what each maps to,including the container route, since the validation tag no longer names them.
Testing
redocly lintpasses on all four root specs; the three customer bundles build.DeviceStatusActiontype in place of the inlineunion. No hand-written UI code references it.
shellhub-io/team#242 is in another repo and will not close on merge; close it by hand.