mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 12:37:48 +00:00
Added more base components to mutable state.
Chopping through the list.
This commit is contained in:
@@ -7,7 +7,10 @@ import (
|
||||
"fmt"
|
||||
lowmodel "github.com/pb33f/libopenapi/datamodel/low"
|
||||
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func ExampleNewXML() {
|
||||
@@ -16,7 +19,10 @@ func ExampleNewXML() {
|
||||
// this can be either JSON or YAML.
|
||||
yml := `
|
||||
namespace: https://pb33f.io/schema
|
||||
prefix: sample`
|
||||
name: something
|
||||
attribute: true
|
||||
prefix: sample
|
||||
wrapped: true`
|
||||
|
||||
// unmarshal raw bytes
|
||||
var node yaml.Node
|
||||
@@ -34,3 +40,35 @@ prefix: sample`
|
||||
fmt.Print(highXML.Namespace)
|
||||
// Output: https://pb33f.io/schema
|
||||
}
|
||||
|
||||
func TestContact_Render(t *testing.T) {
|
||||
|
||||
// create an example schema object
|
||||
// this can be either JSON or YAML.
|
||||
yml := `namespace: https://pb33f.io/schema
|
||||
name: something
|
||||
attribute: true
|
||||
prefix: sample
|
||||
wrapped: true`
|
||||
|
||||
// unmarshal raw bytes
|
||||
var node yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(yml), &node)
|
||||
|
||||
// build out the low-level model
|
||||
var lowXML lowbase.XML
|
||||
_ = lowmodel.BuildModel(node.Content[0], &lowXML)
|
||||
_ = lowXML.Build(node.Content[0], nil)
|
||||
|
||||
// build the high level tag
|
||||
highXML := NewXML(&lowXML)
|
||||
|
||||
// print out the XML doc
|
||||
highXMLBytes, _ := highXML.Render()
|
||||
assert.Equal(t, yml, strings.TrimSpace(string(highXMLBytes)))
|
||||
|
||||
highXML.Attribute = false
|
||||
highXMLBytes, _ = highXML.Render()
|
||||
assert.NotEqual(t, yml, strings.TrimSpace(string(highXMLBytes)))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user