Skip to content

Commit

Permalink
split path vars separately from proceeding path
Browse files Browse the repository at this point in the history
  • Loading branch information
Blodir committed Feb 3, 2025
1 parent 0070807 commit 0226bd8
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions projects/laji-api-client-b/src/laji-api-client-b.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ const splitAndResolvePath = <
M extends Method<P>,
>(path: P, params?: Parameters<paths[P][M]>): string[] => {
// parse path into segments based on path parameters
// eg. "/person/{personToken}/profile" -> ["/person", "/{personToken}/profile"]

// using a lookahead makes the split not consume the matching substrings
// but instead we are splitting *before* the pattern
// using a non-capturing group (?:...) avoids duplicates in the split output
// matches start with `/` such that there's a beginning `/` but no trailing `/`
const segments = path.split(/(?=(?:\/\{[^}]+\}))/);
// eg. "/person/{personToken}/profile" -> ["/person", "/{personToken}", "/profile"]
const segments = path.split(/(\/\{[^}]+\})/).filter(Boolean);

if (!params) {
return segments;
Expand Down

0 comments on commit 0226bd8

Please sign in to comment.