Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ linters:
- nestif
- nlreturn
- nonamedreturns
- noinlineerr
- paralleltest
- recvcheck
- testpackage
- thelper
- tparallel
Expand All @@ -31,6 +33,7 @@ linters:
- whitespace
- wrapcheck
- wsl
- wsl_v5
settings:
dupl:
threshold: 200
Expand Down
31 changes: 14 additions & 17 deletions fmts/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var extensions = []string{"json"}

//nolint:unparam
func assertSpecJSON(t testing.TB, specJSON []byte) bool {
var expected map[string]interface{}
var expected map[string]any
require.NoError(t, json.Unmarshal(specJSON, &expected))

obj := spec.Swagger{}
Expand All @@ -39,13 +39,13 @@ func assertSpecJSON(t testing.TB, specJSON []byte) bool {
cb, err := json.MarshalIndent(obj, "", " ")
require.NoError(t, err)

var actual map[string]interface{}
var actual map[string]any
require.NoError(t, json.Unmarshal(cb, &actual))

return assertSpecMaps(t, actual, expected)
}

func assertSpecMaps(t testing.TB, actual, expected map[string]interface{}) bool {
func assertSpecMaps(t testing.TB, actual, expected map[string]any) bool {
res := true
if id, ok := expected["id"]; ok {
res = assert.Equal(t, id, actual["id"])
Expand All @@ -70,53 +70,53 @@ func assertSpecMaps(t testing.TB, actual, expected map[string]interface{}) bool
}

//nolint:unparam
func roundTripTest(t *testing.T, fixtureType, extension, fileName string, schema interface{}) bool {
func roundTripTest(t *testing.T, fixtureType, extension, fileName string, schema any) bool {
if extension == "yaml" {
return roundTripTestYAML(t, fixtureType, fileName, schema)
}
return roundTripTestJSON(t, fixtureType, fileName, schema)
}

func roundTripTestJSON(t *testing.T, fixtureType, fileName string, schema interface{}) bool {
func roundTripTestJSON(t *testing.T, fixtureType, fileName string, schema any) bool {
specName := strings.TrimSuffix(fileName, filepath.Ext(fileName))
t.Logf("verifying %s JSON fixture %q", fixtureType, specName)

b, err := os.ReadFile(fileName)
require.NoError(t, err)

var expected map[string]interface{}
var expected map[string]any
require.NoError(t, json.Unmarshal(b, &expected))

require.NoError(t, json.Unmarshal(b, schema))

cb, err := json.MarshalIndent(schema, "", " ")
require.NoError(t, err)

var actual map[string]interface{}
var actual map[string]any
require.NoError(t, json.Unmarshal(cb, &actual))

return assert.EqualValues(t, expected, actual)
return assert.Equal(t, expected, actual)
}

func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema interface{}) bool {
func roundTripTestYAML(t *testing.T, fixtureType, fileName string, schema any) bool {
specName := strings.TrimSuffix(fileName, filepath.Ext(fileName))
t.Logf("verifying %s YAML fixture %q", fixtureType, specName)

b, err := YAMLDoc(fileName)
require.NoError(t, err)

var expected map[string]interface{}
var expected map[string]any
require.NoError(t, json.Unmarshal(b, &expected))

require.NoError(t, json.Unmarshal(b, schema))

cb, err := json.MarshalIndent(schema, "", " ")
require.NoError(t, err)

var actual map[string]interface{}
var actual map[string]any
require.NoError(t, json.Unmarshal(cb, &actual))

return assert.EqualValues(t, expected, actual)
return assert.Equal(t, expected, actual)
}

func TestPropertyFixtures(t *testing.T) {
Expand All @@ -127,9 +127,6 @@ func TestPropertyFixtures(t *testing.T) {
t.Fatal(err)
}

// for _, f := range files {
// roundTripTest(t, "property", extension, filepath.Join(path, f.Name()), &Schema{})
// }
f := files[0]
roundTripTest(t, "property", extension, filepath.Join(path, f.Name()), &spec.Schema{})
}
Expand All @@ -139,14 +136,14 @@ func TestAdditionalPropertiesWithObject(t *testing.T) {
schema := new(spec.Schema)
b, err := YAMLDoc("../fixtures/yaml/models/modelWithObjectMap.yaml")
require.NoError(t, err)
var expected map[string]interface{}
var expected map[string]any
require.NoError(t, json.Unmarshal(b, &expected))
require.NoError(t, json.Unmarshal(b, schema))

cb, err := json.MarshalIndent(schema, "", " ")
require.NoError(t, err)

var actual map[string]interface{}
var actual map[string]any
require.NoError(t, json.Unmarshal(cb, &actual))
assert.Equal(t, expected, actual)
}
Expand Down
1 change: 1 addition & 0 deletions loaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func NewDocLoaderWithMatch(fn DocLoader, matcher DocMatcher) DocLoaderWithMatch

type loader struct {
DocLoaderWithMatch

Next *loader
}

Expand Down
2 changes: 1 addition & 1 deletion options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestOptionsWithDocLoader(t *testing.T) {
trimmed, err := trimData(b)
require.NoError(t, err)

assert.EqualValues(t, trimmed, document.Raw())
assert.Equal(t, trimmed, document.Raw())

// a nil loader is a no op
_, err = Spec(optionFixture, WithDocLoader(nil))
Expand Down
Loading