@@ -34,8 +34,9 @@ import type { ReferenceObject, SchemaObject, TransformNodeOptions } from "../typ
34
34
export default function transformSchemaObject (
35
35
schemaObject : SchemaObject | ReferenceObject ,
36
36
options : TransformNodeOptions ,
37
+ fromAdditionalProperties = false ,
37
38
) : ts . TypeNode {
38
- const type = transformSchemaObjectWithComposition ( schemaObject , options ) ;
39
+ const type = transformSchemaObjectWithComposition ( schemaObject , options , fromAdditionalProperties ) ;
39
40
if ( typeof options . ctx . postTransform === "function" ) {
40
41
const postTransformResult = options . ctx . postTransform ( type , options ) ;
41
42
if ( postTransformResult ) {
@@ -51,6 +52,7 @@ export default function transformSchemaObject(
51
52
export function transformSchemaObjectWithComposition (
52
53
schemaObject : SchemaObject | ReferenceObject ,
53
54
options : TransformNodeOptions ,
55
+ fromAdditionalProperties = false ,
54
56
) : ts . TypeNode {
55
57
/**
56
58
* Unexpected types & edge cases
@@ -145,7 +147,13 @@ export function transformSchemaObjectWithComposition(
145
147
146
148
const enumValuesArray = tsArrayLiteralExpression (
147
149
enumValuesVariableName ,
148
- oapiRef ( options . path ?? "" , undefined , true ) ,
150
+ // If fromAdditionalProperties is true we are dealing with a record type and we should append [string] to the generated type
151
+ fromAdditionalProperties
152
+ ? ts . factory . createIndexedAccessTypeNode (
153
+ oapiRef ( options . path ?? "" , undefined , true ) ,
154
+ ts . factory . createTypeReferenceNode ( ts . factory . createIdentifier ( "string" ) ) ,
155
+ )
156
+ : oapiRef ( options . path ?? "" , undefined , true ) ,
149
157
schemaObject . enum as ( string | number ) [ ] ,
150
158
{
151
159
export : true ,
@@ -547,7 +555,7 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
547
555
const hasExplicitAdditionalProperties =
548
556
typeof schemaObject . additionalProperties === "object" && Object . keys ( schemaObject . additionalProperties ) . length ;
549
557
const addlType = hasExplicitAdditionalProperties
550
- ? transformSchemaObject ( schemaObject . additionalProperties as SchemaObject , options )
558
+ ? transformSchemaObject ( schemaObject . additionalProperties as SchemaObject , options , true )
551
559
: UNKNOWN ;
552
560
return tsIntersection ( [
553
561
...( coreObjectType . length ? [ ts . factory . createTypeLiteralNode ( coreObjectType ) ] : [ ] ) ,
0 commit comments