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
5 changes: 5 additions & 0 deletions .changeset/silly-dingos-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/respect-core": patch
---

Fixed Respect's handling of runtime expressions with hyphenated keys in JSON pointers.
Original file line number Diff line number Diff line change
Expand Up @@ -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"');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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);
},
Expand Down
Loading