@@ -5,6 +5,7 @@ package openapi3_test
55
66import (
77 "embed"
8+ "encoding/json"
89 "net/url"
910 "testing"
1011
@@ -24,38 +25,24 @@ func TestLoadCircularRefFromFile(t *testing.T) {
2425 }
2526
2627 got , err := loader .LoadFromFile ("testdata/circularRef/base.yml" )
27- if err != nil {
28- t .Error (err )
29- }
28+ require .NoError (t , err )
3029
3130 foo := & openapi3.SchemaRef {
32- Ref : "" ,
3331 Value : & openapi3.Schema {
34- ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
3532 Properties : map [string ]* openapi3.SchemaRef {
36- "foo2" : { // reference to an external file
37- Ref : "other.yml#/components/schemas/Foo2" ,
33+ "foo2" : {
34+ Ref : "other.yml#/components/schemas/Foo2" , // reference to an external file
3835 Value : & openapi3.Schema {
39- ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
4036 Properties : map [string ]* openapi3.SchemaRef {
4137 "id" : {
42- Value : & openapi3.Schema {
43- Type : "string" ,
44- ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
45- }},
38+ Value : & openapi3.Schema {Type : "string" }},
4639 },
4740 },
4841 },
4942 },
5043 },
5144 }
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- }
45+ bar := & openapi3.SchemaRef {Value : & openapi3.Schema {Properties : make (map [string ]* openapi3.SchemaRef )}}
5946 // circular reference
6047 bar .Value .Properties ["foo" ] = & openapi3.SchemaRef {Ref : "#/components/schemas/Foo" , Value : foo .Value }
6148 foo .Value .Properties ["bar" ] = & openapi3.SchemaRef {Ref : "#/components/schemas/Bar" , Value : bar .Value }
@@ -65,18 +52,19 @@ func TestLoadCircularRefFromFile(t *testing.T) {
6552 Info : & openapi3.Info {
6653 Title : "Recursive cyclic refs example" ,
6754 Version : "1.0" ,
68-
69- ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
7055 },
7156 Components : openapi3.Components {
72- ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
7357 Schemas : map [string ]* openapi3.SchemaRef {
7458 "Foo" : foo ,
7559 "Bar" : bar ,
7660 },
7761 },
78- ExtensionProps : openapi3.ExtensionProps {Extensions : map [string ]interface {}{}},
7962 }
8063
81- require .Equal (t , want , got )
64+ jsoner := func (doc * openapi3.T ) string {
65+ data , err := json .Marshal (doc )
66+ require .NoError (t , err )
67+ return string (data )
68+ }
69+ require .JSONEq (t , jsoner (want ), jsoner (got ))
8270}
0 commit comments