@@ -44,15 +44,50 @@ export function dereferenceSchema(
44
44
45
45
const result : JSONSchema7 = { ...schema } ;
46
46
47
- // Handle allOf
48
- if ( result . allOf ) {
49
- result . allOf = result . allOf . map ( ( subSchema : any ) =>
47
+ // Handle arrays with items
48
+ if ( result . type === "array" && result . items ) {
49
+ result . items = dereferenceSchema (
50
+ result . items as JSONSchema7 ,
51
+ definitions ,
52
+ visited ,
53
+ ) as JSONSchema7 ;
54
+ }
55
+
56
+ // Handle and merge allOf into the main schema
57
+ if ( result . allOf && Array . isArray ( result . allOf ) && result . allOf . length > 0 ) {
58
+ // First dereference all schemas in allOf
59
+ const dereferencedAllOf = result . allOf . map ( ( subSchema : any ) =>
50
60
dereferenceSchema (
51
61
subSchema as JSONSchema7 ,
52
62
definitions ,
53
63
visited ,
54
- )
55
- ) as JSONSchema7 [ ] ;
64
+ ) as JSONSchema7
65
+ ) ;
66
+
67
+ // Merge all properties from allOf schemas into the main schema
68
+ for ( const subSchema of dereferencedAllOf ) {
69
+ // Merge properties if they exist
70
+ if ( subSchema . properties ) {
71
+ result . properties = {
72
+ ...( result . properties || { } ) ,
73
+ ...( subSchema . properties || { } ) ,
74
+ } ;
75
+ }
76
+
77
+ // Merge required fields if they exist
78
+ if ( subSchema . required && Array . isArray ( subSchema . required ) ) {
79
+ result . required = [
80
+ ...( result . required || [ ] ) ,
81
+ ...subSchema . required ,
82
+ ] ;
83
+ }
84
+ }
85
+
86
+ // Remove the allOf array since we've merged its contents
87
+ delete result . allOf ;
88
+ } else if ( result . allOf && ! Array . isArray ( result . allOf ) ) {
89
+ // Handle case where allOf is not an array
90
+ delete result . allOf ;
56
91
}
57
92
58
93
// Handle anyOf
@@ -102,10 +137,6 @@ export function dereferenceSchema(
102
137
) ;
103
138
}
104
139
105
- if ( "allOf" in result && ! Array . isArray ( result . allOf ) ) {
106
- delete result . allOf ;
107
- }
108
-
109
140
return result ;
110
141
}
111
142
0 commit comments