11'use strict' ;
22
3+ const path = require ( 'path' ) ;
4+
35const { openapiOverlay, resolveJsonPathValue, deepMerge} = require ( '../utils/overlay' ) ;
6+ const { parseFile} = require ( '../openapi-format' ) ;
47
58const { describe, it, expect} = require ( '@jest/globals' ) ;
69
@@ -404,6 +407,12 @@ describe('resolveJsonPathValue tests', () => {
404407 expect ( result ) . toEqual ( [ { id : 2 } ] ) ;
405408 } ) ;
406409
410+ it ( 'should handle RFC 9535 filtering without surrounding parentheses' , ( ) => {
411+ const obj = { items : [ { id : 1 } , { id : 2 } , { id : 3 } ] } ;
412+ const result = resolveJsonPathValue ( obj , '$.items[?@.id==2]' ) ;
413+ expect ( result ) . toEqual ( [ { id : 2 } ] ) ;
414+ } ) ;
415+
407416 it ( 'should handle array slicing' , ( ) => {
408417 const obj = { items : [ 1 , 2 , 3 , 4 , 5 ] } ;
409418 const result = resolveJsonPathValue ( obj , '$.items[1:4]' ) ;
@@ -427,4 +436,59 @@ describe('resolveJsonPathValue tests', () => {
427436 const result = resolveJsonPathValue ( obj , '$.paths..summary' ) ;
428437 expect ( result ) . toEqual ( [ ] ) ;
429438 } ) ;
439+
440+ it ( 'should apply overlay action using RFC 9535 filter without parentheses' , async ( ) => {
441+ const baseOAS = {
442+ security : [ { cookieAuth : [ ] } , { bearerAuth : [ ] } ]
443+ } ;
444+ const overlaySet = {
445+ actions : [
446+ {
447+ target : '$.security[?@.cookieAuth]' ,
448+ update : { 'x-applied' : true }
449+ }
450+ ]
451+ } ;
452+
453+ const result = await openapiOverlay ( baseOAS , { overlaySet} ) ;
454+ expect ( result . data . security ) . toEqual ( [ { cookieAuth : [ ] , 'x-applied' : true } , { bearerAuth : [ ] } ] ) ;
455+ expect ( result . resultData . totalUsedActions ) . toBe ( 1 ) ;
456+ } ) ;
457+
458+ it ( 'should apply overlay action to an escaped key path' , async ( ) => {
459+ const baseOAS = {
460+ 'x.map' : {
461+ value : 1
462+ }
463+ } ;
464+ const overlaySet = {
465+ actions : [
466+ {
467+ target : "$['x.map']" ,
468+ update : { updated : true }
469+ }
470+ ]
471+ } ;
472+
473+ const result = await openapiOverlay ( baseOAS , { overlaySet} ) ;
474+ expect ( result . data [ 'x.map' ] ) . toEqual ( { value : 1 , updated : true } ) ;
475+ expect ( result . resultData . totalUsedActions ) . toBe ( 1 ) ;
476+ } ) ;
477+
478+ it ( 'should preserve independent copies when applying a second overlay to prior overlay results' , async ( ) => {
479+ const dir = path . join ( __dirname , 'overlay-previous-overlay' ) ;
480+ const input = await parseFile ( path . join ( dir , 'input.yaml' ) ) ;
481+ const overlaySet = await parseFile ( path . join ( dir , 'overlay.yaml' ) ) ;
482+
483+ const firstPass = await openapiOverlay ( input , { overlaySet : { actions : [ overlaySet . actions [ 0 ] ] } } ) ;
484+ const firstPassMatches = resolveJsonPathValue ( firstPass . data , '$..child.oneOf[0].properties.a' ) ;
485+ expect ( firstPassMatches . length ) . toBe ( 3 ) ;
486+
487+ const result = await openapiOverlay ( input , { overlaySet} ) ;
488+ const aBranches = result . data . properties . parent . properties ;
489+
490+ expect ( aBranches . one . properties . child . oneOf [ 0 ] . properties . a . oneOf ) . toBeDefined ( ) ;
491+ expect ( aBranches . two . properties . child . oneOf [ 0 ] . properties . a . oneOf ) . toBeDefined ( ) ;
492+ expect ( aBranches . three . properties . child . oneOf [ 0 ] . properties . a . oneOf ) . toBeDefined ( ) ;
493+ } ) ;
430494} ) ;
0 commit comments