Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_PICQGAdJ559UmGGsfIaks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"packages/generator/package.json":"Patch"},"note":"Fix wild key issue","date":"2026-04-17T09:02:19.475575400Z"}
52 changes: 52 additions & 0 deletions packages/generator/src/__tests__/generate-interface.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2532,3 +2532,55 @@ test('generateInterface preserves JSON endpoints alongside form/multipart endpoi
// Raw multipart should use FormData | Record<string, unknown>
expect(result).toContain('FormData | Record<string, unknown>')
})

test('generateInterface emits index signature for additionalProperties (not quoted key)', () => {
const schema = {
paths: {
'/news-categories': {
post: {
operationId: 'createNewsCategory',
requestBody: {
content: {
'application/json': {
schema: {
$ref: '#/components/schemas/NewsCategoryCreateRequest',
},
},
},
},
responses: {
'201': {
description: 'Created',
content: {
'application/json': {
schema: { type: 'string' as const },
},
},
},
},
},
},
},
components: {
schemas: {
NewsCategoryCreateRequest: {
type: 'object' as const,
properties: {
title: {
type: 'object' as const,
properties: {},
required: [],
additionalProperties: { type: 'string' as const },
},
},
required: ['title'],
},
},
},
}
const result = generateInterface(createSchemas(createDocument(schema as any)))
// Must emit a real TS index signature
expect(result).toContain('[key: string]: string')
// Must NOT emit a quoted literal key
expect(result).not.toContain("'[key: string]'")
})
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ test.each([
] as const)('wrapInterfaceKeyGuard handles optional keys (ending with ?): %s -> %s', (key, expected) => {
expect(wrapInterfaceKeyGuard(key)).toBe(expected)
})

test.each([
['[key: string]', '[key: string]'],
['[key: number]', '[key: number]'],
['[k: string]', '[k: string]'],
] as const)('wrapInterfaceKeyGuard preserves index signature syntax: %s -> %s', (key, expected) => {
expect(wrapInterfaceKeyGuard(key)).toBe(expected)
})
5 changes: 5 additions & 0 deletions packages/generator/src/wrap-interface-key-guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export function wrapInterfaceKeyGuard(key: string): string {
return key
}

// Preserve TypeScript index signature syntax (e.g., [key: string], [key: number])
if (/^\[.+:\s*.+\]$/.test(key)) {
return key
}

// Check if key ends with '?' (optional marker in TypeScript)
// If so, process the base key and add '?' back at the end
const isOptional = key.endsWith('?')
Expand Down