mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 20:47:44 +00:00
now things are robust, we can move things around a little to prepare for the next set of incoming models. The extraction and builder functions have all been moved to the low packakge, and out of the v3 package.
36 lines
830 B
Go
36 lines
830 B
Go
package datamodel
|
|
|
|
import (
|
|
"github.com/pb33f/libopenapi/datamodel/low"
|
|
"github.com/pb33f/libopenapi/datamodel/low/3.0"
|
|
"github.com/pb33f/libopenapi/index"
|
|
"github.com/stretchr/testify/assert"
|
|
"gopkg.in/yaml.v3"
|
|
"testing"
|
|
)
|
|
|
|
func TestExternalDoc_Build(t *testing.T) {
|
|
|
|
yml := `url: https://pb33f.io
|
|
description: the ranch
|
|
x-b33f: princess`
|
|
|
|
var idxNode yaml.Node
|
|
mErr := yaml.Unmarshal([]byte(yml), &idxNode)
|
|
assert.NoError(t, mErr)
|
|
idx := index.NewSpecIndex(&idxNode)
|
|
|
|
var n v3.ExternalDoc
|
|
err := low.BuildModel(&idxNode, &n)
|
|
assert.NoError(t, err)
|
|
|
|
err = n.Build(idxNode.Content[0], idx)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, "https://pb33f.io", n.URL.Value)
|
|
assert.Equal(t, "the ranch", n.Description.Value)
|
|
ext := n.FindExtension("x-b33f")
|
|
assert.NotNil(t, ext)
|
|
assert.Equal(t, "princess", ext.Value)
|
|
|
|
}
|