Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions datamodel/low/base/schema_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ func (sp *SchemaProxy) computeHash() uint64 {
if !sp.IsReference() {
return sch.Hash()
}
if cfg := sp.getSpecConfig(); cfg != nil && cfg.UseSchemaQuickHash && !CheckSchemaProxyForCircularRefs(sp) {
return sch.QuickHash()
}
return sp.hashReference()
}

Expand Down
16 changes: 16 additions & 0 deletions datamodel/low/base/schema_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,22 @@ func TestSchemaProxy_QuickHash_BuildsOnMiss(t *testing.T) {
assert.Equal(t, built.quickHashKey(), quickHashKeyOf(sp.idx, sp.idx, sp.vn))
}

func TestSchemaProxyQuickHashIndependentOfModelAccess(t *testing.T) {
ClearSchemaQuickHashMap()
defer ClearSchemaQuickHashMap()
for _, spec := range []string{"type: string\n", "type: integer\n"} {
cold := quickHashRefProxy(t, spec, &index.SpecIndexConfig{})
warm := quickHashRefProxy(t, spec, &index.SpecIndexConfig{})
require.NotNil(t, warm.Schema())
assert.Equal(t, cold.Hash(), warm.Hash())
}
left := quickHashRefProxy(t, "type: string\n", &index.SpecIndexConfig{})
right := quickHashRefProxy(t, "type: integer\n", &index.SpecIndexConfig{})
require.NotNil(t, left.Schema())
require.NotNil(t, right.Schema())
assert.NotEqual(t, left.Hash(), right.Hash())
}

func TestSchemaProxy_CachedQuickHash_Declines(t *testing.T) {
ClearSchemaQuickHashMap()
defer ClearSchemaQuickHashMap()
Expand Down
4 changes: 2 additions & 2 deletions datamodel/spec_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ func extractSpecInfoInternal(spec []byte, bypass bool, skipJSON bool) (*SpecInfo
}
parsed = true

// so far there is only 2 as a major release of AsyncAPI
if majorVersion > 2 {
// Detect supported AsyncAPI versions; model construction belongs to libasyncapi.
if majorVersion > 3 {
if !bypass {
specInfo.Error = errors.New("spec is defined as asyncapi, but has a major version that is invalid")
return specInfo, specInfo.Error
Expand Down
18 changes: 18 additions & 0 deletions datamodel/spec_info_asyncapi3_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package datamodel

import (
"github.com/pb33f/testify/require"
"testing"
)

func TestExtractSpecInfoAsyncAPI3(t *testing.T) {
for _, spec := range []string{"asyncapi: 3.0.0\ninfo: {title: Events, version: 1.0.0}\n", `{"asyncapi":"3.0.0","info":{"title":"Events","version":"1.0.0"}}`} {
info, err := ExtractSpecInfo([]byte(spec))
require.NoError(t, err)
require.Equal(t, "asyncapi", info.SpecType)
require.Equal(t, "3.0.0", info.Version)
require.NotNil(t, info.RootNode)
}
_, err := ExtractSpecInfo([]byte("asyncapi: 3.0.0\nasyncapi: 3.0.0\n"))
require.Error(t, err)
}
2 changes: 1 addition & 1 deletion datamodel/spec_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ channels:
type: string
pattern: '^hello .+$'`

var AsyncAPISpecOdd = `asyncapi: 3.0.0
var AsyncAPISpecOdd = `asyncapi: 4.0.0
info:
title: Hello world application
version: '0.1.0'`
Expand Down
Loading