Report OpenAPI spec version and last-check date in --version#19
Conversation
`apimetrics --version` now prints the OpenAPI document version (info.version) and the date/time the spec was last fetched from the server, to aid customer support and debugging. - Persist the spec version in the cached API struct (SpecVersion), captured from libopenapi's model.Info.Version (previously discarded). - Record a `<name>.checked` timestamp in cacheAPI (24h refresh TTL unchanged). - Add a custom cobra version template that appends the two lines. - Make --version a pure reporting command: it reads the cached spec state from disk and skips the network load, so it works offline and never triggers an auth prompt. Fixtures updated: testdata/*/output.yaml now include spec_version. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances apimetrics --version output to include the cached OpenAPI document’s info.version plus a “last checked” timestamp, while ensuring --version avoids any network/API loading (so it remains usable when offline).
Changes:
- Persist OpenAPI
info.versioninto the cachedcli.APImodel (SpecVersion) and expose it via the Cobra version template. - Record a per-API “checked” timestamp when the API spec cache is written, and display it in
--version. - Update OpenAPI test fixtures to include
spec_versionin expected YAML output.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
cli/api.go |
Adds SpecVersion to cached API state, records <name>.checked, and implements versionExtraInfo() to read cached spec version + timestamp. |
cli/cli.go |
Customizes Cobra version template and skips network loading when --version is requested. |
openapi/openapi.go |
Captures model.Info.Version into cli.API.SpecVersion during OpenAPI load. |
openapi/testdata/request/output.yaml |
Updates expected fixture output to include spec_version. |
openapi/testdata/petstore/output.yaml |
Updates expected fixture output to include spec_version. |
openapi/testdata/long_example/output.yaml |
Updates expected fixture output to include spec_version. |
openapi/testdata/group-resp/output.yaml |
Updates expected fixture output to include spec_version. |
openapi/testdata/extensions/output.yaml |
Updates expected fixture output to include spec_version. |
openapi/testdata/auto_config/output.yaml |
Updates expected fixture output to include spec_version. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR review: versionExtraInfo now only trusts the on-disk cache when its CLIVersion matches the running binary, mirroring Load's validity check, so --version won't report a stale spec version/timestamp after a binary upgrade (the CLI would refetch that cache anyway). Also skip the cache lookup entirely when api-name is empty. Add TestVersionExtraInfo covering the no-cache, valid-cache, and stale-cache (mismatched CLIVersion) paths. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks — both points addressed in 38e4ca3.
|
Loading the OpenAPI spec (the entrypoint and /openapi.json) is done against public endpoints, but MakeRequest was still applying the profile's auth, which triggered an interactive login on any invocation that hit a cache miss -- including `apimetrics`, `apimetrics --help`, completion, and config commands that never call an API operation. Add an IgnoreAuth() request option and use it for the two spec-loading requests in Load, so building the command tree never prompts for login. Auth is still applied for real API operations (which don't pass the option). Add TestIgnoreAuth verifying the auth hook is skipped. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Address PR review: the offline/no-auth skip for --version matched only the literal "--version" arg, so `--version=true` would still trigger the network load. Register a version bool on GlobalFlags and read it via the eager parse, which handles every bool form (--version, --version=true, --version=false) consistently with Cobra. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
apimetrics --versionnow reports the OpenAPI document version (info.version) and the date/time the spec was last fetched from the server, to aid customer support and debugging:Background
The CLI already auto-refreshes the cached OpenAPI spec on a 24-hour TTL (
cacheAPIincli/api.go) — that cadence is unchanged here. The value added is visibility: previously the spec's own version was parsed by libopenapi and then discarded, and there was no way to see when the spec was last refreshed.Changes
cli/api.go— AddSpecVersionto the cachedAPIstruct (CBOR-persisted), carry it throughMerge, and record a<name>.checkedtimestamp incacheAPI. AddversionExtraInfo()which reads the loaded API or falls back to the on-disk.cborcache.openapi/openapi.go— Capturemodel.Info.Versioninto the builtcli.API.cli/cli.go— Register aversionExtratemplate func + custom cobra version template, and make--versionskip the network load (reads cached state from disk).openapi/testdata/*/output.yaml— Fixtures updated to includespec_version.Resilience
--versionis used precisely when things are broken, so it must not depend on the network. It now reads the cached spec state from disk and skips the load entirely — no network call, no auth prompt, no panic when offline. Verified:unknown/never, clean exitAfter a binary upgrade, existing caches repopulate automatically (a CLI version change already invalidates the cache).
Testing
go test ./...— all passgo vet ./...— clean🤖 Generated with Claude Code