@@ -31,6 +31,10 @@ export function dereferenceSchema(
3131 // Save the original schema metadata (excluding $ref)
3232 const { $ref : _ , ...originalMetadata } = schema ;
3333
34+ const description =
35+ ( originalMetadata . description ?? "" ) ||
36+ ( referencedSchema . description ?? "" ) ;
37+
3438 // Merge the original metadata with the dereferenced schema
3539 return {
3640 ...originalMetadata ,
@@ -40,7 +44,7 @@ export function dereferenceSchema(
4044 visited ,
4145 ) ,
4246 title : originalMetadata . title || referencedSchema . title ,
43- description : originalMetadata . description || referencedSchema . description ,
47+ ... ( description && { description } ) ,
4448 } ;
4549 }
4650
@@ -50,9 +54,11 @@ export function dereferenceSchema(
5054 if ( result . type === "array" && result . items ) {
5155 if ( Array . isArray ( result . items ) ) {
5256 // Handle tuple types
53- result . items = result . items . map ( ( item ) =>
54- dereferenceSchema ( item as JSONSchema7 , definitions , visited )
55- ) . filter ( Boolean ) as JSONSchema7 [ ] ;
57+ result . items = result . items
58+ . map ( ( item ) =>
59+ dereferenceSchema ( item as JSONSchema7 , definitions , visited ) ,
60+ )
61+ . filter ( Boolean ) as JSONSchema7 [ ] ;
5662 } else {
5763 // Handle single item schema
5864 result . items = dereferenceSchema (
@@ -66,12 +72,13 @@ export function dereferenceSchema(
6672 // Handle and merge allOf into the main schema
6773 if ( result . allOf && Array . isArray ( result . allOf ) && result . allOf . length > 0 ) {
6874 // First dereference all schemas in allOf
69- const dereferencedAllOf = result . allOf . map ( ( subSchema : any ) =>
70- dereferenceSchema (
71- subSchema as JSONSchema7 ,
72- definitions ,
73- visited ,
74- ) as JSONSchema7
75+ const dereferencedAllOf = result . allOf . map (
76+ ( subSchema : any ) =>
77+ dereferenceSchema (
78+ subSchema as JSONSchema7 ,
79+ definitions ,
80+ visited ,
81+ ) as JSONSchema7 ,
7582 ) ;
7683
7784 // Merge all properties from allOf schemas into the main schema
@@ -86,10 +93,7 @@ export function dereferenceSchema(
8693
8794 // Merge required fields if they exist
8895 if ( subSchema . required && Array . isArray ( subSchema . required ) ) {
89- result . required = [
90- ...( result . required || [ ] ) ,
91- ...subSchema . required ,
92- ] ;
96+ result . required = [ ...( result . required || [ ] ) , ...subSchema . required ] ;
9397 }
9498 }
9599
@@ -103,22 +107,14 @@ export function dereferenceSchema(
103107 // Handle anyOf
104108 if ( result . anyOf ) {
105109 result . anyOf = result . anyOf . map ( ( subSchema : any ) =>
106- dereferenceSchema (
107- subSchema as JSONSchema7 ,
108- definitions ,
109- visited ,
110- )
110+ dereferenceSchema ( subSchema as JSONSchema7 , definitions , visited ) ,
111111 ) as JSONSchema7 [ ] ;
112112 }
113113
114114 // Handle oneOf
115115 if ( result . oneOf ) {
116116 result . oneOf = result . oneOf . map ( ( subSchema : any ) =>
117- dereferenceSchema (
118- subSchema as JSONSchema7 ,
119- definitions ,
120- visited ,
121- )
117+ dereferenceSchema ( subSchema as JSONSchema7 , definitions , visited ) ,
122118 ) as JSONSchema7 [ ] ;
123119 }
124120
0 commit comments