Skip to content

Commit 682a03c

Browse files
authored
fix: modify() preserve unknown top-level schema keys when using pick (#264)
* fix: modify() with pick drops unknown top-level schema keys pickFields() only copied properties/x-jsf-order/required/allOf/x-jsf-logic, silently dropping anything else (type, x-rmt-meta, additionalProperties...). Add a default case so unrecognized keys pass through, matching v0 behavior. * fix: TS errors from unknown-key pass-through and untyped test assertions
1 parent c20265e commit 682a03c

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/modify-schema.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,8 @@ function pickFields(originalSchema: JsfSchema, fieldsToPick: ModifyConfig['pick'
354354

355355
break
356356
}
357-
case 'x-jsf-logic':
358-
newSchema[attrKey] = attrValue
359-
break
357+
default:
358+
(newSchema as Record<string, unknown>)[attrKey] = attrValue
360359
}
361360
})
362361

test/modify-schema.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,21 @@ describe('modifySchema', () => {
11461146
expect(warnings).toHaveLength(0)
11471147
})
11481148

1149+
it('preserves unknown top-level schema keys (e.g. x-rmt-meta) not just properties/order/allOf', () => {
1150+
const schemaWithMeta = {
1151+
...schemaTickets,
1152+
'type': 'object',
1153+
'x-rmt-meta': { jsfOldVersion: true },
1154+
}
1155+
1156+
const { schema } = modifySchema(schemaWithMeta, {
1157+
pick: ['quantity'],
1158+
}) as { schema: { 'type'?: string, 'x-rmt-meta'?: unknown } }
1159+
1160+
expect(schema.type).toBe('object')
1161+
expect(schema['x-rmt-meta']).toEqual({ jsfOldVersion: true })
1162+
})
1163+
11491164
it('basic usage without conditionals', () => {
11501165
const schemaMinimal = {
11511166
'properties': {

0 commit comments

Comments
 (0)