@@ -13,17 +13,26 @@ export class SchemaComponentsMap {
13
13
this . _data = [ ] ;
14
14
}
15
15
16
- createRef = ( paths : string [ ] ) => {
16
+ createRef = ( paths : string [ ] ) : string => {
17
+ if ( ! Array . isArray ( paths ) ) {
18
+ throw new Error ( `Expected an array, but received: ${ typeof paths } ` ) ;
19
+ }
20
+ if ( paths . length === 0 ) {
21
+ throw new Error ( "Paths array cannot be empty." ) ;
22
+ }
17
23
return [ "#" , ...paths ] . join ( "/" ) ;
18
24
} ;
19
25
20
- parseRef = ( ref : string ) => {
26
+ parseRef = ( ref : string ) : string [ ] => {
27
+ if ( ! ref . startsWith ( "#/" ) ) {
28
+ throw new Error ( `Invalid ref format: ${ ref } . It should start with "#/"` ) ;
29
+ }
21
30
return ref . split ( "/" ) ;
22
31
} ;
23
32
24
33
createComponent (
25
34
$ref : string ,
26
- rawTypeData : SchemaComponent [ "rawTypeData" ] ,
35
+ rawTypeData : SchemaComponent [ "rawTypeData" ]
27
36
) : SchemaComponent {
28
37
const parsed = this . parseRef ( $ref ) ;
29
38
const typeName = parsed [ parsed . length - 1 ] ! ;
@@ -60,8 +69,8 @@ export class SchemaComponentsMap {
60
69
filter ( ...componentNames : ( string [ ] | string ) [ ] ) {
61
70
return this . _data . filter ( ( it ) =>
62
71
componentNames . some ( ( componentName ) =>
63
- it . $ref . startsWith ( `#/components/${ componentName } ` ) ,
64
- ) ,
72
+ it . $ref . startsWith ( `#/components/${ componentName } ` )
73
+ )
65
74
) ;
66
75
}
67
76
0 commit comments