mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
Added support for unevaluatedProperties as Schema and bool #118
Also ran `gofmt` across the entire project. Things need cleaning up. Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
@@ -4,17 +4,17 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strings"
|
||||
"testing"
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
lowbase "github.com/pb33f/libopenapi/datamodel/low/base"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSchemaProxy_MarshalYAML(t *testing.T) {
|
||||
const ymlComponents = `components:
|
||||
const ymlComponents = `components:
|
||||
schemas:
|
||||
rice:
|
||||
type: string
|
||||
@@ -27,42 +27,41 @@ func TestSchemaProxy_MarshalYAML(t *testing.T) {
|
||||
rice:
|
||||
$ref: '#/components/schemas/rice'`
|
||||
|
||||
idx := func() *index.SpecIndex {
|
||||
var idxNode yaml.Node
|
||||
err := yaml.Unmarshal([]byte(ymlComponents), &idxNode)
|
||||
assert.NoError(t, err)
|
||||
return index.NewSpecIndexWithConfig(&idxNode, index.CreateOpenAPIIndexConfig())
|
||||
}()
|
||||
idx := func() *index.SpecIndex {
|
||||
var idxNode yaml.Node
|
||||
err := yaml.Unmarshal([]byte(ymlComponents), &idxNode)
|
||||
assert.NoError(t, err)
|
||||
return index.NewSpecIndexWithConfig(&idxNode, index.CreateOpenAPIIndexConfig())
|
||||
}()
|
||||
|
||||
const ref = "#/components/schemas/nice"
|
||||
const ymlSchema = `$ref: '` + ref + `'`
|
||||
var node yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(ymlSchema), &node)
|
||||
const ref = "#/components/schemas/nice"
|
||||
const ymlSchema = `$ref: '` + ref + `'`
|
||||
var node yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(ymlSchema), &node)
|
||||
|
||||
lowProxy := new(lowbase.SchemaProxy)
|
||||
err := lowProxy.Build(node.Content[0], idx)
|
||||
assert.NoError(t, err)
|
||||
lowProxy := new(lowbase.SchemaProxy)
|
||||
err := lowProxy.Build(node.Content[0], idx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
lowRef := low.NodeReference[*lowbase.SchemaProxy]{
|
||||
Value: lowProxy,
|
||||
}
|
||||
lowRef := low.NodeReference[*lowbase.SchemaProxy]{
|
||||
Value: lowProxy,
|
||||
}
|
||||
|
||||
sp := NewSchemaProxy(&lowRef)
|
||||
sp := NewSchemaProxy(&lowRef)
|
||||
|
||||
rend, _ := sp.Render()
|
||||
assert.Equal(t, "$ref: '#/components/schemas/nice'", strings.TrimSpace(string(rend)))
|
||||
rend, _ := sp.Render()
|
||||
assert.Equal(t, "$ref: '#/components/schemas/nice'", strings.TrimSpace(string(rend)))
|
||||
|
||||
}
|
||||
|
||||
func TestCreateSchemaProxy(t *testing.T) {
|
||||
sp := CreateSchemaProxy(&Schema{Description: "iAmASchema"})
|
||||
assert.Equal(t, "iAmASchema", sp.rendered.Description)
|
||||
assert.False(t, sp.IsReference())
|
||||
sp := CreateSchemaProxy(&Schema{Description: "iAmASchema"})
|
||||
assert.Equal(t, "iAmASchema", sp.rendered.Description)
|
||||
assert.False(t, sp.IsReference())
|
||||
}
|
||||
|
||||
func TestCreateSchemaProxyRef(t *testing.T) {
|
||||
sp := CreateSchemaProxyRef("#/components/schemas/MySchema")
|
||||
assert.Equal(t, "#/components/schemas/MySchema", sp.GetReference())
|
||||
assert.True(t, sp.IsReference())
|
||||
sp := CreateSchemaProxyRef("#/components/schemas/MySchema")
|
||||
assert.Equal(t, "#/components/schemas/MySchema", sp.GetReference())
|
||||
assert.True(t, sp.IsReference())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user