Skip to content

Commit

Permalink
Bump github.com/getkin/kin-openapi from 0.125.0 to 0.126.0 (#575)
Browse files Browse the repository at this point in the history
* Bump github.com/getkin/kin-openapi from 0.125.0 to 0.126.0

Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.125.0 to 0.126.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](getkin/kin-openapi@v0.125.0...v0.126.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* hide --max-circular-dep

* separate unix and win tests

* update windows err messsages

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Reuven <[email protected]>
  • Loading branch information
dependabot[bot] and Reuven authored Jul 9, 2024
1 parent 6e2d425 commit 2ab458f
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 124 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.5
require (
cloud.google.com/go v0.115.0
github.com/TwiN/go-color v1.4.1
github.com/getkin/kin-openapi v0.125.0
github.com/getkin/kin-openapi v0.126.0
github.com/oasdiff/telemetry v0.1.2
github.com/stretchr/testify v1.9.0
github.com/yargevad/filepathx v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
github.com/getkin/kin-openapi v0.125.0 h1:jyQCyf2qXS1qvs2U00xQzkGCqYPhEhZDmSmVt65fXno=
github.com/getkin/kin-openapi v0.125.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM=
github.com/getkin/kin-openapi v0.126.0 h1:c2cSgLnAsS0xYfKsgt5oBV6MYRM/giU8/RtwUY4wyfY=
github.com/getkin/kin-openapi v0.126.0/go.mod h1:7mONz8IwmSRg6RttPu6v8U/OJ+gr+J99qSFNjPGSQqw=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
Expand Down
3 changes: 0 additions & 3 deletions internal/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"

"github.com/getkin/kin-openapi/openapi3"
"github.com/spf13/cobra"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/formatters"
Expand Down Expand Up @@ -48,8 +47,6 @@ func runChangelog(flags Flags, stdout io.Writer) (bool, *ReturnError) {

func getChangelog(flags Flags, stdout io.Writer, level checker.Level) (bool, *ReturnError) {

openapi3.CircularReferenceCounter = flags.getCircularReferenceCounter()

diffResult, err := calcDiff(flags)
if err != nil {
return false, err
Expand Down
57 changes: 24 additions & 33 deletions internal/changelog_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,30 @@ import (
)

type ChangelogFlags struct {
base *load.Source
revision *load.Source
composed bool
prefixBase string
prefixRevision string
stripPrefixBase string
stripPrefixRevision string
matchPath string
filterExtension string
format string
circularReferenceCounter int
includePathParams bool
excludeElements []string
includeChecks []string
failOn string
level string
flattenAllOf bool
flattenParams bool
insensitiveHeaders bool
lang string
errIgnoreFile string
warnIgnoreFile string
deprecationDaysBeta uint
deprecationDaysStable uint
color string
base *load.Source
revision *load.Source
composed bool
prefixBase string
prefixRevision string
stripPrefixBase string
stripPrefixRevision string
matchPath string
filterExtension string
format string
includePathParams bool
excludeElements []string
includeChecks []string
failOn string
level string
flattenAllOf bool
flattenParams bool
insensitiveHeaders bool
lang string
errIgnoreFile string
warnIgnoreFile string
deprecationDaysBeta uint
deprecationDaysStable uint
color string
}

func (flags *ChangelogFlags) toConfig() *diff.Config {
Expand Down Expand Up @@ -70,10 +69,6 @@ func (flags *ChangelogFlags) getInsensitiveHeaders() bool {
return flags.insensitiveHeaders
}

func (flags *ChangelogFlags) getCircularReferenceCounter() int {
return flags.circularReferenceCounter
}

func (flags *ChangelogFlags) getIncludeChecks() []string {
return flags.includeChecks
}
Expand Down Expand Up @@ -150,10 +145,6 @@ func (flags *ChangelogFlags) refFilterExtension() *string {
return &flags.filterExtension
}

func (flags *ChangelogFlags) refCircularReferenceCounter() *int {
return &flags.circularReferenceCounter
}

func (flags *ChangelogFlags) refPrefixBase() *string {
return &flags.prefixBase
}
Expand Down
31 changes: 22 additions & 9 deletions internal/cmd_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ func addCommonDiffFlags(cmd *cobra.Command, flags Flags) {
cmd.PersistentFlags().BoolVarP(flags.refComposed(), "composed", "c", false, "work in 'composed' mode, compare paths in all specs matching base and revision globs")
cmd.PersistentFlags().StringVarP(flags.refMatchPath(), "match-path", "p", "", "include only paths that match this regular expression")
cmd.PersistentFlags().StringVarP(flags.refFilterExtension(), "filter-extension", "", "", "exclude paths and operations with an OpenAPI Extension matching this regular expression")
cmd.PersistentFlags().IntVarP(flags.refCircularReferenceCounter(), "max-circular-dep", "", 5, "maximum allowed number of circular dependencies between objects in OpenAPI specs")
cmd.PersistentFlags().StringVarP(flags.refPrefixBase(), "prefix-base", "", "", "add this prefix to paths in base-spec before comparison")
cmd.PersistentFlags().StringVarP(flags.refPrefixRevision(), "prefix-revision", "", "", "add this prefix to paths in revised-spec before comparison")
cmd.PersistentFlags().StringVarP(flags.refStripPrefixBase(), "strip-prefix-base", "", "", "strip this prefix from paths in base-spec before comparison")
Expand All @@ -20,18 +19,32 @@ func addCommonDiffFlags(cmd *cobra.Command, flags Flags) {
cmd.PersistentFlags().BoolVarP(flags.refFlattenAllOf(), "flatten-allof", "", false, "merge subschemas under allOf before diff")
cmd.PersistentFlags().BoolVarP(flags.refFlattenParams(), "flatten-params", "", false, "merge common parameters at path level with operation parameters")
cmd.PersistentFlags().BoolVarP(flags.refInsensitiveHeaders(), "case-insensitive-headers", "", false, "case-insensitive header name comparison")
addDeprecatedFlattenFlag(cmd, flags)

addHiddenFlattenFlag(cmd, flags)
addHiddenCircularDepFlag(cmd)
}

func addDeprecatedFlattenFlag(cmd *cobra.Command, flags Flags) {
const flag = "flatten"
// addHiddenFlattenFlag adds --flatten as a hidden flag
// --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, flags Flags) {
cmd.PersistentFlags().BoolVarP(flags.refFlattenAllOf(), "flatten", "", false, "merge subschemas under allOf before diff")
hideFlag(cmd, "flatten")
}

// add this flag for backward compatibility
cmd.PersistentFlags().BoolVarP(flags.refFlattenAllOf(), flag, "", false, "merge subschemas under allOf before diff")
// 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) {
var dummy int
cmd.PersistentFlags().IntVarP(&dummy, "max-circular-dep", "", 5, "maximum allowed number of circular dependencies between objects in OpenAPI specs")
hideFlag(cmd, "max-circular-dep")
}

// ideally we'd like to mark '--flatten' as deprecated but this causes cobra to write an error message to stdout when the flag is used
// this messes up the json and yaml output
// so instead we just hide the flag
// hideFlag hides a flag from the help
// this is an alternative to marking the flag as deprecated
// marking the flag as deprecated is problematic because it causes cobra to write an error message to stdout which messes up the json and yaml output
func hideFlag(cmd *cobra.Command, flag string) {
if err := cmd.PersistentFlags().MarkHidden(flag); err != nil {
// we can ignore this error safely
_ = err
Expand Down
2 changes: 0 additions & 2 deletions internal/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ func getDiffCmd() *cobra.Command {

func runDiff(flags Flags, stdout io.Writer) (bool, *ReturnError) {

openapi3.CircularReferenceCounter = flags.getCircularReferenceCounter()

if flags.getFormat() == string(formatters.FormatJSON) {
flags.addExcludeElements(diff.ExcludeEndpointsOption)
}
Expand Down
41 changes: 16 additions & 25 deletions internal/diff_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ import (
)

type DiffFlags struct {
base *load.Source
revision *load.Source
composed bool
prefixBase string
prefixRevision string
stripPrefixBase string
stripPrefixRevision string
matchPath string
filterExtension string
format string
failOnDiff bool
flattenAllOf bool
flattenParams bool
insensitiveHeaders bool
circularReferenceCounter int
includePathParams bool
excludeElements []string
base *load.Source
revision *load.Source
composed bool
prefixBase string
prefixRevision string
stripPrefixBase string
stripPrefixRevision string
matchPath string
filterExtension string
format string
failOnDiff bool
flattenAllOf bool
flattenParams bool
insensitiveHeaders bool
includePathParams bool
excludeElements []string
}

func (flags *DiffFlags) toConfig() *diff.Config {
Expand Down Expand Up @@ -62,10 +61,6 @@ func (flags *DiffFlags) getInsensitiveHeaders() bool {
return flags.insensitiveHeaders
}

func (flags *DiffFlags) getCircularReferenceCounter() int {
return flags.circularReferenceCounter
}

func (flags *DiffFlags) getIncludeChecks() []string {
return nil
}
Expand Down Expand Up @@ -142,10 +137,6 @@ func (flags *DiffFlags) refFilterExtension() *string {
return &flags.filterExtension
}

func (flags *DiffFlags) refCircularReferenceCounter() *int {
return &flags.circularReferenceCounter
}

func (flags *DiffFlags) refPrefixBase() *string {
return &flags.prefixBase
}
Expand Down
2 changes: 0 additions & 2 deletions internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ type Flags interface {
getFlattenAllOf() bool
getFlattenParams() bool
getInsensitiveHeaders() bool
getCircularReferenceCounter() int
getIncludeChecks() []string
getDeprecationDaysBeta() uint
getDeprecationDaysStable() uint
Expand All @@ -37,7 +36,6 @@ type Flags interface {
refExcludeElements() *[]string
refMatchPath() *string
refFilterExtension() *string
refCircularReferenceCounter() *int
refPrefixBase() *string
refPrefixRevision() *string
refStripPrefixBase() *string
Expand Down
4 changes: 1 addition & 3 deletions internal/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ Spec can be a path to a file, a URL or '-' to read standard input.
}

enumWithOptions(&cmd, newEnumValue(formatters.SupportedFormatsByContentType(formatters.OutputFlatten), string(formatters.FormatJSON), &flags.format), "format", "f", "output format")
cmd.PersistentFlags().IntVarP(&flags.circularReferenceCounter, "max-circular-dep", "", 5, "maximum allowed number of circular dependencies between objects in OpenAPI specs")
addHiddenCircularDepFlag(&cmd)

return &cmd
}

func runFlatten(flags *FlattenFlags, stdout io.Writer) *ReturnError {

openapi3.CircularReferenceCounter = flags.circularReferenceCounter

loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
spec, err := load.NewSpecInfo(loader, flags.spec, load.WithFlattenAllOf())
Expand Down
5 changes: 2 additions & 3 deletions internal/flatten_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package internal
import "github.com/tufin/oasdiff/load"

type FlattenFlags struct {
spec *load.Source
format string
circularReferenceCounter int
spec *load.Source
format string
}
14 changes: 0 additions & 14 deletions internal/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,17 +326,3 @@ func Test_InvalidEnumValue(t *testing.T) {
require.Equal(t, `Error: invalid argument "xxx" for "-e, --exclude-elements" flag: xxx is not one of the allowed values: description, endpoints, examples, extensions, summary, or title
`, stderr.String())
}

// The behavior of max-circular-dep (which is mapped to CircularReferenceCounter in kin-openapi) is unclear
// All we know is that if a user gets this error, they should increase the value of max-circular-dep
// See https://github.com/getkin/kin-openapi/issues/916
func Test_MaxCircularInsufficient(t *testing.T) {
var stderr bytes.Buffer
require.Equal(t, 102, internal.Run(cmdToArgs("oasdiff diff ../data/circular3.yaml ../data/circular3.yaml --max-circular-dep=0"), io.Discard, &stderr))
require.Contains(t, stderr.String(), "Error: failed to load base spec from \"../data/circular3.yaml\": kin-openapi bug found: circular schema reference not handled with")
}

// Increasing max-circular-dep to 2 is enough to handle the circular reference
func Test_MaxCircularSufficient(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff diff ../data/circular3.yaml ../data/circular3.yaml --max-circular-dep=2"), io.Discard, io.Discard))
}
3 changes: 0 additions & 3 deletions internal/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"io"

"github.com/getkin/kin-openapi/openapi3"
"github.com/spf13/cobra"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/formatters"
Expand Down Expand Up @@ -33,8 +32,6 @@ func getSummaryCmd() *cobra.Command {

func runSummary(flags Flags, stdout io.Writer) (bool, *ReturnError) {

openapi3.CircularReferenceCounter = flags.getCircularReferenceCounter()

diffResult, err := calcDiff(flags)
if err != nil {
return false, err
Expand Down
24 changes: 0 additions & 24 deletions load/spec_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,11 @@ func TestSpecInfo_File(t *testing.T) {
require.NoError(t, err)
}

func TestLoadInfo_FileWindows(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource(`C:\dev\OpenApi\spec2.yaml`))
require.Condition(t, func() (success bool) {
return err.Error() == "open C:\\dev\\OpenApi\\spec2.yaml: no such file or directory" ||
err.Error() == "open C:/dev/OpenApi/spec2.yaml: The system cannot find the path specified."
})
}

func TestLoadInfo_URI(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource("https://localhost/data/openapi-test1.yaml"))
require.NoError(t, err)
}

func TestLoadInfo_UriInvalid(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource("http://localhost/null"))
require.Condition(t, func() (success bool) {
return err.Error() == "open ../null: no such file or directory" ||
err.Error() == "open ../null: The system cannot find the file specified."
})
}

func TestLoadInfo_UriBadScheme(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource("ftp://localhost/null"))
require.Condition(t, func() (success bool) {
return err.Error() == "open ftp://localhost/null: no such file or directory" ||
err.Error() == "open ftp://localhost/null: The filename, directory name, or volume label syntax is incorrect."
})
}

func TestLoadInfo_Stdin(t *testing.T) {
content := []byte(`openapi: 3.0.1
info:
Expand Down
25 changes: 25 additions & 0 deletions load/spec_info_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build unix

package load_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/load"
)

func TestLoadInfo_FileWindows(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource(`C:\dev\OpenApi\spec2.yaml`))
require.EqualError(t, err, "open C:\\dev\\OpenApi\\spec2.yaml: no such file or directory")
}

func TestLoadInfo_UriInvalid(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource("http://localhost/null"))
require.EqualError(t, err, "open ../null: no such file or directory")
}

func TestLoadInfo_UriBadScheme(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource("ftp://localhost/null"))
require.EqualError(t, err, "open ftp://localhost/null: no such file or directory")
}
23 changes: 23 additions & 0 deletions load/spec_info_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package load_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tufin/oasdiff/load"
)

func TestLoadInfo_FileWindows(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource(`C:\dev\OpenApi\spec2.yaml`))
require.EqualError(t, err, "open C:\\dev\\OpenApi\\spec2.yaml: The system cannot find the path specified.")
}

func TestLoadInfo_UriInvalid(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource("http://localhost/null"))
require.EqualError(t, err, "open ..\\null: The system cannot find the file specified.")
}

func TestLoadInfo_UriBadScheme(t *testing.T) {
_, err := load.NewSpecInfo(MockLoader{}, load.NewSource("ftp://localhost/null"))
require.EqualError(t, err, "open ftp:\\\\localhost\\null: The filename, directory name, or volume label syntax is incorrect.")
}

0 comments on commit 2ab458f

Please sign in to comment.