@@ -5,10 +5,11 @@ package openapi3_test
55
66import (
77 "embed"
8- "fmt"
98 "net/url"
109 "testing"
1110
11+ "github.com/stretchr/testify/require"
12+
1213 "github.com/getkin/kin-openapi/openapi3"
1314)
1415
@@ -22,9 +23,60 @@ func TestLoadCircularRefFromFile(t *testing.T) {
2223 return circularResSpecs .ReadFile (uri .Path )
2324 }
2425
25- doc , err := loader .LoadFromFile ("testdata/circularRef/base.yml" )
26+ got , err := loader .LoadFromFile ("testdata/circularRef/base.yml" )
2627 if err != nil {
2728 t .Error (err )
2829 }
29- fmt .Printf ("%v\n " , doc )
30+
31+ foo := & openapi3.SchemaRef {
32+ Ref : "" ,
33+ Value : & openapi3.Schema {
34+ ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
35+ Properties : map [string ]* openapi3.SchemaRef {
36+ "foo2" : { // reference to an external file
37+ Ref : "other.yml#/components/schemas/Foo2" ,
38+ Value : & openapi3.Schema {
39+ ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
40+ Properties : map [string ]* openapi3.SchemaRef {
41+ "id" : {
42+ Value : & openapi3.Schema {
43+ Type : "string" ,
44+ ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
45+ }},
46+ },
47+ },
48+ },
49+ },
50+ },
51+ }
52+ bar := & openapi3.SchemaRef {
53+ Ref : "" ,
54+ Value : & openapi3.Schema {
55+ ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
56+ Properties : map [string ]* openapi3.SchemaRef {},
57+ },
58+ }
59+ // circular reference
60+ bar .Value .Properties ["foo" ] = & openapi3.SchemaRef {Ref : "#/components/schemas/Foo" , Value : foo .Value }
61+ foo .Value .Properties ["bar" ] = & openapi3.SchemaRef {Ref : "#/components/schemas/Bar" , Value : bar .Value }
62+
63+ want := & openapi3.T {
64+ OpenAPI : "3.0.3" ,
65+ Info : & openapi3.Info {
66+ Title : "Recursive cyclic refs example" ,
67+ Version : "1.0" ,
68+
69+ ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
70+ },
71+ Components : openapi3.Components {
72+ ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
73+ Schemas : map [string ]* openapi3.SchemaRef {
74+ "Foo" : foo ,
75+ "Bar" : bar ,
76+ },
77+ },
78+ ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
79+ }
80+
81+ require .Equal (t , want , got )
3082}
0 commit comments