diff --git a/datamodel/high/base/contact_test.go b/datamodel/high/base/contact_test.go new file mode 100644 index 0000000..4cb0970 --- /dev/null +++ b/datamodel/high/base/contact_test.go @@ -0,0 +1,36 @@ +// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley +// SPDX-License-Identifier: MIT + +package base + +import ( + lowmodel "github.com/pb33f/libopenapi/datamodel/low" + lowbase "github.com/pb33f/libopenapi/datamodel/low/base" + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v3" + "testing" +) + +func TestNewContact(t *testing.T) { + + var cNode yaml.Node + + yml := `name: pizza +url: https://pb33f.io +email: buckaroo@pb33f.io` + + _ = yaml.Unmarshal([]byte(yml), &cNode) + + // build low + var lowContact lowbase.Contact + _ = lowmodel.BuildModel(&cNode, &lowContact) + + // build high + highContact := NewContact(&lowContact) + + assert.Equal(t, "pizza", highContact.Name) + assert.Equal(t, "https://pb33f.io", highContact.URL) + assert.Equal(t, "buckaroo@pb33f.io", highContact.Email) + assert.Equal(t, 1, highContact.GoLow().Name.KeyNode.Line) + +} diff --git a/datamodel/high/base/discriminator_test.go b/datamodel/high/base/discriminator_test.go new file mode 100644 index 0000000..2a7e5db --- /dev/null +++ b/datamodel/high/base/discriminator_test.go @@ -0,0 +1,35 @@ +// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley +// SPDX-License-Identifier: MIT + +package base + +import ( + lowmodel "github.com/pb33f/libopenapi/datamodel/low" + lowbase "github.com/pb33f/libopenapi/datamodel/low/base" + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v3" + "testing" +) + +func TestNewDiscriminator(t *testing.T) { + + var cNode yaml.Node + + yml := `propertyName: coffee +mapping: + fogCleaner: in the morning` + + _ = yaml.Unmarshal([]byte(yml), &cNode) + + // build low + var lowDiscriminator lowbase.Discriminator + _ = lowmodel.BuildModel(&cNode, &lowDiscriminator) + + // build high + highDiscriminator := NewDiscriminator(&lowDiscriminator) + + assert.Equal(t, "coffee", highDiscriminator.PropertyName) + assert.Equal(t, "in the morning", highDiscriminator.Mapping["fogCleaner"]) + assert.Equal(t, 3, highDiscriminator.GoLow().FindMappingValue("fogCleaner").ValueNode.Line) + +} diff --git a/datamodel/high/base/example.go b/datamodel/high/base/example.go index 4475522..36d3e0e 100644 --- a/datamodel/high/base/example.go +++ b/datamodel/high/base/example.go @@ -23,7 +23,7 @@ func NewExample(example *low.Example) *Example { e.low = example e.Summary = example.Summary.Value e.Description = example.Description.Value - e.Value = example.Value + e.Value = example.Value.Value e.ExternalValue = example.ExternalValue.Value e.Extensions = high.ExtractExtensions(example.Extensions) return e diff --git a/datamodel/high/base/example_test.go b/datamodel/high/base/example_test.go new file mode 100644 index 0000000..e27641d --- /dev/null +++ b/datamodel/high/base/example_test.go @@ -0,0 +1,41 @@ +// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley +// SPDX-License-Identifier: MIT + +package base + +import ( + lowmodel "github.com/pb33f/libopenapi/datamodel/low" + lowbase "github.com/pb33f/libopenapi/datamodel/low/base" + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v3" + "testing" +) + +func TestNewExample(t *testing.T) { + + var cNode yaml.Node + + yml := `summary: an example +description: something more +value: a thing +externalValue: https://pb33f.io +x-hack: code` + + _ = yaml.Unmarshal([]byte(yml), &cNode) + + // build low + var lowExample lowbase.Example + _ = lowmodel.BuildModel(&cNode, &lowExample) + + _ = lowExample.Build(cNode.Content[0], nil) + + // build high + highExample := NewExample(&lowExample) + + assert.Equal(t, "an example", highExample.Summary) + assert.Equal(t, "something more", highExample.Description) + assert.Equal(t, "https://pb33f.io", highExample.ExternalValue) + assert.Equal(t, "code", highExample.Extensions["x-hack"]) + assert.Equal(t, "a thing", highExample.Value) + assert.Equal(t, 4, highExample.GoLow().ExternalValue.ValueNode.Line) +} diff --git a/datamodel/low/2.0/parameter_test.go b/datamodel/low/2.0/parameter_test.go new file mode 100644 index 0000000..47dbece --- /dev/null +++ b/datamodel/low/2.0/parameter_test.go @@ -0,0 +1,49 @@ +// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley +// SPDX-License-Identifier: MIT + +package v2 + +import ( + "github.com/pb33f/libopenapi/datamodel/low" + "github.com/pb33f/libopenapi/index" + "github.com/stretchr/testify/assert" + "gopkg.in/yaml.v3" + "testing" +) + +func TestParameter_Build(t *testing.T) { + + yml := `$ref: break` + + var idxNode yaml.Node + mErr := yaml.Unmarshal([]byte(yml), &idxNode) + assert.NoError(t, mErr) + idx := index.NewSpecIndex(&idxNode) + + var n Parameter + err := low.BuildModel(&idxNode, &n) + assert.NoError(t, err) + + err = n.Build(idxNode.Content[0], idx) + assert.Error(t, err) + +} + +func TestParameter_Build_Items(t *testing.T) { + + yml := `items: + $ref: break` + + var idxNode yaml.Node + mErr := yaml.Unmarshal([]byte(yml), &idxNode) + assert.NoError(t, mErr) + idx := index.NewSpecIndex(&idxNode) + + var n Parameter + err := low.BuildModel(&idxNode, &n) + assert.NoError(t, err) + + err = n.Build(idxNode.Content[0], idx) + assert.Error(t, err) + +}