Skip to content

Commit fc8cbdb

Browse files
committed
Allow path variable in basePath
1 parent 66af3ab commit fc8cbdb

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/fetch/index.t-test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AsJsonApi, DefineApiEndpoints } from "../common";
1+
import { AsJsonApi, DefineApiEndpoints, ParseURL, Replace } from "../common";
22
import FetchT from "./index";
33
import JSONT from "../json";
44

@@ -138,3 +138,29 @@ import JSONT from "../json";
138138
});
139139
})();
140140
}
141+
142+
{
143+
type Spec = DefineApiEndpoints<{
144+
"/packages/list": {
145+
get: {
146+
headers: { Cookie: `a=${string}` };
147+
resBody: {
148+
200: { prop: string };
149+
};
150+
};
151+
};
152+
}>;
153+
(async () => {
154+
const basePath = "/api/projects/:projectName/workflow";
155+
const f = fetch as FetchT<typeof basePath, Spec>;
156+
const res = await f(
157+
`/api/projects/projectA/workflow/packages/list?state=true`,
158+
{
159+
headers: { Cookie: "a=b" },
160+
},
161+
);
162+
if (res.ok) {
163+
(await res.json()).prop;
164+
}
165+
})();
166+
}

src/fetch/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type FetchT<UrlPrefix extends UrlPrefixPattern, E extends ApiEndpoints> = <
3737
| `${ToUrlParamPattern<UrlPrefix>}${ToUrlParamPattern<keyof E & string>}`
3838
| `${ToUrlParamPattern<UrlPrefix>}${ToUrlParamPattern<keyof E & string>}?${string}`,
3939
InputPath extends NormalizePath<
40-
ParseURL<Replace<Input, UrlPrefix, "">>["path"]
40+
ParseURL<Replace<Input, ToUrlParamPattern<UrlPrefix>, "">>["path"]
4141
>,
4242
CandidatePaths extends MatchedPatterns<InputPath, keyof E & string>,
4343
InputMethod extends CaseInsensitiveMethod = "get",

0 commit comments

Comments
 (0)