mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
Building out schema comparison mechanism
Which has led to a new wider hashing capability for the low level API. hashing makes it very easy to determine changes quickly, without having to run comparisons to discover changes, could really speed things up moving forward.
This commit is contained in:
@@ -1208,3 +1208,100 @@ func TestExtractSchema_OneOfRef(t *testing.T) {
|
||||
res.Value.Schema().OneOf.Value[0].Value.Schema().Description.Value)
|
||||
|
||||
}
|
||||
|
||||
func TestSchema_Hash_Equal(t *testing.T) {
|
||||
|
||||
left := `schema:
|
||||
title: an OK message
|
||||
properties:
|
||||
propA:
|
||||
title: a proxy property
|
||||
type: string`
|
||||
|
||||
right := `schema:
|
||||
title: an OK message
|
||||
properties:
|
||||
propA:
|
||||
title: a proxy property
|
||||
type: string`
|
||||
|
||||
var lNode, rNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(left), &lNode)
|
||||
_ = yaml.Unmarshal([]byte(right), &rNode)
|
||||
|
||||
lDoc, _ := ExtractSchema(lNode.Content[0], nil)
|
||||
rDoc, _ := ExtractSchema(rNode.Content[0], nil)
|
||||
|
||||
assert.NotNil(t, lDoc)
|
||||
assert.NotNil(t, rDoc)
|
||||
|
||||
lHash := lDoc.Value.Schema().Hash()
|
||||
rHash := rDoc.Value.Schema().Hash()
|
||||
|
||||
assert.Equal(t, lHash, rHash)
|
||||
|
||||
}
|
||||
|
||||
func TestSchema_Hash_NotEqual(t *testing.T) {
|
||||
|
||||
left := `schema:
|
||||
title: an OK message - but different
|
||||
properties:
|
||||
propA:
|
||||
title: a proxy property
|
||||
type: string`
|
||||
|
||||
right := `schema:
|
||||
title: an OK message
|
||||
properties:
|
||||
propA:
|
||||
title: a proxy property
|
||||
type: string`
|
||||
|
||||
var lNode, rNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(left), &lNode)
|
||||
_ = yaml.Unmarshal([]byte(right), &rNode)
|
||||
|
||||
lDoc, _ := ExtractSchema(lNode.Content[0], nil)
|
||||
rDoc, _ := ExtractSchema(rNode.Content[0], nil)
|
||||
|
||||
assert.False(t, low.AreEqual(lDoc.Value.Schema(), rDoc.Value.Schema()))
|
||||
}
|
||||
|
||||
func TestSchema_Hash_EqualJumbled(t *testing.T) {
|
||||
|
||||
left := `schema:
|
||||
title: an OK message
|
||||
description: a nice thing.
|
||||
properties:
|
||||
propZ:
|
||||
type: int
|
||||
propK:
|
||||
description: a prop!
|
||||
type: bool
|
||||
propA:
|
||||
title: a proxy property
|
||||
type: string`
|
||||
|
||||
right := `schema:
|
||||
description: a nice thing.
|
||||
properties:
|
||||
propA:
|
||||
type: string
|
||||
title: a proxy property
|
||||
propK:
|
||||
type: bool
|
||||
description: a prop!
|
||||
propZ:
|
||||
type: int
|
||||
title: an OK message`
|
||||
|
||||
var lNode, rNode yaml.Node
|
||||
_ = yaml.Unmarshal([]byte(left), &lNode)
|
||||
_ = yaml.Unmarshal([]byte(right), &rNode)
|
||||
|
||||
lDoc, _ := ExtractSchema(lNode.Content[0], nil)
|
||||
rDoc, _ := ExtractSchema(rNode.Content[0], nil)
|
||||
assert.True(t, low.AreEqual(lDoc.Value.Schema(), rDoc.Value.Schema()))
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user