@@ -215,8 +215,9 @@ export function resolveAllOfObject(params: {
215215export function getProps ( params : {
216216 schemaObject : SchemaObject ;
217217 getType : ( schema : SchemaObject ) => string ;
218+ openAPIData ?: OpenAPIObject ;
218219} ) : IPropObject [ ] {
219- const { schemaObject, getType } = params ;
220+ const { schemaObject, getType, openAPIData } = params ;
220221 const requiredPropKeys = schemaObject ?. required ?? false ;
221222 const properties = schemaObject . properties ;
222223
@@ -226,15 +227,35 @@ export function getProps(params: {
226227 // eslint-disable-next-line no-useless-escape
227228 propKey = propKey . replace ( / [ \[ | \] ] / g, '' ) ;
228229
230+ // 获取描述信息,如果是 $ref 引用,尝试获取引用对象的描述
231+ let desc = [ schema . title , schema . description ]
232+ . filter ( ( item ) => item )
233+ . join ( ' ' )
234+ . replace ( lineBreakReg , '' ) ;
235+
236+ // 如果是 $ref 引用,尝试获取引用对象的描述
237+ if ( isReferenceObject ( schema ) && openAPIData ) {
238+ const refName = getLastRefName ( schema . $ref ) ;
239+ const refSchema = openAPIData . components ?. schemas ?. [
240+ refName
241+ ] as SchemaObject ;
242+ if ( refSchema ) {
243+ const refDesc = [ refSchema . title , refSchema . description ]
244+ . filter ( ( item ) => item )
245+ . join ( ' ' )
246+ . replace ( lineBreakReg , '' ) ;
247+ if ( refDesc ) {
248+ desc = desc + refDesc ;
249+ }
250+ }
251+ }
252+
229253 // 复用 schema 部分字段
230254 return {
231255 ...schema ,
232256 name : propKey ,
233257 type : getType ( schema ) ,
234- desc : [ schema . title , schema . description ]
235- . filter ( ( item ) => item )
236- . join ( ' ' )
237- . replace ( lineBreakReg , '' ) ,
258+ desc : desc ,
238259 // 如果没有 required 信息,默认全部是非必填
239260 required : requiredPropKeys
240261 ? requiredPropKeys . some ( ( key ) => key === propKey )
0 commit comments