@@ -34,10 +34,18 @@ export default class genTypeSchema extends typescriptToFileDatas {
3434 file : string ,
3535 type : string ,
3636 entry ?: { keySet : Set < string > ; refKeyTime : Record < string , number > } ,
37+ isLast ?: boolean
3738 ) : AnyOption {
3839 if ( ! entry ) {
3940 entry = { keySet : new Set ( ) , refKeyTime : { } } ;
4041 }
42+
43+ // 支持输入的是 code 场景
44+ if ( file && ! type ) {
45+ type = file ;
46+ file = 'index.ts' ;
47+ }
48+
4149 if ( ! file || ! type ) return { type : 'object' } ;
4250
4351 // 处理 Param.C.D.E.F.GetBaseDetailResponse 这种外部导入路径
@@ -60,8 +68,13 @@ export default class genTypeSchema extends typescriptToFileDatas {
6068 refFile ,
6169 typeJson . from ? type . replace ( / .+ ?(? = \. ) | .+ / , typeJson . from ) : type ,
6270 entry ,
71+ true ,
6372 ) ;
6473
74+ if ( ! isLast && typeJson . typeParams ) {
75+ delete typeJson . typeParams
76+ }
77+
6578 return typeJson ;
6679 }
6780 }
@@ -85,6 +98,11 @@ export default class genTypeSchema extends typescriptToFileDatas {
8598 }
8699 typeJson . definitions [ type ] = cloneTypeJson ;
87100 }
101+
102+ if ( ! isLast && typeJson . typeParams ) {
103+ delete typeJson . typeParams
104+ }
105+
88106 return typeJson ;
89107 }
90108
@@ -200,7 +218,7 @@ export default class genTypeSchema extends typescriptToFileDatas {
200218 // 别的文件ref
201219 if ( realRef . $ref && realRef . type !== ImportType . ImportNamespaceSpecifier ) {
202220 const refFile = realRef . $ref . replace ( / # \/ d e f i n i t i o n s | # / , '' ) ;
203- const realSchema = this . getJsonSchema ( refFile , result . $realRef ) ;
221+ const realSchema = this . getJsonSchema ( refFile , result . $realRef , undefined , true ) ;
204222 delete realRef . $ref ;
205223 delete realRef . from ;
206224 Object . assign ( realRef , realSchema ) ;
@@ -280,10 +298,10 @@ export default class genTypeSchema extends typescriptToFileDatas {
280298
281299 // 处理继承
282300 const handleExtends = ( item : AnyOption ) => {
283- const newTypeJson = this . getJsonSchema ( file as string , item . extends , entry ) ;
301+ const newTypeJson = this . getJsonSchema ( file as string , item . extends , entry , true ) ;
284302 if ( newTypeJson ) {
285303 const result = newTypeJson . $ref
286- ? this . getJsonSchema ( newTypeJson . $ref . replace ( / # / g, '' ) , item . extends , entry )
304+ ? this . getJsonSchema ( newTypeJson . $ref . replace ( / # / g, '' ) , item . extends , entry , true )
287305 : this . genJsonschema ( fileJson , newTypeJson , entry ) ;
288306 if ( typeof result === 'object' ) {
289307 item = merge ( result , item , {
@@ -358,6 +376,7 @@ export default class genTypeSchema extends typescriptToFileDatas {
358376 $dependRefKey ,
359377 $refJson . from ? $refKey . replace ( / .+ ?(? = \. ) | .+ / , $refJson . from ) : $refKey ,
360378 entry ,
379+ true
361380 ) ;
362381 handle && handleCommonRef ( result , $refKey ) ;
363382 return result ;
@@ -650,6 +669,11 @@ export default class genTypeSchema extends typescriptToFileDatas {
650669 // anyOf|allOf
651670 allOfAnyOfHandle ( typeJson ) ;
652671
672+ // 处理泛型
673+ if ( typeJson . typeParams && Object . keys ( typeJson . typeParams ) . length ) {
674+ handleGenericDefaultType ( typeJson . properties , typeJson . typeParams ) ;
675+ }
676+
653677 // 数组类型
654678 if ( typeJson . type === 'array' ) {
655679 commonArrayHandle ( typeJson ) ;
@@ -660,7 +684,6 @@ export default class genTypeSchema extends typescriptToFileDatas {
660684 typeJson = handleExtends ( typeJson ) ;
661685 }
662686
663-
664687 // 对象类型
665688 if ( typeJson . properties && Object . keys ( typeJson . properties ) ) {
666689 // eslint-disable-next-line guard-for-in
0 commit comments