Skip to content

Commit 9b5083d

Browse files
committed
Addressed #218
1 parent b7b2247 commit 9b5083d

8 files changed

Lines changed: 135 additions & 5 deletions

File tree

AGENTS.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,23 @@ Public documentation:
1616
- local git history for a file in a repository
1717
- GitHub-hosted file history via file URL
1818

19-
The public command surface is:
19+
The public comparison/report surface is:
2020

2121
- `console`
2222
- `summary`
2323
- `report`
2424
- `markdown-report`
2525
- `html-report`
2626

27-
All five commands use the current engine built on `doctor`, the open source Apache 2.0 library from pb33f:
27+
These five commands use the current engine built on `doctor`, the open source Apache 2.0 library from pb33f:
2828

2929
- https://github.com/pb33f/doctor
3030

31+
Utility commands:
32+
33+
- `completion`
34+
- `version`
35+
3136
## Source Of Truth
3237

3338
The code is the source of truth.
@@ -90,6 +95,7 @@ All `cmd/` implementation files use their canonical names (e.g., `cmd/summary.go
9095
## Files That Matter Most
9196

9297
- `cmd/root.go` — root Cobra command, CLI entry point, subcommand registration
98+
- `cmd/version.go` — prints the raw build version string
9399
- `cmd/common.go` — shared option flags and Lip Gloss styling for all doctor-based commands
94100
- `cmd/loaders.go` — loads specs from files, URLs, and git history; progress tracking and error aggregation
95101
- `cmd/engine.go` — wraps doctor changerator for API comparison; manages document resource cleanup and mutex-guarded breaking config

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ To run the interactive `console` through Docker, allocate a TTY with `-it`:
7575
docker run --rm -it -v $PWD:/work:rw pb33f/openapi-changes console . path/to/openapi.yaml
7676
```
7777

78+
## Verify the install
79+
80+
Print the installed version:
81+
82+
```bash
83+
openapi-changes version
84+
```
7885

7986
---
8087

@@ -159,6 +166,7 @@ Full docs: https://pb33f.io/openapi-changes/
159166
- [`markdown-report`](https://pb33f.io/openapi-changes/markdown-report/)
160167
- [`html-report`](https://pb33f.io/openapi-changes/html-report/)
161168
- [`completion`](https://pb33f.io/openapi-changes/completion/)
169+
- [`version`](https://pb33f.io/openapi-changes/version/)
162170
- [About openapi-changes](https://pb33f.io/openapi-changes/about/)
163171

164172
---
@@ -191,6 +199,7 @@ The current command surface is:
191199
- `markdown-report` for shareable markdown output
192200
- `html-report` for the interactive offline browser report
193201
- `completion` for shell completion scripts
202+
- `version` for raw build version output
194203

195204
Run `openapi-changes --help` or `openapi-changes <command> --help` for the live CLI surface.
196205

cmd/command_surface_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ func TestCommandSurface_UsesCanonicalNames(t *testing.T) {
1515
assert.Equal(t, "markdown-report", GetMarkdownReportCommand().Use)
1616
assert.Equal(t, "html-report", GetHTMLReportCommand().Use)
1717
assert.Equal(t, "console", GetConsoleCommand().Use)
18+
assert.Equal(t, "version", GetVersionCommand().Use)
1819
}

cmd/root.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package cmd
66
import (
77
"fmt"
88
"os"
9+
"sort"
910

1011
"github.com/spf13/cobra"
1112
)
@@ -20,9 +21,9 @@ var (
2021
Use: "openapi-changes",
2122
Short: "Detect and explore changes between OpenAPI / Swagger specifications.",
2223
Long: `openapi-changes can detect every change found in an OpenAPI specification.
23-
it can compare between two files, or a single file, over time.
24+
it can compare between two files, or a single file, over time.
2425
25-
All commands use the current doctor-based engine.`,
26+
The comparison and reporting commands use the current doctor-based engine.`,
2627
RunE: func(cmd *cobra.Command, args []string) error {
2728
opts, _, err := readCommonFlags(cmd)
2829
if err != nil {
@@ -32,7 +33,7 @@ All commands use the current doctor-based engine.`,
3233

3334
fmt.Println("Current commands")
3435
fmt.Println()
35-
for _, name := range []string{"console", "summary", "report", "markdown-report", "html-report"} {
36+
for _, name := range visibleRootCommandNames(cmd) {
3637
fmt.Printf(" > %s\n", name)
3738
}
3839
fmt.Println()
@@ -53,13 +54,26 @@ func Execute(version, commit, date string) {
5354
}
5455
}
5556

57+
func visibleRootCommandNames(root *cobra.Command) []string {
58+
var names []string
59+
for _, command := range root.Commands() {
60+
if command == nil || command.Hidden || command.Name() == "help" {
61+
continue
62+
}
63+
names = append(names, command.Name())
64+
}
65+
sort.Strings(names)
66+
return names
67+
}
68+
5669
func init() {
5770
cobra.OnInitialize(initConfig)
5871
rootCmd.AddCommand(GetConsoleCommand())
5972
rootCmd.AddCommand(GetHTMLReportCommand())
6073
rootCmd.AddCommand(GetMarkdownReportCommand())
6174
rootCmd.AddCommand(GetReportCommand())
6275
rootCmd.AddCommand(GetSummaryCommand())
76+
rootCmd.AddCommand(GetVersionCommand())
6377
rootCmd.PersistentFlags().BoolP("top", "t", false, "Only show latest changes (last git revision against HEAD)")
6478
rootCmd.PersistentFlags().IntP("limit", "l", 5, "Limit history to number of revisions (default is 5)")
6579
rootCmd.PersistentFlags().BoolP("global-revisions", "R", false, "Consider all revisions in limit, not just the ones for the file")

cmd/root_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ func TestRootCommand_ZeroArgsHonorsNoLogo(t *testing.T) {
2121
})
2222

2323
assert.Contains(t, output, "Current commands")
24+
assert.Contains(t, output, "completion")
25+
assert.Contains(t, output, "version")
2426
assert.NotContains(t, output, "https://pb33f.io/openapi-changes/")
2527
assert.NotContains(t, output, "@@@@@@@")
2628
}

cmd/summary_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,51 @@ func TestRenderSummary_ComposedSchemaTitleRemovalDoesNotMislabelAsAnyOf(t *testi
427427
assert.NotContains(t, output, "anyOf")
428428
}
429429

430+
func TestRenderSummary_RendersRemovedRequiredMemberName(t *testing.T) {
431+
commit := mustMakeDoctorOnlyCommitFromSpecs(t, "required-label", `openapi: 3.0.3
432+
info:
433+
title: Test API
434+
version: "1.0"
435+
paths: {}
436+
components:
437+
schemas:
438+
ReminderRequest:
439+
type: object
440+
required:
441+
- result
442+
properties:
443+
result:
444+
type: string
445+
`, `openapi: 3.0.3
446+
info:
447+
title: Test API
448+
version: "1.0"
449+
paths: {}
450+
components:
451+
schemas:
452+
ReminderRequest:
453+
type: object
454+
properties:
455+
result:
456+
type: string
457+
`)
458+
459+
output, hasBreaking, hasChanges, err := renderSummary(
460+
[]*model.Commit{commit},
461+
nil,
462+
true,
463+
true,
464+
true,
465+
summaryStyles{},
466+
)
467+
468+
require.NoError(t, err)
469+
assert.True(t, hasChanges)
470+
assert.True(t, hasBreaking)
471+
assert.Contains(t, output, "Removed ReminderRequest required/result")
472+
assert.Contains(t, output, "required/result (")
473+
}
474+
430475
func TestLoadLeftRightCommits_ReturnsHTTPStatusErrors(t *testing.T) {
431476
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
432477
http.Error(w, "missing", http.StatusNotFound)

cmd/version.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// GetVersionCommand returns the cobra command for printing the raw build version.
13+
func GetVersionCommand() *cobra.Command {
14+
return &cobra.Command{
15+
Use: "version",
16+
Short: "Print the openapi-changes version",
17+
Args: cobra.NoArgs,
18+
RunE: func(cmd *cobra.Command, args []string) error {
19+
version := Version
20+
if version == "" {
21+
version = "latest"
22+
}
23+
_, err := fmt.Fprintln(cmd.OutOrStdout(), version)
24+
return err
25+
},
26+
}
27+
}

cmd/version_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2023-2026 Princess Beef Heavy Industries, LLC / Dave Shanley
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package cmd
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestVersionCommand_PrintsVersionOnly(t *testing.T) {
14+
originalVersion := Version
15+
Version = "v1.2.3-test"
16+
t.Cleanup(func() {
17+
Version = originalVersion
18+
})
19+
20+
cmd := testRootCmd(GetVersionCommand())
21+
output := captureStdout(t, func() {
22+
require.NoError(t, cmd.Execute())
23+
})
24+
25+
assert.Equal(t, "v1.2.3-test\n", output)
26+
}

0 commit comments

Comments
 (0)