Skip to content

Commit d30c95f

Browse files
committed
test: add assertion to load_cicular_ref_with_external_file_test
1 parent a133d7f commit d30c95f

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

openapi3/load_cicular_ref_with_external_file_test.go

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ package openapi3_test
55

66
import (
77
"embed"
8-
"fmt"
98
"net/url"
109
"testing"
1110

1211
"github.com/getkin/kin-openapi/openapi3"
12+
"github.com/stretchr/testify/require"
1313
)
1414

1515
//go:embed testdata/circularRef/*
@@ -22,9 +22,60 @@ func TestLoadCircularRefFromFile(t *testing.T) {
2222
return circularResSpecs.ReadFile(uri.Path)
2323
}
2424

25-
doc, err := loader.LoadFromFile("testdata/circularRef/base.yml")
25+
got, err := loader.LoadFromFile("testdata/circularRef/base.yml")
2626
if err != nil {
2727
t.Error(err)
2828
}
29-
fmt.Printf("%v\n", doc)
29+
30+
foo := &openapi3.SchemaRef{
31+
Ref: "",
32+
Value: &openapi3.Schema{
33+
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
34+
Properties: map[string]*openapi3.SchemaRef{
35+
"foo2": { // reference to an external file
36+
Ref: "other.yml#/components/schemas/Foo2",
37+
Value: &openapi3.Schema{
38+
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
39+
Properties: map[string]*openapi3.SchemaRef{
40+
"id": {
41+
Value: &openapi3.Schema{
42+
Type: "string",
43+
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
44+
}},
45+
},
46+
},
47+
},
48+
},
49+
},
50+
}
51+
bar := &openapi3.SchemaRef{
52+
Ref: "",
53+
Value: &openapi3.Schema{
54+
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
55+
Properties: map[string]*openapi3.SchemaRef{},
56+
},
57+
}
58+
// circular reference
59+
bar.Value.Properties["foo"] = &openapi3.SchemaRef{Ref: "#/components/schemas/Foo", Value: foo.Value}
60+
foo.Value.Properties["bar"] = &openapi3.SchemaRef{Ref: "#/components/schemas/Bar", Value: bar.Value}
61+
62+
want := &openapi3.T{
63+
OpenAPI: "3.0.3",
64+
Info: &openapi3.Info{
65+
Title: "Recursive cyclic refs example",
66+
Version: "1.0",
67+
68+
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
69+
},
70+
Components: openapi3.Components{
71+
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
72+
Schemas: map[string]*openapi3.SchemaRef{
73+
"Foo": foo,
74+
"Bar": bar,
75+
},
76+
},
77+
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
78+
}
79+
80+
require.Equal(t, want, got)
3081
}

0 commit comments

Comments
 (0)