@@ -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 ? 'readonly ' : ''
125128 } ${ getKey ( key ) } ${ isRequired ? '' : '?' } : ${ resolvedValue . value } ;`;
@@ -139,6 +142,7 @@ export const getObject = ({
139142 }
140143 } else {
141144 acc . value += '\n}' ;
145+ acc . factoryMethodValue += '\n };\n}' ;
142146 }
143147
144148 acc . value += nullable ;
@@ -150,6 +154,7 @@ export const getObject = ({
150154 imports : [ ] ,
151155 schemas : [ ] ,
152156 value : '' ,
157+ factoryMethodValue : '' ,
153158 isEnum : false ,
154159 type : 'object' as SchemaType ,
155160 isRef : false ,
@@ -165,6 +170,7 @@ export const getObject = ({
165170 if ( isBoolean ( item . additionalProperties ) ) {
166171 return {
167172 value : `{ [key: string]: any }` + nullable ,
173+ factoryMethodValue : `{}` ,
168174 imports : [ ] ,
169175 schemas : [ ] ,
170176 isEnum : false ,
@@ -180,6 +186,7 @@ export const getObject = ({
180186 } ) ;
181187 return {
182188 value : `{[key: string]: ${ resolvedValue . value } }` + nullable ,
189+ factoryMethodValue : `{}` ,
183190 imports : resolvedValue . imports ?? [ ] ,
184191 schemas : resolvedValue . schemas ?? [ ] ,
185192 isEnum : false ,
@@ -193,6 +200,7 @@ export const getObject = ({
193200 if ( itemWithConst . const ) {
194201 return {
195202 value : `'${ itemWithConst . const } '` + nullable ,
203+ factoryMethodValue : `null` ,
196204 imports : [ ] ,
197205 schemas : [ ] ,
198206 isEnum : false ,
@@ -206,6 +214,7 @@ export const getObject = ({
206214 value :
207215 ( item . type === 'object' ? '{ [key: string]: any }' : 'unknown' ) +
208216 nullable ,
217+ factoryMethodValue : `${ item . type === 'object' ? '{}' : 'null' } ` ,
209218 imports : [ ] ,
210219 schemas : [ ] ,
211220 isEnum : false ,
0 commit comments