diff --git a/.changeset/silly-dingos-lie.md b/.changeset/silly-dingos-lie.md new file mode 100644 index 0000000000..e0e1e3743c --- /dev/null +++ b/.changeset/silly-dingos-lie.md @@ -0,0 +1,5 @@ +--- +"@redocly/respect-core": patch +--- + +Fixed Respect's handling of runtime expressions with hyphenated keys in JSON pointers. diff --git a/packages/respect-core/src/modules/__tests__/runtime-expressions/replace-json-pointers.test.ts b/packages/respect-core/src/modules/__tests__/runtime-expressions/replace-json-pointers.test.ts index d22c2d9c48..437c87c426 100644 --- a/packages/respect-core/src/modules/__tests__/runtime-expressions/replace-json-pointers.test.ts +++ b/packages/respect-core/src/modules/__tests__/runtime-expressions/replace-json-pointers.test.ts @@ -169,4 +169,19 @@ describe('replaceJSONPointers', () => { expect(result).toBe('[] == []'); }); + + it('should correctly replace hyphenated keys', () => { + const context = { + $response: { + body: { + 'test-hyphenated-key-with-value': 'some-value-to-test', + }, + }, + }; + + const expression = '$response.body#/test-hyphenated-key-with-value'; + const result = replaceJSONPointers(expression, context); + + expect(result).toBe('"some-value-to-test"'); + }); }); diff --git a/packages/respect-core/src/modules/runtime-expressions/replace-json-pointers.ts b/packages/respect-core/src/modules/runtime-expressions/replace-json-pointers.ts index 51bc10f2b6..427e0b0030 100644 --- a/packages/respect-core/src/modules/runtime-expressions/replace-json-pointers.ts +++ b/packages/respect-core/src/modules/runtime-expressions/replace-json-pointers.ts @@ -3,25 +3,25 @@ import JsonPointerLib from 'json-pointer'; export function replaceJSONPointers(expression: string, context: any): string { const jsonPointerReplacementRules = [ { - pattern: /\$response\.body#\/([\w/]+)/g, + pattern: /\$response\.body#\/([\w/-]+)/g, ctxFunction: (match: string, pointer: string) => { return resolvePointer(context.$response?.body, pointer, match); }, }, { - pattern: /\$request\.body#\/([\w/]+)/g, + pattern: /\$request\.body#\/([\w/-]+)/g, ctxFunction: (match: string, pointer: string) => { return resolvePointer(context.$request?.body, pointer, match); }, }, { - pattern: /\$outputs\.([\w-]+)#\/([\w/]+)/g, + pattern: /\$outputs\.([\w-]+)#\/([\w/-]+)/g, ctxFunction: (match: string, property: string, pointer: string) => { return resolvePointer(context.$outputs?.[property], pointer, match); }, }, { - pattern: /\$workflows\.([\w-]+)\.outputs\.([\w-]+)#\/([\w/]+)/g, + pattern: /\$workflows\.([\w-]+)\.outputs\.([\w-]+)#\/([\w/-]+)/g, ctxFunction: (match: string, workflowId: string, property: string, pointer: string) => { return resolvePointer( context.$workflows?.[workflowId]?.outputs?.[property], @@ -31,7 +31,7 @@ export function replaceJSONPointers(expression: string, context: any): string { }, }, { - pattern: /\$steps\.([\w-]+)\.outputs\.([\w-]+)#\/([\w/]+)/g, + pattern: /\$steps\.([\w-]+)\.outputs\.([\w-]+)#\/([\w/-]+)/g, ctxFunction: (match: string, stepId: string, property: string, pointer: string) => { return resolvePointer(context.$steps?.[stepId]?.outputs?.[property], pointer, match); },