Skip to content

fix(server): stop documenting device status updates the API rejects - #7078

Merged
otavio merged 2 commits into
masterfrom
fix/openapi-device-status-spec
Sep 11, 2026
Merged

fix(server): stop documenting device status updates the API rejects#7078
otavio merged 2 commits into
masterfrom
fix/openapi-device-status-spec

Conversation

@otavio

@otavio otavio commented Sep 11, 2026

Copy link
Copy Markdown
Member

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}/unused was documented but always answered
    400 {"message":"invalid entity"}. The handler mapped unused to a status the request's
    oneof rule refused.
  • PATCH /admin/api/devices/{uid}/{status} was documented in the combined, cloud and enterprise
    specs, but the admin router registers only GET /devices and GET /devices/:uid.

No documented accept/reject/pending flow changes behaviour.

Changes

  • spec: dropped unused from 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 same
    defect. Removed the admin route and deviceStatusPath.yaml, its only consumer. The
    deviceStatus schema stays; the list filters use it.
  • server: removed unused from the handler's path-value map. A request for unused still gets
    400, now from required instead of oneof.
  • refactor (second commit): the bug was the map and oneof drifting apart. The map is the only
    producer of the request's status and yields "" for unknown values, so required alone rejects
    everything oneof did. Dropped oneof, making the map the single list. Both spec routes now
    share a deviceStatusAction schema instead of inline enums.
  • tests: TestUpdateDeviceStatus pins which path values are accepted and what each maps to,
    including the container route, since the validation tag no longer names them.

Testing

  • redocly lint passes on all four root specs; the three customer bundles build.
  • The generated console client gets a named DeviceStatusAction type in place of the inline
    union. 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.

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.
@otavio
otavio requested review from a team as code owners September 11, 2026 19:03
@github-actions

github-actions Bot commented Sep 11, 2026

Copy link
Copy Markdown

Code Review Complete

The 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 /review.

View job

@otavio
otavio merged commit 5b27ff6 into master Sep 11, 2026
43 checks passed
@otavio
otavio deleted the fix/openapi-device-status-spec branch September 11, 2026 19:12
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.

1 participant