fix: continued moving everything to orderedmaps plus cleaned up most the tests

This commit is contained in:
Tristan Cartledge
2023-12-01 17:37:07 +00:00
parent 0f3d0cb28f
commit a4ad09aab3
169 changed files with 3435 additions and 3764 deletions

View File

@@ -5,15 +5,16 @@ package base
import (
"context"
"testing"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/orderedmap"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
"testing"
)
func TestSchemaProxy_Build(t *testing.T) {
yml := `x-windows: washed
description: something`
@@ -24,29 +25,25 @@ description: something`
err := sch.Build(context.Background(), &idxNode, idxNode.Content[0], nil)
assert.NoError(t, err)
assert.Equal(t, "db2a35dd6fb3d9481d0682571b9d687616bb2a34c1887f7863f0b2e769ca7b23",
assert.Equal(t, "e20c009d370944d177c0b46e8fa29e15fadc3a6f9cca6bb251ff9e120265fc96",
low.GenerateHashString(&sch))
assert.Equal(t, "something", sch.Schema().Description.Value)
assert.Empty(t, sch.GetSchemaReference())
assert.Equal(t, "something", sch.Schema().Description.GetValue())
assert.Empty(t, sch.GetReference())
assert.NotNil(t, sch.GetKeyNode())
assert.NotNil(t, sch.GetValueNode())
assert.False(t, sch.IsSchemaReference())
assert.False(t, sch.IsReference())
assert.Empty(t, sch.GetReference())
sch.SetReference("coffee")
sch.SetReference("coffee", nil)
assert.Equal(t, "coffee", sch.GetReference())
// already rendered, should spit out the same
assert.Equal(t, "db2a35dd6fb3d9481d0682571b9d687616bb2a34c1887f7863f0b2e769ca7b23",
assert.Equal(t, "37290d74ac4d186e3a8e5785d259d2ec04fac91ae28092e7620ec8bc99e830aa",
low.GenerateHashString(&sch))
assert.Len(t, sch.Schema().GetExtensions(), 1)
assert.Equal(t, 1, orderedmap.Len(sch.Schema().GetExtensions()))
}
func TestSchemaProxy_Build_CheckRef(t *testing.T) {
yml := `$ref: wat`
var sch SchemaProxy
@@ -55,14 +52,13 @@ func TestSchemaProxy_Build_CheckRef(t *testing.T) {
err := sch.Build(context.Background(), nil, idxNode.Content[0], nil)
assert.NoError(t, err)
assert.True(t, sch.IsSchemaReference())
assert.Equal(t, "wat", sch.GetSchemaReference())
assert.True(t, sch.IsReference())
assert.Equal(t, "wat", sch.GetReference())
assert.Equal(t, "f00a787f7492a95e165b470702f4fe9373583fbdc025b2c8bdf0262cc48fcff4",
low.GenerateHashString(&sch))
}
func TestSchemaProxy_Build_HashInline(t *testing.T) {
yml := `type: int`
var sch SchemaProxy
@@ -71,14 +67,13 @@ func TestSchemaProxy_Build_HashInline(t *testing.T) {
err := sch.Build(context.Background(), nil, idxNode.Content[0], nil)
assert.NoError(t, err)
assert.False(t, sch.IsSchemaReference())
assert.False(t, sch.IsReference())
assert.NotNil(t, sch.Schema())
assert.Equal(t, "6da88c34ba124c41f977db66a4fc5c1a951708d285c81bb0d47c3206f4c27ca8",
low.GenerateHashString(&sch))
}
func TestSchemaProxy_Build_UsingMergeNodes(t *testing.T) {
yml := `
x-common-definitions:
life_cycle_types: &life_cycle_types_def
@@ -95,11 +90,9 @@ x-common-definitions:
assert.NoError(t, err)
assert.Len(t, sch.Schema().Enum.Value, 3)
assert.Equal(t, "The type of life cycle", sch.Schema().Description.Value)
}
func TestSchemaProxy_GetSchemaReferenceLocation(t *testing.T) {
yml := `type: object
properties:
name:
@@ -159,5 +152,4 @@ properties:
err = schC.Build(context.Background(), nil, idxNodeA.Content[0], nil)
origin = schC.GetSchemaReferenceLocation()
assert.Nil(t, origin)
}