Skip to content

Commit 80e7f5a

Browse files
MintsIncclaude
andauthored
Add path parameter support for undo operations (#3322)
Support extracting path parameters from request URLs for use in undo operations. This enables cleanup of resources identified by path parameters (e.g., /api/v2/resource/{id}). Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 05a3b0e commit 80e7f5a

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

features/step_definitions/request_steps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ When("the request is sent", async function (this: World) {
155155
this.operationId,
156156
this.response,
157157
this.opts,
158+
this.opts // Pass opts as pathParameters (contains all parameters including path ones)
158159
)
159160
);
160161
}

features/support/undo.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ function buildUndoFor(
4545
operationUndo: iUndoAction,
4646
operationOrig: string,
4747
response: any,
48-
request: any
48+
request: any,
49+
pathParameters: { [key: string]: any } = {}
4950
): { (): void } {
5051
return async function () {
5152
let apiName = operationUndo.tag.replace(/[\s-]/g, "");
@@ -88,19 +89,36 @@ function buildUndoFor(
8889
// perform operation
8990
const opts: { [key: string]: any } = {};
9091
for (const p of operationUndo.undo.parameters) {
91-
let dataSource: { [key: string]: any; };
92-
if (p.origin === undefined) {
92+
let dataSource: { [key: string]: any };
93+
if (p.origin === "path") {
94+
dataSource = pathParameters;
95+
} else if (p.origin === undefined) {
9396
dataSource = response;
9497
} else if (p.origin === "request") {
9598
dataSource = request.body;
9699
} else {
97100
dataSource = response;
98101
}
102+
99103
if (p.source !== undefined) {
100-
opts[p.name.toAttributeName()] = pathLookup(dataSource, p.source);
104+
if (p.origin === "path") {
105+
// For path parameters, try both attribute name and original name
106+
const attrName = p.source.toAttributeName();
107+
if (attrName in dataSource) {
108+
opts[p.name.toAttributeName()] = dataSource[attrName];
109+
} else if (p.source in dataSource) {
110+
opts[p.name.toAttributeName()] = dataSource[p.source];
111+
} else {
112+
throw new Error(`Path parameter '${p.source}' not found`);
113+
}
114+
} else {
115+
opts[p.name.toAttributeName()] = pathLookup(dataSource, p.source);
116+
}
101117
} else if (p.template !== undefined) {
102118
const data = JSON.parse(p.template.templated(dataSource));
103119
opts[p.name.toAttributeName()] = data;
120+
} else if (p.origin === "path") {
121+
throw new Error(`Path origin requires 'source' field`);
104122
}
105123
}
106124

features/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
async cleanup() {
2728
const undo = this.undo;

0 commit comments

Comments
 (0)