@@ -756,6 +756,75 @@ describe('dereferenceExternalRefs', () => {
756756 expect ( result ) . not . toHaveProperty ( 'x-ext' ) ;
757757 } ) ;
758758
759+ it ( 'should resolve external path-item refs with escaped JSON Pointer tokens (#3380)' , ( ) => {
760+ // A cross-file path-item `$ref` (e.g. `common.yaml#/paths/~1pets`) is
761+ // bundled into an x-ext ref whose pointer keeps the JSON Pointer escape
762+ // `~1` (for `/`) and percent-encoding (`%7B`/`%7D` for `{`/`}` in
763+ // templated paths). Both must be decoded before walking the external doc.
764+ const input = {
765+ openapi : '3.0.0' ,
766+ info : { version : '1.0.0' , title : 'API' } ,
767+ paths : {
768+ '/pets' : {
769+ $ref : '#/x-ext/abc1234/paths/~1pets' ,
770+ } ,
771+ '/pets/{petId}' : {
772+ $ref : '#/x-ext/abc1234/paths/~1pets~1%7BpetId%7D' ,
773+ } ,
774+ } ,
775+ 'x-ext' : {
776+ abc1234 : {
777+ paths : {
778+ '/pets' : {
779+ get : {
780+ operationId : 'listPets' ,
781+ responses : { '200' : { description : 'ok' } } ,
782+ } ,
783+ } ,
784+ '/pets/{petId}' : {
785+ get : {
786+ operationId : 'getPet' ,
787+ parameters : [
788+ {
789+ name : 'petId' ,
790+ in : 'path' ,
791+ required : true ,
792+ schema : { type : 'string' } ,
793+ } ,
794+ ] ,
795+ responses : { '200' : { description : 'ok' } } ,
796+ } ,
797+ } ,
798+ } ,
799+ } ,
800+ } ,
801+ } ;
802+
803+ const result = dereferenceExternalRef ( input ) as OpenApiDocument ;
804+
805+ expect ( result . paths ?. [ '/pets' ] ) . toEqual ( {
806+ get : {
807+ operationId : 'listPets' ,
808+ responses : { '200' : { description : 'ok' } } ,
809+ } ,
810+ } ) ;
811+ expect ( result . paths ?. [ '/pets/{petId}' ] ) . toEqual ( {
812+ get : {
813+ operationId : 'getPet' ,
814+ parameters : [
815+ {
816+ name : 'petId' ,
817+ in : 'path' ,
818+ required : true ,
819+ schema : { type : 'string' } ,
820+ } ,
821+ ] ,
822+ responses : { '200' : { description : 'ok' } } ,
823+ } ,
824+ } ) ;
825+ expect ( result ) . not . toHaveProperty ( 'x-ext' ) ;
826+ } ) ;
827+
759828 it ( 'should dereference external doc schemas with internal refs' , ( ) => {
760829 const input = {
761830 openapi : '3.0.3' ,
0 commit comments