Skip to content

Commit

Permalink
remove lint from oasdiff tool (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven Harrison authored May 5, 2023
1 parent 1a35f6d commit 53efef8
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 38 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ docker run --rm -t tufin/oasdiff -format text -base https://raw.githubuserconten
- Comprehensive diff including all aspects of [OpenAPI Specification](https://swagger.io/specification/): paths, operations, parameters, request bodies, responses, schemas, enums, callbacks, security etc.
- Allow [non-breaking removal of deprecated resources](#non-breaking-removal-of-deprecated-resources-beta)
- Support [path prefix modification](#path-prefix-modification)
- OpenAPI [Lint](#lint-beta)
- [Extend Breaking-Changes with Custom Checks](CUSTOMIZING-CHECKS.md)

## Install with Go
Expand Down Expand Up @@ -84,8 +83,6 @@ Copy binaries from [latest release](https://github.com/Tufin/oasdiff/releases/)
language for localized breaking changes checks errors (default "en")
-max-circular-dep int
maximum allowed number of circular dependencies between objects in OpenAPI specs (default 5)
-no-lint
disable linter
-prefix string
deprecated. use '-prefix-revision' instead
-prefix-base string
Expand Down Expand Up @@ -442,13 +439,6 @@ You can use the `-exclude-elements` flag to exclude certain kinds of changes:
You can ignore multiple elements with a comma-separated list of excluded elements as in [this example](#ignore-changes-to-description-and-examples).
Note that [Extensions](https://swagger.io/specification/#specification-extensions) are always excluded from the diff.
## Lint [Beta]
oasdiff performs a lint to validate both specs before running the diff and breaking-changes.
If errors are found, the diff is aborted and the errors are displayed instead.
You can pass `-no-lint` to skip lint validation.
Note: This is a Beta feature, please report issues
## Notes for Go Developers
### Embedding oasdiff into your program
```go
Expand Down
2 changes: 0 additions & 2 deletions internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type InputFlags struct {
excludeEndpoints bool
includeChecks utils.StringList
excludeElements utils.StringList
noLint bool
}

func parseFlags(args []string, stdout io.Writer) (*InputFlags, *ReturnError) {
Expand Down Expand Up @@ -79,7 +78,6 @@ func parseFlags(args []string, stdout io.Writer) (*InputFlags, *ReturnError) {
flags.BoolVar(&inputFlags.excludeEndpoints, "exclude-endpoints", false, "exclude endpoints from output (deprecated, use '-exclude-elements endpoints' instead)")
flags.Var(&inputFlags.includeChecks, "include-checks", "comma-separated list of optional breaking-changes checks")
flags.Var(&inputFlags.excludeElements, "exclude-elements", "comma-separated list of elements to exclude from diff")
flags.BoolVar(&inputFlags.noLint, "no-lint", false, "disable linter")

flags.SetOutput(stdout)
if err := flags.Parse(args[1:]); err != nil {
Expand Down
17 changes: 3 additions & 14 deletions internal/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/tufin/oasdiff/build"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/lint"
"github.com/tufin/oasdiff/load"
)

Expand Down Expand Up @@ -87,11 +86,11 @@ func runInternal(args []string, stdout io.Writer, stderr io.Writer) (bool, *Retu
return false, getErrDiffFailed(err)
}
} else {
s1, returnErr := linter(stdout, inputFlags.base, "base", inputFlags.noLint)
s1, returnErr := open(stdout, inputFlags.base, "base")
if returnErr != nil {
return false, returnErr
}
s2, returnErr := linter(stdout, inputFlags.revision, "revision", inputFlags.noLint)
s2, returnErr := open(stdout, inputFlags.revision, "revision")
if returnErr != nil {
return false, returnErr
}
Expand All @@ -118,23 +117,13 @@ func runInternal(args []string, stdout io.Writer, stderr io.Writer) (bool, *Retu
return failEmpty(inputFlags.failOnDiff, diffReport.Empty()), handleDiff(stdout, diffReport, inputFlags.format)
}

func linter(stdout io.Writer, source string, name string, noLint bool) (*load.OpenAPISpecInfo, *ReturnError) {
func open(stdout io.Writer, source string, name string) (*load.OpenAPISpecInfo, *ReturnError) {

s, err := checker.LoadOpenAPISpecInfo(source)
if err != nil {
return nil, getErrFailedToLoadSpec(name, source, err)
}

if noLint {
return s, nil
}

errs := lint.Run(*lint.DefaultConfig(), source, s)
if len(errs) > 0 {
printYAML(stdout, errs)
return nil, getErrLintFailed()
}

return s, nil
}

Expand Down
12 changes: 0 additions & 12 deletions internal/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,3 @@ func Test_Version(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff -version"), &stdout, io.Discard))
require.Contains(t, stdout.String(), "oasdiff version:")
}

func Test_LintFailed(t *testing.T) {
var stdout bytes.Buffer
require.Equal(t, 130, internal.Run(cmdToArgs("oasdiff -base ../data/lint/openapi-invalid-regex.yaml -revision ../data/openapi-test3.yaml"), &stdout, io.Discard))
var errs interface{}
require.NoError(t, yaml.Unmarshal(stdout.Bytes(), &errs))
require.Len(t, errs, 1)
}

func Test_NoLint(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff -base ../data/openapi-test3.yaml -revision ../data/openapi-test3.yaml"), io.Discard, io.Discard))
}

0 comments on commit 53efef8

Please sign in to comment.