@@ -10,7 +10,6 @@ import (
1010
1111 "github.com/speakeasy-api/jsonpath/pkg/jsonpath"
1212 "github.com/speakeasy-api/jsonpath/pkg/jsonpath/config"
13- "github.com/speakeasy-api/jsonpath/pkg/jsonpath/token"
1413 "github.com/speakeasy-api/openapi/overlay"
1514 "gopkg.in/yaml.v3"
1615)
@@ -34,7 +33,6 @@ func CalculateOverlay(originalYAML, targetYAML, existingOverlay string) (string,
3433 if err != nil {
3534 return "" , fmt .Errorf ("failed to parse overlay schema in CalculateOverlay: %w" , err )
3635 }
37- existingOverlayDocument .JSONPathVersion = "rfc9535" // force this in the playground.
3836 // now modify the original using the existing overlay
3937 err = existingOverlayDocument .ApplyTo (& orig )
4038 if err != nil {
@@ -46,8 +44,16 @@ func CalculateOverlay(originalYAML, targetYAML, existingOverlay string) (string,
4644 return "" , fmt .Errorf ("failed to compare schemas: %w" , err )
4745 }
4846 // special case, is there only one action and it targets the same as the last overlayDocument.Actions item entry, we'll just replace it.
49- if len (newOverlay .Actions ) == 1 && len (existingOverlayDocument .Actions ) > 0 && newOverlay .Actions [0 ].Target == existingOverlayDocument .Actions [len (existingOverlayDocument .Actions )- 1 ].Target {
50- existingOverlayDocument .Actions [len (existingOverlayDocument .Actions )- 1 ] = newOverlay .Actions [0 ]
47+ lastAction := len (existingOverlayDocument .Actions ) - 1
48+ if len (newOverlay .Actions ) == 1 && lastAction >= 0 && newOverlay .Actions [0 ].Target == existingOverlayDocument .Actions [lastAction ].Target {
49+ prev := & existingOverlayDocument .Actions [lastAction ]
50+ next := & newOverlay .Actions [0 ]
51+ // If both are sequence updates, concatenate content rather than replacing
52+ if prev .Update .Kind == yaml .SequenceNode && next .Update .Kind == yaml .SequenceNode {
53+ prev .Update .Content = append (prev .Update .Content , next .Update .Content ... )
54+ } else {
55+ existingOverlayDocument .Actions [lastAction ] = * next
56+ }
5157 } else {
5258 // Otherwise, we'll just append the new overlay to the existing overlay
5359 existingOverlayDocument .Actions = append (existingOverlayDocument .Actions , newOverlay .Actions ... )
@@ -115,16 +121,8 @@ func ApplyOverlay(originalYAML, overlayYAML string) (string, error) {
115121 if err != nil {
116122 return "" , fmt .Errorf ("failed to validate overlay schema in ApplyOverlay: %w" , err )
117123 }
118- hasFilterExpression := false
119- // check to see if we have an overlay with an error, or a partial overlay: i.e. any overlay actions are missing an update or remove
124+ // If an action has a valid target but no operation (update, remove, or copy), return query results for the target path (explorer mode).
120125 for i , action := range overlay .Actions {
121- tokenized := token .NewTokenizer (action .Target , config .WithPropertyNameExtension ()).Tokenize ()
122- for _ , tok := range tokenized {
123- if tok .Token == token .FILTER {
124- hasFilterExpression = true
125- break
126- }
127- }
128126 parsed , pathErr := jsonpath .NewPath (action .Target , config .WithPropertyNameExtension ())
129127
130128 var node * yaml.Node
@@ -136,7 +134,7 @@ func ApplyOverlay(originalYAML, overlayYAML string) (string, error) {
136134
137135 return applyOverlayJSONPathError (pathErr , node )
138136 }
139- if reflect .ValueOf (action .Update ).IsZero () && action .Remove == false {
137+ if reflect .ValueOf (action .Update ).IsZero () && ! action .Remove && action . Copy == "" {
140138 result := parsed .Query (& orig )
141139
142140 node , err = lookupOverlayActionTargetNode (overlayYAML , i )
@@ -147,10 +145,6 @@ func ApplyOverlay(originalYAML, overlayYAML string) (string, error) {
147145 return applyOverlayJSONPathIncomplete (result , node )
148146 }
149147 }
150- if hasFilterExpression && overlay .JSONPathVersion != "rfc9535" {
151- return "" , fmt .Errorf ("invalid overlay schema: must have `x-speakeasy-jsonpath: rfc9535`" )
152- }
153-
154148 err = overlay .ApplyTo (& orig )
155149 if err != nil {
156150 return "" , fmt .Errorf ("failed to apply overlay: %w" , err )
0 commit comments