File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ export const refToObject = <T extends object>(
77 if ( '$ref' in data ) {
88 const target = data . $ref . split ( '/' ) . reduce < any > ( ( carry , pathName ) => {
99 if ( pathName === '#' ) return carry ;
10- return carry [ pathName ] ;
10+ return carry [ pathName ] || carry [ decodeURIComponent ( pathName ) ] ;
1111 } , docs ) ;
1212 return target as T ;
1313 }
Original file line number Diff line number Diff line change 1+ import { test , expect } from 'vitest' ;
2+ import { getBasicDocument } from '../mocks/get-basic-document' ;
3+ import { refToObject } from '../../src/lib/ref-to-object' ;
4+
5+ test ( '中文被转译' , ( ) => {
6+ const docs = getBasicDocument ( ) ;
7+ docs . components ||= { } ;
8+ docs . components . parameters ||= { } ;
9+ docs . components . parameters [ '你好' ] = { name : 'foo' , in : 'query' } ;
10+
11+ expect ( refToObject ( docs , { $ref : '#/components/parameters/你好' } ) ) . toMatchObject ( {
12+ in : 'query' ,
13+ name : 'foo' ,
14+ } ) ;
15+
16+ expect (
17+ refToObject ( docs , { $ref : '#/components/parameters/%E4%BD%A0%E5%A5%BD' } ) ,
18+ ) . toMatchObject ( {
19+ in : 'query' ,
20+ name : 'foo' ,
21+ } ) ;
22+ } ) ;
You can’t perform that action at this time.
0 commit comments