Skip to content

Commit

Permalink
test: add assertion to load_cicular_ref_with_external_file_test
Browse files Browse the repository at this point in the history
  • Loading branch information
masu-mi committed Aug 29, 2022
1 parent a133d7f commit d30c95f
Showing 1 changed file with 54 additions and 3 deletions.
57 changes: 54 additions & 3 deletions openapi3/load_cicular_ref_with_external_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package openapi3_test

import (
"embed"
"fmt"
"net/url"
"testing"

"github.com/getkin/kin-openapi/openapi3"
"github.com/stretchr/testify/require"
)

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

doc, err := loader.LoadFromFile("testdata/circularRef/base.yml")
got, err := loader.LoadFromFile("testdata/circularRef/base.yml")
if err != nil {
t.Error(err)
}
fmt.Printf("%v\n", doc)

foo := &openapi3.SchemaRef{
Ref: "",
Value: &openapi3.Schema{
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
Properties: map[string]*openapi3.SchemaRef{
"foo2": { // reference to an external file
Ref: "other.yml#/components/schemas/Foo2",
Value: &openapi3.Schema{
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
Properties: map[string]*openapi3.SchemaRef{
"id": {
Value: &openapi3.Schema{
Type: "string",
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
}},
},
},
},
},
},
}
bar := &openapi3.SchemaRef{
Ref: "",
Value: &openapi3.Schema{
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
Properties: map[string]*openapi3.SchemaRef{},
},
}
// circular reference
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}

want := &openapi3.T{
OpenAPI: "3.0.3",
Info: &openapi3.Info{
Title: "Recursive cyclic refs example",
Version: "1.0",

ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
},
Components: openapi3.Components{
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
Schemas: map[string]*openapi3.SchemaRef{
"Foo": foo,
"Bar": bar,
},
},
ExtensionProps: openapi3.ExtensionProps{Extensions: map[string]interface{}{}},
}

require.Equal(t, want, got)
}

0 comments on commit d30c95f

Please sign in to comment.