Skip to content

Commit

Permalink
fix 'p' shortcut for match-path (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison authored Aug 27, 2024
1 parent c5e4d47 commit 30196c0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
15 changes: 15 additions & 0 deletions data/path-filter/base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
openapi: 3.0.1
info:
title: Test API
version: v1
paths:
/a:
get:
responses:
"200":
description: OK
/b:
get:
responses:
"200":
description: OK
19 changes: 19 additions & 0 deletions data/path-filter/revision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: 3.0.1
info:
title: Test API
version: v1
paths:
/a:
get:
tags:
- Test
responses:
"200":
description: OK
/b:
get:
tags:
- Test
responses:
"200":
description: OK
6 changes: 3 additions & 3 deletions internal/cmd_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func addCommonDiffFlags(cmd *cobra.Command) {
cmd.PersistentFlags().BoolP("composed", "c", false, "work in 'composed' mode, compare paths in all specs matching base and revision globs")
cmd.PersistentFlags().String("match-path", "p", "include only paths that match this regular expression")
cmd.PersistentFlags().StringP("match-path", "p", "", "include only paths that match this regular expression")
cmd.PersistentFlags().String("filter-extension", "", "exclude paths and operations with an OpenAPI Extension matching this regular expression")
cmd.PersistentFlags().String("prefix-base", "", "add this prefix to paths in base-spec before comparison")
cmd.PersistentFlags().String("prefix-revision", "", "add this prefix to paths in revised-spec before comparison")
Expand All @@ -28,15 +28,15 @@ func addCommonDiffFlags(cmd *cobra.Command) {
// --flatten was replaced by --flatten-allof
// we still accept --flatten as a synonym for --flatten-allof to avoid breaking existing scripts
func addHiddenFlattenFlag(cmd *cobra.Command) {
cmd.PersistentFlags().BoolP("flatten", "", false, "merge subschemas under allOf before diff")
cmd.PersistentFlags().Bool("flatten", false, "merge subschemas under allOf before diff")
hideFlag(cmd, "flatten")
}

// addHiddenCircularDepFlag adds --max-circular-dep as a hidden flag
// --max-circular-dep is no longer needed because kin-openapi3 handles circular references automatically since https://github.com/getkin/kin-openapi/pull/970
// we still accept --max-circular-dep to avoid breaking existing scripts, but we ignore this flag
func addHiddenCircularDepFlag(cmd *cobra.Command) {
cmd.PersistentFlags().IntP("max-circular-dep", "", 5, "maximum allowed number of circular dependencies between objects in OpenAPI specs")
cmd.PersistentFlags().Int("max-circular-dep", 5, "maximum allowed number of circular dependencies between objects in OpenAPI specs")
hideFlag(cmd, "max-circular-dep")
}

Expand Down
18 changes: 17 additions & 1 deletion internal/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func Test_ChangelogWithAttributes(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff changelog ../data/openapi-test1.yaml ../data/openapi-test3.yaml --attributes x-beta,x-extension-test -f yaml"), &stdout, io.Discard))
cl := formatters.Changes{}
require.NoError(t, yaml.Unmarshal(stdout.Bytes(), &cl))
require.Len(t, cl, 19)
require.Len(t, cl, 21)
require.Equal(t, map[string]interface{}{"x-beta": true, "x-extension-test": interface{}(nil)}, cl[12].Attributes)
}

Expand Down Expand Up @@ -343,3 +343,19 @@ func Test_CustomSeverityLevels(t *testing.T) {
func Test_CustomSeverityLevelsInvalidFile(t *testing.T) {
require.Equal(t, 106, internal.Run(cmdToArgs("oasdiff changelog ../data/openapi-test1.yaml ../data/openapi-test3.yaml --severity-levels ../data/invalid.txt"), io.Discard, io.Discard))
}

func Test_Changelog_WithoutPathFilter(t *testing.T) {
var stdout bytes.Buffer
require.Zero(t, internal.Run(cmdToArgs("oasdiff changelog ../data/path-filter/base.yaml ../data/path-filter/revision.yaml --format json"), &stdout, io.Discard))
bc := formatters.Changes{}
require.NoError(t, json.Unmarshal(stdout.Bytes(), &bc))
require.Len(t, bc, 2)
}

func Test_Changelog_WithPathFilter(t *testing.T) {
var stdout bytes.Buffer
require.Zero(t, internal.Run(cmdToArgs("oasdiff changelog ../data/path-filter/base.yaml ../data/path-filter/revision.yaml --format json -p a"), &stdout, io.Discard))
bc := formatters.Changes{}
require.NoError(t, json.Unmarshal(stdout.Bytes(), &bc))
require.Len(t, bc, 1)
}

0 comments on commit 30196c0

Please sign in to comment.