@@ -30,6 +30,7 @@ export const getObject = ({
3030 const { name, specKey } = getRefInfo ( item . $ref , context ) ;
3131 return {
3232 value : name + nullable ,
33+ factoryMethodValue : `''` ,
3334 imports : [ { name, specKey } ] ,
3435 schemas : [ ] ,
3536 isEnum : false ,
@@ -114,12 +115,14 @@ export const getObject = ({
114115 const isReadOnly = item . readOnly || ( schema as SchemaObject ) . readOnly ;
115116 if ( ! index ) {
116117 acc . value += '{' ;
118+ acc . factoryMethodValue += '{\n return {' ;
117119 }
118120
119121 const doc = jsDoc ( schema as SchemaObject , true ) ;
120122
121123 acc . hasReadonlyProps ||= isReadOnly || false ;
122124 acc . imports . push ( ...resolvedValue . imports ) ;
125+ acc . factoryMethodValue += `\n ${ getKey ( key ) } : ${ resolvedValue . factoryMethodValue } ,` ;
123126 acc . value += `\n ${ doc ? `${ doc } ` : '' } ${
124127 isReadOnly && ! context . output . override . suppressReadonlyModifier
125128 ? 'readonly '
@@ -141,6 +144,7 @@ export const getObject = ({
141144 }
142145 } else {
143146 acc . value += '\n}' ;
147+ acc . factoryMethodValue += '\n };\n}' ;
144148 }
145149
146150 acc . value += nullable ;
@@ -152,6 +156,7 @@ export const getObject = ({
152156 imports : [ ] ,
153157 schemas : [ ] ,
154158 value : '' ,
159+ factoryMethodValue : '' ,
155160 isEnum : false ,
156161 type : 'object' as SchemaType ,
157162 isRef : false ,
@@ -167,6 +172,7 @@ export const getObject = ({
167172 if ( isBoolean ( item . additionalProperties ) ) {
168173 return {
169174 value : `{ [key: string]: any }` + nullable ,
175+ factoryMethodValue : `{}` ,
170176 imports : [ ] ,
171177 schemas : [ ] ,
172178 isEnum : false ,
@@ -182,6 +188,7 @@ export const getObject = ({
182188 } ) ;
183189 return {
184190 value : `{[key: string]: ${ resolvedValue . value } }` + nullable ,
191+ factoryMethodValue : `{}` ,
185192 imports : resolvedValue . imports ?? [ ] ,
186193 schemas : resolvedValue . schemas ?? [ ] ,
187194 isEnum : false ,
@@ -195,6 +202,7 @@ export const getObject = ({
195202 if ( itemWithConst . const ) {
196203 return {
197204 value : `'${ itemWithConst . const } '` + nullable ,
205+ factoryMethodValue : `null` ,
198206 imports : [ ] ,
199207 schemas : [ ] ,
200208 isEnum : false ,
@@ -208,6 +216,7 @@ export const getObject = ({
208216 value :
209217 ( item . type === 'object' ? '{ [key: string]: any }' : 'unknown' ) +
210218 nullable ,
219+ factoryMethodValue : `${ item . type === 'object' ? '{}' : 'null' } ` ,
211220 imports : [ ] ,
212221 schemas : [ ] ,
213222 isEnum : false ,
0 commit comments