mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 12:37:48 +00:00
Refactoring core structure of datamodel to accomodate v2 model.
There is a lot of overlap on these models, to create a much more sensible design, a new 'base' package has been added which contains shared models that both versions make use of.
This commit is contained in:
55
datamodel/low/base/external_doc_test.go
Normal file
55
datamodel/low/base/external_doc_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExternalDoc_FindExtension(t *testing.T) {
|
||||
|
||||
yml := `x-fish: cake`
|
||||
|
||||
var idxNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(yml), &idxNode)
|
||||
idx := index.NewSpecIndex(&idxNode)
|
||||
|
||||
var n ExternalDoc
|
||||
err := low.BuildModel(&idxNode, &n)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = n.Build(idxNode.Content[0], idx)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "cake", n.FindExtension("x-fish").Value)
|
||||
|
||||
}
|
||||
|
||||
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 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)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user