diff --git a/src/parser.ts b/src/parser.ts index 6add6efa..5e4bd241 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -416,12 +416,13 @@ function parseSchema( const comment = `This interface was referenced by \`${parentSchemaName}\`'s JSON-Schema definition via the \`patternProperty\` "${key}".` ast.comment = ast.comment ? `${ast.comment}\n\n${comment}` : comment + ast.keyName = singlePatternProperty ? '[k: string]' : key return { ast, isPatternProperty: !singlePatternProperty, isRequired: singlePatternProperty || includes(schema.required || [], key), isUnreachableDefinition: false, - keyName: singlePatternProperty ? '[k: string]' : key, + keyName: ast.keyName, } }), ) diff --git a/test/__snapshots__/test/test.ts.md b/test/__snapshots__/test/test.ts.md index c83bd491..bf3a0b4c 100644 --- a/test/__snapshots__/test/test.ts.md +++ b/test/__snapshots__/test/test.ts.md @@ -2230,6 +2230,14 @@ Generated by [AVA](https://avajs.dev). maybe?: string;␊ [k: string]: Leaf | undefined;␊ };␊ + pattern?: {␊ + maybe?: string;␊ + /**␊ + * This interface was referenced by \`undefined\`'s JSON-Schema definition␊ + * via the \`patternProperty\` "leaf|tree".␊ + */␊ + [k: string]: unknown[] | undefined;␊ + };␊ [k: string]: string | undefined;␊ }␊ export interface Leaf {␊ diff --git a/test/__snapshots__/test/test.ts.snap b/test/__snapshots__/test/test.ts.snap index 4d3e02b7..cdd1cd09 100644 Binary files a/test/__snapshots__/test/test.ts.snap and b/test/__snapshots__/test/test.ts.snap differ diff --git a/test/e2e/options.strictIndexSignatures.ts b/test/e2e/options.strictIndexSignatures.ts index cab3874d..a29f479c 100644 --- a/test/e2e/options.strictIndexSignatures.ts +++ b/test/e2e/options.strictIndexSignatures.ts @@ -22,6 +22,19 @@ export const input = { }, }, }, + pattern: { + type: 'object', + properties: { + maybe: { + type: 'string', + }, + }, + patternProperties: { + 'leaf|tree': { + type: 'array', + }, + }, + }, }, additionalProperties: { type: 'string',