@@ -80,7 +80,8 @@ class SingleTypeMeta {
80
80
81
81
for ( const component of components ) {
82
82
const { alias, schema } = component ;
83
- const prefix = ! isNested ? 'DynamicModel' : '' ;
83
+
84
+ const prefix = isNested ? '' : 'DynamicModel' ;
84
85
const aliasKey = `${ prefix } ${ ucfirst ( singleTypeAlias ) } ` ;
85
86
86
87
const newProperties = {
@@ -111,29 +112,57 @@ class SingleTypeMeta {
111
112
}
112
113
113
114
if ( type === InputType . COMPONENT ) {
114
- const { id } = field as IComponentSchema ;
115
+ /**
116
+ * Extract ref from component
117
+ */
118
+ const { id : inputId } = field as IComponentSchema ;
115
119
116
120
const nestedCustomComponents : ComponentEntity [ ] =
117
- await this . componentRepository . getChildrenComponentById ( id ) ;
121
+ await this . componentRepository . getChildrenComponentById ( inputId ) ;
118
122
119
123
if ( ! nestedCustomComponents ?. length ) {
120
124
continue ;
121
125
}
122
126
127
+ const nestedData = await this . buildMetaSchema ( {
128
+ components : nestedCustomComponents ,
129
+ isNested : true ,
130
+ singleTypeAlias : alias ,
131
+ } ) ;
132
+
133
+ /**
134
+ * Extracted component from ref
135
+ */
136
+ const extractedComponent = nestedData ?. properties ?. [ 0 ] ;
137
+
138
+ /**
139
+ * Check if nested component data isn't declared as the refComponent(id) => refComponent(id) => dataComponent
140
+ * If isn't ref component spread nested data to parent component
141
+ */
142
+ if ( nestedData ?. properties ?. [ name ] && extractedComponent ) {
143
+ newProperties . properties [ alias ] . properties . data . properties = {
144
+ ...newProperties . properties [ alias ] . properties . data . properties ,
145
+ ...nestedData . properties ,
146
+ } ;
147
+ continue ;
148
+ }
149
+
150
+ /**
151
+ * If ref component wrap and spread nested
152
+ */
123
153
newProperties . properties [ alias ] . properties . data . properties [ name ] = {
124
154
type : 'object' ,
125
155
properties : {
126
156
id : { type : 'string' } ,
127
- data : await this . buildMetaSchema ( {
128
- components : nestedCustomComponents ,
129
- isNested : true ,
130
- singleTypeAlias : alias ,
131
- } ) ,
157
+ data : nestedData ,
132
158
} ,
133
159
} ;
134
160
continue ;
135
161
}
136
162
163
+ /**
164
+ * If is primitive
165
+ */
137
166
newProperties . properties [ alias ] . properties . data . properties [ name ] = {
138
167
type : this . getSchemaType ( type ) ,
139
168
} ;
0 commit comments