@@ -37,13 +37,23 @@ export function convertToJsDoc(
37
37
export function generateProps ( flattenedObj : Record < string , any > , option : ConvertOption ) : Property [ ] {
38
38
const props : Property [ ] = [ ]
39
39
for ( const key in flattenedObj ) {
40
+ if ( ! key ) {
41
+ continue
42
+ }
43
+
40
44
// primitive types
41
45
if ( key . indexOf ( DOT ) === - 1 ) {
46
+ const parentPath = option . rootTypeName ?? ROOT_TYPE_NAME
47
+ // skip duplicated property
48
+ if ( props . some ( p => p . path === key && p . parentPath === parentPath ) ) {
49
+ continue
50
+ }
51
+
42
52
props . push ( {
53
+ parentPath,
43
54
path : key ,
44
55
value : flattenedObj [ key ] ,
45
56
type : detectValType ( key , flattenedObj [ key ] ) ,
46
- parentPath : option . rootTypeName ?? ROOT_TYPE_NAME
47
57
} )
48
58
continue
49
59
}
@@ -53,13 +63,15 @@ export function generateProps(flattenedObj: Record<string, any>, option: Convert
53
63
for ( let i = keyArr . length - 1 ; i >= 0 ; i -- ) {
54
64
let path = keyArr [ i ]
55
65
const parentPath = keyArr [ i - 1 ] ?. replace ( / \[ \d + ] / , EMPTY_STR ) ?? option . rootTypeName
66
+ // @ts -ignore
56
67
const pathWithoutBrackets = path . replace ( / \[ \d ] / , EMPTY_STR )
57
68
// skip duplicated property
58
69
if ( props . some ( p => p . path === pathWithoutBrackets && p . parentPath === parentPath ) ) {
59
70
continue
60
71
}
61
72
62
73
const property : Property = {
74
+ // @ts -ignore
63
75
parentPath,
64
76
path : pathWithoutBrackets ,
65
77
value : flattenedObj [ key ] ,
@@ -69,10 +81,12 @@ export function generateProps(flattenedObj: Record<string, any>, option: Convert
69
81
if ( i !== keyArr . length - 1 ) {
70
82
property . type = pascalCase ( pluralize . singular ( pathWithoutBrackets ) )
71
83
// array
84
+ // @ts -ignore
72
85
if ( / \w \[ \d + ] / . test ( path ) ) {
73
86
property . type = `${ property . type } []`
74
87
}
75
88
} else {
89
+ // @ts -ignore
76
90
property . type = detectValType ( path , property . value )
77
91
}
78
92
0 commit comments