@@ -8,29 +8,22 @@ function applyOverlayToOpenAPI(spec, overlay) {
8
8
overlay . actions . forEach ( ( a ) => {
9
9
// Is it a remove?
10
10
if ( a . hasOwnProperty ( 'remove' ) ) {
11
- // split the path expression
12
- var target_pieces = jsonpath . parse ( a . target ) ;
13
- // snag the last piece, we need this info to work out which element to remove
14
- var final_segment = target_pieces . pop ( ) ;
15
- var target_key = "" ;
16
- if ( final_segment . expression . type == "identifier" ) {
17
- target_key = final_segment . expression . value ;
11
+ while ( true ) {
12
+ var path = jsonpath . paths ( spec , a . target , 1 )
13
+ if ( path . length == 0 ) {
14
+ break
15
+ }
16
+ var parent = jsonpath . parent ( spec , a . target )
17
+ const thingToRemove = path [ 0 ] [ path [ 0 ] . length - 1 ]
18
+ delete parent [ thingToRemove ]
18
19
}
19
20
20
- // Now rebuild the path up to before the final bit
21
- var remaining_path = jsonpath . stringify ( target_pieces ) ;
22
-
23
- // get the parent node and remove the target element
24
- var node_value = jsonpath . value ( spec , remaining_path ) ;
25
- delete node_value [ target_key ] ;
26
-
27
21
} else {
28
22
// It must be an update
29
23
jsonpath . apply ( spec , a . target , ( chunk ) => {
30
24
31
25
// Deep merge using a module (built-in spread operator is only shallow)
32
26
const merger = mergician ( { appendArrays : true } ) ;
33
- console . debug ( a ) ;
34
27
const merged = merger ( chunk , a . update ) ;
35
28
return merged ;
36
29
@@ -43,8 +36,6 @@ function applyOverlayToOpenAPI(spec, overlay) {
43
36
44
37
export function overlayFiles ( openapiFile , overlayFile ) {
45
38
// Parse the "input" OpenAPI document
46
- console . debug ( openapiFile ) ;
47
- console . debug ( typeof openapiFile ) ;
48
39
const specraw = fs . readFileSync ( openapiFile , 'utf8' ) ;
49
40
var spec = parseWithPointers ( specraw ) . data ;
50
41
0 commit comments