File tree Expand file tree Collapse file tree 2 files changed +44
-1
lines changed
Expand file tree Collapse file tree 2 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,48 @@ describe('#findOperation()', () => {
185185 } ) ;
186186 } ) ;
187187
188+ it ( 'should return result if path is slash' , ( ) => {
189+ const oas = new Oas ( {
190+ openapi : '3.0.0' ,
191+ servers : [
192+ {
193+ url : 'https://example.com' ,
194+ } ,
195+ ] ,
196+ paths : {
197+ '/' : {
198+ get : {
199+ responses : {
200+ '200' : {
201+ description : 'OK' ,
202+ } ,
203+ } ,
204+ } ,
205+ } ,
206+ } ,
207+ } ) ;
208+
209+ const uri = 'https://example.com' ;
210+ const method = 'get' ;
211+
212+ const res = oas . findOperation ( uri , method ) ;
213+ expect ( res . url ) . toStrictEqual ( {
214+ origin : 'https://example.com' ,
215+ path : '/' ,
216+ nonNormalizedPath : '/' ,
217+ slugs : { } ,
218+ method : 'GET' ,
219+ } ) ;
220+
221+ expect ( res . operation ) . toStrictEqual ( {
222+ responses : {
223+ '200' : {
224+ description : 'OK' ,
225+ } ,
226+ } ,
227+ } ) ;
228+ } ) ;
229+
188230 it ( 'should return result if in server variable defaults' , ( ) => {
189231 const oas = new Oas ( serverVariables ) ;
190232 const uri = 'https://demo.example.com:443/v2/post' ;
Original file line number Diff line number Diff line change @@ -167,8 +167,9 @@ class Oas {
167167 if ( ! targetServer ) return undefined ;
168168 targetServer . url = this . replaceUrl ( targetServer . url , targetServer . variables || { } ) ;
169169
170- const [ , pathName ] = url . split ( targetServer . url ) ;
170+ let [ , pathName ] = url . split ( targetServer . url ) ;
171171 if ( pathName === undefined ) return undefined ;
172+ if ( pathName === '' ) pathName = '/' ;
172173 const annotatedPaths = generatePathMatches ( paths , pathName , targetServer . url ) ;
173174 if ( ! annotatedPaths . length ) return undefined ;
174175
You can’t perform that action at this time.
0 commit comments