Skip to content

fix(server/show): include security_groups in JSON/YAML output (closes #191)#200

Merged
crowdy merged 2 commits into
mainfrom
fix/issue-191-server-show-json-sg
May 9, 2026
Merged

fix(server/show): include security_groups in JSON/YAML output (closes #191)#200
crowdy merged 2 commits into
mainfrom
fix/issue-191-server-show-json-sg

Conversation

@crowdy
Copy link
Copy Markdown
Owner

@crowdy crowdy commented May 9, 2026

Summary

  • `server show --format json` returned `security_groups: null` because `model.Server` has no such field — table output assembled SG names from `/v2.0/ports?device_id=...` + `/v2.0/security-groups` separately, but the structured-format path just marshalled the raw model.
  • Move the port + SG resolution above the format branch, then surface it via a `serverShowDetail` wrapper that embeds `*model.Server` (so existing field names stay top-level) and adds `security_groups`, `ports`, `volumes`.
  • `omitempty` keeps responses lean — servers with no ports won't sprout empty arrays, and nil SG state simply drops the key rather than re-introducing the null bug.

JSON shape

```json
{
"id": "...",
"name": "web1",
"flavor": { "id": "..." },
"security_groups": ["IPv4v6-SSH", "3000-9999"],
"ports": [{ "id": "...", "mac_address": "...", "ips": ["..."] }],
"volumes": [{ "id": "...", "device": "/dev/vda", "size_gb": 100 }]
}
```

Test plan

  • `go test ./cmd/server/ -run ServerShowDetail` — covers JSON shape (security_groups present), YAML inline flattening, omitempty for nil SGs
  • `go test ./...` — full suite green
  • Live verify: `conoha server show --format json | jq '.security_groups'` returns array, not null

Note

CSV output of `server show` was already not particularly useful (single struct → header + 1 row); behaviour is unchanged for CSV consumers.

🤖 Generated with Claude Code

t-kim-planitai and others added 2 commits May 9, 2026 17:41
…191)

server show --format json previously returned security_groups: null
because the underlying model.Server has no such field — the table
renderer assembled SG names by querying /v2.0/ports?device_id=... and
joining against /v2.0/security-groups, but the structured-format path
just dumped the raw model and dropped that data.

Move the port + SG resolution above the format branch and surface it
through a serverShowDetail wrapper that embeds *model.Server (so
existing JSON/YAML field names stay at the top level) plus
security_groups, ports, and volumes. omitempty keeps the JSON shape
for servers without ports; nil SG state therefore omits the field
rather than resurrecting the null bug.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
CI's golangci-lint pulls in gofmt and the embedded *model.Server line
needed an extra space for tag-column alignment. Pure formatting; no
behaviour change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@crowdy crowdy merged commit decebee into main May 9, 2026
5 checks passed
@crowdy crowdy deleted the fix/issue-191-server-show-json-sg branch May 9, 2026 13:32
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.

2 participants