@@ -34,8 +34,9 @@ import type { ReferenceObject, SchemaObject, TransformNodeOptions } from "../typ
3434export default function transformSchemaObject (
3535 schemaObject : SchemaObject | ReferenceObject ,
3636 options : TransformNodeOptions ,
37+ fromAdditionalProperties = false ,
3738) : ts . TypeNode {
38- const type = transformSchemaObjectWithComposition ( schemaObject , options ) ;
39+ const type = transformSchemaObjectWithComposition ( schemaObject , options , fromAdditionalProperties ) ;
3940 if ( typeof options . ctx . postTransform === "function" ) {
4041 const postTransformResult = options . ctx . postTransform ( type , options ) ;
4142 if ( postTransformResult ) {
@@ -51,6 +52,7 @@ export default function transformSchemaObject(
5152export function transformSchemaObjectWithComposition (
5253 schemaObject : SchemaObject | ReferenceObject ,
5354 options : TransformNodeOptions ,
55+ fromAdditionalProperties = false ,
5456) : ts . TypeNode {
5557 /**
5658 * Unexpected types & edge cases
@@ -145,7 +147,13 @@ export function transformSchemaObjectWithComposition(
145147
146148 const enumValuesArray = tsArrayLiteralExpression (
147149 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 ) ,
149157 schemaObject . enum as ( string | number ) [ ] ,
150158 {
151159 export : true ,
@@ -578,7 +586,7 @@ function transformSchemaObjectCore(schemaObject: SchemaObject, options: Transfor
578586 typeof schemaObject . patternProperties === "object" && Object . keys ( schemaObject . patternProperties ) . length ;
579587 const stringIndexTypes = [ ] ;
580588 if ( hasExplicitAdditionalProperties ) {
581- stringIndexTypes . push ( transformSchemaObject ( schemaObject . additionalProperties as SchemaObject , options ) ) ;
589+ stringIndexTypes . push ( transformSchemaObject ( schemaObject . additionalProperties as SchemaObject , options , true ) ) ;
582590 }
583591 if ( hasImplicitAdditionalProperties || ( ! schemaObject . additionalProperties && options . ctx . additionalProperties ) ) {
584592 stringIndexTypes . push ( UNKNOWN ) ;
0 commit comments