Skip to content

Commit efe7ae9

Browse files
authored
cleanup after #583 (#585)
1 parent 2470727 commit efe7ae9

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

openapi3/load_cicular_ref_with_external_file_test.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package openapi3_test
55

66
import (
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
}

openapi3/loader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,7 @@ func (loader *Loader) resolveSchemaRef(doc *T, component *SchemaRef, documentPat
748748
}
749749

750750
func (loader *Loader) getResolvedRefPath(ref string, resolved *SchemaRef, cur, found *url.URL) string {
751-
referencedFilename := strings.Split(ref, "#")[0]
752-
if referencedFilename == "" {
751+
if referencedFilename := strings.Split(ref, "#")[0]; referencedFilename == "" {
753752
if cur != nil {
754753
return path.Base(cur.Path)
755754
}

0 commit comments

Comments
 (0)