mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 20:47:49 +00:00
An enormous amount of surgery on the low level model.
Every `Build()` method now requires a `context.Context`. This is so the rolodex knows where to resolve from when locating relative links. Without knowing where we are, there is no way to resolve anything. This new mechanism allows the model to recurse across as many files as required to locate references, without loosing track of where we are in the process. Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -4,15 +4,14 @@
|
||||
package low
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
func TestFindItemInMap(t *testing.T) {
|
||||
@@ -1570,38 +1569,6 @@ func TestExtractMapFlat_Ref_Bad(t *testing.T) {
|
||||
assert.Len(t, things, 0)
|
||||
}
|
||||
|
||||
func TestLocateRefNode_RemoteFile(t *testing.T) {
|
||||
|
||||
ymlFile := fmt.Sprintf(`components:
|
||||
schemas:
|
||||
hey:
|
||||
$ref: '%s#/components/schemas/hey'`, "remote.yaml")
|
||||
|
||||
ymlRemote := `components:
|
||||
schemas:
|
||||
hey:
|
||||
AlmostWork: 999`
|
||||
|
||||
_ = os.WriteFile("remote.yaml", []byte(ymlRemote), 0665)
|
||||
defer os.Remove("remote.yaml")
|
||||
|
||||
ymlLocal := `$ref: '#/components/schemas/hey'`
|
||||
|
||||
var idxNode yaml.Node
|
||||
mErr := yaml.Unmarshal([]byte(ymlFile), &idxNode) // an empty index.
|
||||
assert.NoError(t, mErr)
|
||||
idx := index.NewSpecIndexWithConfig(&idxNode, index.CreateOpenAPIIndexConfig())
|
||||
|
||||
var cNode yaml.Node
|
||||
e := yaml.Unmarshal([]byte(ymlLocal), &cNode)
|
||||
assert.NoError(t, e)
|
||||
|
||||
things, _, _, err := ExtractMap[*test_Good]("one", cNode.Content[0], idx)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, things, 1)
|
||||
|
||||
}
|
||||
|
||||
func TestExtractExtensions(t *testing.T) {
|
||||
|
||||
yml := `x-bing: ding
|
||||
|
||||
Reference in New Issue
Block a user