Skip to content

Commit a6b0a16

Browse files
feat(respect): added support for runtime expression in the url property of the x-operation (#2517)
1 parent 49e575a commit a6b0a16

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

.changeset/light-deer-send.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@redocly/respect-core": minor
3+
---
4+
5+
Added support for runtime expressions in the `url` property of the Respect `x-operation` extension.

packages/respect-core/src/modules/__tests__/flow-runner/get-server-url.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,23 @@ describe('getServerUrl', () => {
161161
expect(result).toEqual({ url: 'http:/localhost:3000/test' });
162162
});
163163

164+
it('should resolve runtime expression in "x-operation" url', () => {
165+
const ctx = {
166+
$steps: {
167+
test: { outputs: { upload_url: 'http://localhost:3000/test' } },
168+
},
169+
options: {
170+
logger,
171+
},
172+
} as unknown as TestContext;
173+
const result = getServerUrl({
174+
ctx,
175+
descriptionName: '',
176+
xOperation: { url: '$steps.test.outputs.upload_url', method: 'get' },
177+
});
178+
expect(result).toEqual({ url: 'http://localhost:3000/test' });
179+
});
180+
164181
it('should return x-serverUrl when available when descriptionName is not provided and there is only one sourceDescription', () => {
165182
const ctx: TestContext = {
166183
sourceDescriptions: [

packages/respect-core/src/modules/flow-runner/get-server-url.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getValueFromContext } from '../context-parser/index.js';
22
import { formatCliInputs } from './inputs/index.js';
3+
import { evaluateRuntimeExpressionPayload } from '../runtime-expressions/evaluate.js';
34

45
import type { ExtendedOperation, TestContext } from '../../types.js';
56
import type { OperationDetails } from '../description-parser/index.js';
@@ -31,7 +32,13 @@ export function getServerUrl({
3132
xOperation,
3233
}: GetServerUrlInput): { url: string } | undefined {
3334
if (!descriptionName && xOperation?.url) {
34-
return { url: xOperation?.url };
35+
const resolvedUrl = evaluateRuntimeExpressionPayload({
36+
payload: xOperation?.url,
37+
context: ctx,
38+
logger: ctx.options.logger,
39+
});
40+
41+
return { url: resolvedUrl };
3542
}
3643

3744
// Handle server overrides from command line `server` option

0 commit comments

Comments
 (0)