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
19 changes: 2 additions & 17 deletions compilers/openapi/cycles_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package openapi

import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -16,6 +14,7 @@ import (
"github.com/dexpace/morphic/compilers/openapi/internal/openapitest"
"github.com/dexpace/morphic/compilers/openapi/internal/scan"
"github.com/dexpace/morphic/compilers/openapi/internal/sourceindex"
"github.com/dexpace/morphic/compilers/openapi/internal/ynode"
"github.com/dexpace/morphic/ir"
)

Expand Down Expand Up @@ -292,24 +291,10 @@ func readReproducer(t *testing.T, file string) []byte {
return data
}

func mergeChainSpec(levels int) string {
var b strings.Builder
b.WriteString("openapi: 3.1.0\ninfo: {title: t, version: '1'}\npaths: {}\nx-anchors:\n")
b.WriteString(" m0: &m0 {type: object}\n")
for i := 1; i <= levels; i++ {
fmt.Fprintf(&b, " m%d: &m%d {<<: *m%d, p%d: %d}\n", i, i, i-1, i, i)
}
b.WriteString("components:\n schemas:\n")
for i := levels; i >= 0; i-- {
fmt.Fprintf(&b, " S%d: {properties: {x: *m%d}}\n", i, i)
}
return b.String()
}

func TestCompile_MergeChainPastBoundStillCompiles(t *testing.T) {
t.Parallel()
doc, diags, err := New().Compile(t.Context(),
[]compilers.Source{{Path: "deep-merge.yaml", Data: []byte(mergeChainSpec(200))}},
[]compilers.Source{{Path: "deep-merge.yaml", Data: []byte(ynode.MergeChainSpec(200))}},
compilers.Options{})
require.NoError(t, err)
require.NotNil(t, doc, "a legal document is still compiled")
Expand Down
7 changes: 2 additions & 5 deletions compilers/openapi/internal/nodeview/nodeview.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
yaml "gopkg.in/yaml.v3"

"github.com/dexpace/morphic/compilers/openapi/internal/ids"
"github.com/dexpace/morphic/compilers/openapi/internal/ynode"
)

// maxAliasChain bounds how many alias hops Deref follows. yaml.v3 resolves an
Expand Down Expand Up @@ -270,10 +271,6 @@ func (v *View) mergeSource(val *yaml.Node, depth int) ([]Pair, bool) {
return dedupeFirstWins(out), complete
}

// MergeTag is the tag yaml.v3 resolves every `<<` merge key to, and the exact
// tag speakeasy's yml.IsMergeKey requires before treating one as a merge.
const MergeTag = "!!merge"

// IsMergeKey reports whether a raw mapping key node is a `<<` merge key,
// applying the same test speakeasy does: yml.IsMergeKey (yml/yml.go), run over
// every mapping via yml.ResolveMergeKeys. The key is checked undereferenced (an
Expand All @@ -288,7 +285,7 @@ const MergeTag = "!!merge"
// reachable from a parsed document today, but re-check this against
// yml.IsMergeKey on any dependency bump.
func IsMergeKey(n *yaml.Node) bool {
return n != nil && n.Kind == yaml.ScalarNode && n.Value == "<<" && n.Tag == MergeTag
return n != nil && n.Kind == yaml.ScalarNode && n.Value == "<<" && n.Tag == ynode.MergeTag
}

// dedupeFirstWins keeps only the first pair for each key, preserving order — the
Expand Down
Loading
Loading