@@ -52,14 +52,22 @@ export function transformSchemaObjMap(obj: Record<string, any>, options: Transfo
52
52
}
53
53
54
54
/** make sure all required fields exist **/
55
- export function addRequiredProps ( properties : Record < string , any > , required : Set < string > ) : string [ ] {
55
+ export function addRequiredProps (
56
+ properties : Record < string , any > ,
57
+ required : Set < string > ,
58
+ additionalProperties : any ,
59
+ options : TransformSchemaObjOptions
60
+ ) : string [ ] {
56
61
const missingRequired = [ ...required ] . filter ( ( r : string ) => ! ( r in properties ) ) ;
57
62
if ( missingRequired . length == 0 ) {
58
63
return [ ] ;
59
64
}
60
65
let output = "" ;
66
+
67
+ const valueType = additionalProperties ? transformSchemaObj ( additionalProperties , options ) : "unknown" ;
68
+
61
69
for ( const r of missingRequired ) {
62
- output += `${ r } : unknown ;\n` ;
70
+ output += `${ r } : ${ valueType } ;\n` ;
63
71
}
64
72
return [ `{\n${ output } }` ] ;
65
73
}
@@ -131,7 +139,12 @@ export function transformSchemaObj(node: any, options: TransformSchemaObjOptions
131
139
}
132
140
case "object" : {
133
141
const isAnyOfOrOneOfOrAllOf = "anyOf" in node || "oneOf" in node || "allOf" in node ;
134
- const missingRequired = addRequiredProps ( node . properties || { } , node . required || [ ] ) ;
142
+ const missingRequired = addRequiredProps (
143
+ node . properties || { } ,
144
+ node . required || [ ] ,
145
+ node . additionalProperties ,
146
+ options
147
+ ) ;
135
148
// if empty object, then return generic map type
136
149
if (
137
150
! isAnyOfOrOneOfOrAllOf &&
0 commit comments