Skip to content

Commit

Permalink
feat(loader): implement reference back-tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyRugalev committed Jun 26, 2024
1 parent 57624b3 commit 1871e49
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 138 deletions.
1 change: 0 additions & 1 deletion cmd/validate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func main() {

switch {
case vd.OpenAPI == "3" || strings.HasPrefix(vd.OpenAPI, "3."):
openapi3.CircularReferenceCounter = *circular
loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = *ext

Expand Down
2 changes: 1 addition & 1 deletion openapi3/issue570_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import (
func TestIssue570(t *testing.T) {
loader := NewLoader()
_, err := loader.LoadFromFile("testdata/issue570.json")
require.ErrorContains(t, err, CircularReferenceError)
require.NoError(t, err)
}
15 changes: 0 additions & 15 deletions openapi3/issue615_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,6 @@ import (
)

func TestIssue615(t *testing.T) {
{
var old int
old, openapi3.CircularReferenceCounter = openapi3.CircularReferenceCounter, 1
defer func() { openapi3.CircularReferenceCounter = old }()

loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
_, err := loader.LoadFromFile("testdata/recursiveRef/issue615.yml")
require.ErrorContains(t, err, openapi3.CircularReferenceError)
}

var old int
old, openapi3.CircularReferenceCounter = openapi3.CircularReferenceCounter, 4
defer func() { openapi3.CircularReferenceCounter = old }()

loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
doc, err := loader.LoadFromFile("testdata/recursiveRef/issue615.yml")
Expand Down
5 changes: 0 additions & 5 deletions openapi3/issue796_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import (
)

func TestIssue796(t *testing.T) {
var old int
// Need to set CircularReferenceCounter to > 10
old, CircularReferenceCounter = CircularReferenceCounter, 20
defer func() { CircularReferenceCounter = old }()

loader := NewLoader()
doc, err := loader.LoadFromFile("testdata/issue796.yml")
require.NoError(t, err)
Expand Down
14 changes: 14 additions & 0 deletions openapi3/load_cicular_ref_with_external_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ func TestLoadCircularRefFromFile(t *testing.T) {
bar.Value.Properties["foo"] = &openapi3.SchemaRef{Ref: "#/components/schemas/Foo", Value: foo.Value}
foo.Value.Properties["bar"] = &openapi3.SchemaRef{Ref: "#/components/schemas/Bar", Value: bar.Value}

bazNestedRef := &openapi3.SchemaRef{Ref: "./baz.yml#/BazNested"}
array := openapi3.NewArraySchema()
array.Items = bazNestedRef
bazNested := &openapi3.Schema{Properties: map[string]*openapi3.SchemaRef{
"bazArray": {
Value: &openapi3.Schema{
Items: bazNestedRef,
},
},
"baz": bazNestedRef,
}}
bazNestedRef.Value = bazNested

want := &openapi3.T{
OpenAPI: "3.0.3",
Info: &openapi3.Info{
Expand All @@ -57,6 +70,7 @@ func TestLoadCircularRefFromFile(t *testing.T) {
Schemas: openapi3.Schemas{
"Foo": foo,
"Bar": bar,
"Baz": bazNestedRef,
},
},
}
Expand Down
Loading

0 comments on commit 1871e49

Please sign in to comment.