Skip to content

Commit 4e2d08c

Browse files
committed
fix: issue assigning list response to the output
1 parent 31ea755 commit 4e2d08c

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

.changeset/hungry-spies-stand.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@redocly/respect-core": patch
3+
---
4+
5+
Resolved an issue in Respect where the response list with nested object was not correctly assigned to the output.

packages/respect-core/src/modules/__tests__/runtime-expressions/evaluate.test.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ const runtimeExpressionContext = {
9696
'Join us as we review and classify a rare collection of 20 thingamabobs, gadgets, gizmos, whoosits, and whatsits, kindly donated by Ariel.',
9797
dates: ['2023-12-15', '2023-12-22'],
9898
price: 0,
99+
items: [
100+
{
101+
name: 'item1',
102+
description: 'item1 description',
103+
},
104+
{
105+
name: 'item2',
106+
description: 'item2 description',
107+
},
108+
],
99109
},
100110
statusCode: 201,
101111
header: {
@@ -229,7 +239,16 @@ const runtimeExpressionContext = {
229239
eventDescription: 'Join us as we review and classify a rare collection of 20 thingamabobs.',
230240
dates: ['2023-12-15', '2023-12-22'],
231241
price: 0,
232-
items: [],
242+
items: [
243+
{
244+
name: 'item1',
245+
description: 'item1 description',
246+
},
247+
{
248+
name: 'item2',
249+
description: 'item2 description',
250+
},
251+
],
233252
device_code: '123',
234253
piNumber: 3.14,
235254
},
@@ -394,7 +413,16 @@ describe('evaluateRuntimeExpressionPayload', () => {
394413
eventDescription: 'Join us as we review and classify a rare collection of 20 thingamabobs.',
395414
dates: ['2023-12-15', '2023-12-22'],
396415
price: 0,
397-
items: [],
416+
items: [
417+
{
418+
name: 'item1',
419+
description: 'item1 description',
420+
},
421+
{
422+
name: 'item2',
423+
description: 'item2 description',
424+
},
425+
],
398426
piNumber: 3.14,
399427
});
400428
});
@@ -639,4 +667,18 @@ describe('evaluateRuntimeExpression', () => {
639667
expect(evaluateRuntimeExpression(expression2, runtimeExpressionContext, logger)).toEqual(true);
640668
expect(evaluateRuntimeExpression(expression3, runtimeExpressionContext, logger)).toEqual(false);
641669
});
670+
671+
it('should evaluate list runtime expression value', () => {
672+
const expression = '$response.body#/items';
673+
expect(evaluateRuntimeExpression(expression, runtimeExpressionContext, logger)).toEqual([
674+
{
675+
name: 'item1',
676+
description: 'item1 description',
677+
},
678+
{
679+
name: 'item2',
680+
description: 'item2 description',
681+
},
682+
]);
683+
});
642684
});

packages/respect-core/src/modules/flow-runner/schema/schema-checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const ajvStrict = new Ajv({
2020
validateSchema: false,
2121
discriminator: true,
2222
allowUnionTypes: true,
23-
validateFormats: false,
23+
validateFormats: true,
2424
logger: false,
2525
verbose: true,
2626
defaultUnevaluatedProperties: false,

packages/respect-core/src/modules/runtime-expressions/evaluate.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,17 @@ function normalizeExpression(expression: string, context: RuntimeExpressionConte
152152
// Normalize the expression for evaluation by replacing hyphens with underscores and converting to lowercase
153153
const normalizedSymbolsExpression = normalizeSymbolsExpression(modifiedJsExpression);
154154

155-
// Remove the curly braces surrounding the expression (if any)
156-
const cleanedJsExpression = normalizedSymbolsExpression.replace(/{(.*?)}/g, '$1');
155+
// Remove the curly braces surrounding the ENTIRE expression (if any), but not braces within JSON
156+
let cleanedJsExpression = normalizedSymbolsExpression;
157+
158+
if (cleanedJsExpression.startsWith('{') && cleanedJsExpression.endsWith('}')) {
159+
// A runtime expression wrapper has the form {$variable...} with no nested braces until the end
160+
const potentialUnwrapped = cleanedJsExpression.slice(1, -1);
161+
// Unwrap if it doesn't look like JSON (i.e., doesn't start with { or [)
162+
if (!potentialUnwrapped.trim().startsWith('{') && !potentialUnwrapped.trim().startsWith('[')) {
163+
cleanedJsExpression = potentialUnwrapped;
164+
}
165+
}
157166

158167
// Convert numeric indices (e.g., `.0`) into square bracket notation (e.g., `[0]`)
159168
const expressionWithBrackets = convertNumericIndices(cleanedJsExpression);

0 commit comments

Comments
 (0)