@@ -37,13 +37,23 @@ export function convertToJsDoc(
3737export function generateProps ( flattenedObj : Record < string , any > , option : ConvertOption ) : Property [ ] {
3838 const props : Property [ ] = [ ]
3939 for ( const key in flattenedObj ) {
40+ if ( ! key ) {
41+ continue
42+ }
43+
4044 // primitive types
4145 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+
4252 props . push ( {
53+ parentPath,
4354 path : key ,
4455 value : flattenedObj [ key ] ,
4556 type : detectValType ( key , flattenedObj [ key ] ) ,
46- parentPath : option . rootTypeName ?? ROOT_TYPE_NAME
4757 } )
4858 continue
4959 }
@@ -53,13 +63,15 @@ export function generateProps(flattenedObj: Record<string, any>, option: Convert
5363 for ( let i = keyArr . length - 1 ; i >= 0 ; i -- ) {
5464 let path = keyArr [ i ]
5565 const parentPath = keyArr [ i - 1 ] ?. replace ( / \[ \d + ] / , EMPTY_STR ) ?? option . rootTypeName
66+ // @ts -ignore
5667 const pathWithoutBrackets = path . replace ( / \[ \d ] / , EMPTY_STR )
5768 // skip duplicated property
5869 if ( props . some ( p => p . path === pathWithoutBrackets && p . parentPath === parentPath ) ) {
5970 continue
6071 }
6172
6273 const property : Property = {
74+ // @ts -ignore
6375 parentPath,
6476 path : pathWithoutBrackets ,
6577 value : flattenedObj [ key ] ,
@@ -69,10 +81,12 @@ export function generateProps(flattenedObj: Record<string, any>, option: Convert
6981 if ( i !== keyArr . length - 1 ) {
7082 property . type = pascalCase ( pluralize . singular ( pathWithoutBrackets ) )
7183 // array
84+ // @ts -ignore
7285 if ( / \w \[ \d + ] / . test ( path ) ) {
7386 property . type = `${ property . type } []`
7487 }
7588 } else {
89+ // @ts -ignore
7690 property . type = detectValType ( path , property . value )
7791 }
7892
0 commit comments