We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a62435c commit 5d42784Copy full SHA for 5d42784
packages/rest-api-construct/src/construct.ts
@@ -68,8 +68,16 @@ export class RestApiConstruct extends Construct {
68
root: apiGateway.IResource,
69
path: string,
70
): apiGateway.IResource {
71
- return path.split('/').reduce((resource, part) => {
72
- return resource.getResource(part) ?? resource.addResource(part);
73
- }, root);
+ // Split the path into parts (e.g. "posts/comments" → ["posts", "comments"])
+ const parts = path.split('/');
+
74
+ // Traverse the path, adding any missing nested resources along the way
75
+ let current = root;
76
+ for (const part of parts) {
77
+ const existing = current.getResource(part);
78
+ current = existing ?? current.addResource(part);
79
+ }
80
81
+ return current;
82
}
83
0 commit comments