Skip to content

Commit 1b4c08b

Browse files
MintsIncclaude
andauthored
Add path parameter support for undo operations in v2 (#3333)
BDD test undo operations previously could only extract parameters from response bodies or request bodies. This prevented proper cleanup of resources where identifiers exist only in the request URL path. This adds support for origin: "path" in undo.json definitions, allowing undo operations to reference path parameters from the original request. - Added pathParameters field to World class - Modified buildUndoFor to accept and handle path parameters - Updated step definitions to pass path parameters during request setup Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent f7c3328 commit 1b4c08b

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

private/bdd_runner/src/step_definitions/request_steps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ When("the request is sent", async function (this: World) {
151151
this.response,
152152
this.opts,
153153
this.servicesDir,
154+
this.opts,
154155
),
155156
);
156157
}

private/bdd_runner/src/support/undo.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function buildUndoFor(
4545
response: any,
4646
request: any,
4747
servicesDir: string,
48+
pathParameters: { [key: string]: any } = {},
4849
): { (): void } {
4950
return async function () {
5051
const apiName: string = tagToApiClassName(operationUndo.tag);
@@ -84,22 +85,38 @@ function buildUndoFor(
8485
const opts: { [key: string]: any } = {};
8586
for (const p of operationUndo.undo.parameters) {
8687
let dataSource: { [key: string]: any };
87-
if (p.origin === undefined) {
88+
if (p.origin === "path") {
89+
dataSource = pathParameters;
90+
} else if (p.origin === undefined) {
8891
dataSource = response;
8992
} else if (p.origin === "request") {
9093
dataSource = request.body;
9194
} else {
9295
dataSource = response;
9396
}
9497
if (p.source !== undefined) {
95-
opts[p.name.toAttributeName()] = pathLookup(dataSource, p.source);
98+
if (p.origin === "path") {
99+
// For path parameters, try both attribute name and original name
100+
const attrName = p.source.toAttributeName();
101+
if (attrName in dataSource) {
102+
opts[p.name.toAttributeName()] = dataSource[attrName];
103+
} else if (p.source in dataSource) {
104+
opts[p.name.toAttributeName()] = dataSource[p.source];
105+
} else {
106+
throw new Error(`Path parameter '${p.source}' not found`);
107+
}
108+
} else {
109+
opts[p.name.toAttributeName()] = pathLookup(dataSource, p.source);
110+
}
96111
} else if (p.template !== undefined) {
97112
const data = JSON.parse(p.template.templated(dataSource));
98113
const param: { [key: string]: any } = {};
99114
for (const [key, value] of Object.entries(data)) {
100115
param[key.toAttributeName()] = value;
101116
}
102117
opts[p.name.toAttributeName()] = param;
118+
} else if (p.origin === "path") {
119+
throw new Error(`Path origin requires 'source' field`);
103120
}
104121
}
105122
try {

private/bdd_runner/src/support/world.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export class World {
2222

2323
public fixtures: { [key: string]: any } = {};
2424
public opts: { [key: string]: any } = {};
25+
public pathParameters: { [key: string]: any } = {};
2526

2627
public cassettesDir: string;
2728
public packagePrefix: string;

0 commit comments

Comments
 (0)