File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,21 @@ class Pointer {
103103
104104 const token = tokens [ i ] ;
105105 if ( this . value [ token ] === undefined || ( this . value [ token ] === null && i === tokens . length - 1 ) ) {
106+ // one final case is if the entry itself includes slashes, and was parsed out as a token - we can join the remaining tokens and try again
107+ let didFindSubstringSlashMatch = false ;
108+ for ( let j = tokens . length - 1 ; j > i ; j -- ) {
109+ const joinedToken = tokens . slice ( i , j + 1 ) . join ( "/" ) ;
110+ if ( this . value [ joinedToken ] !== undefined ) {
111+ this . value = this . value [ joinedToken ] ;
112+ i = j ;
113+ didFindSubstringSlashMatch = true ;
114+ break ;
115+ }
116+ }
117+ if ( didFindSubstringSlashMatch ) {
118+ continue ;
119+ }
120+
106121 this . value = null ;
107122 throw new MissingPointerError ( token , decodeURI ( this . originalPath ) ) ;
108123 } else {
Original file line number Diff line number Diff line change 1+ channels :
2+ ' smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured ' :
3+ description : The topic on which measured values may be produced and consumed.
4+ parameters :
5+ streetlightId :
6+ description : The ID of the streetlight.
7+ schema :
8+ type : string
Original file line number Diff line number Diff line change 1+ import { describe , it } from "vitest" ;
2+ import $RefParser from "../../../lib/index.js" ;
3+ import path from "../../utils/path.js" ;
4+
5+ import { expect } from "vitest" ;
6+
7+ describe ( "$refs that include slashes" , ( ) => {
8+ it ( "should parse successfully" , async ( ) => {
9+ const parser = new $RefParser ( ) ;
10+ await parser . parse ( path . rel ( "test/specs/substrings/definitions/slash-strings.yaml" ) ) ;
11+ const $refs = parser . $refs ;
12+ const ref = $refs . get (
13+ "#/channels/smartylighting/streetlights/1/0/event/{streetlightId}/lighting/measured/parameters" ,
14+ ) ;
15+ expect ( ref ) . to . deep . equal ( {
16+ streetlightId : {
17+ description : "The ID of the streetlight." ,
18+ schema : {
19+ type : "string" ,
20+ } ,
21+ } ,
22+ } ) ;
23+ } ) ;
24+ } ) ;
You can’t perform that action at this time.
0 commit comments