typed-openapi
typed-openapi copied to clipboard
Path parameters not automatically replaced?
Should we have to manually replace the path params? If I have an endpoint, /Patient/{patient_id}
, the patient_id is not getting replaced by the parameter.
Here is how I am doing it right now:
const patientData = await api.get("/Patient/{patient_id}", {
path: { patient_id: path.patient_id },
});
export const api = createApiClient(async (method, url, params) => {
const canvasToken = await ensureValidToken();
const headers = {
Authorization: `Bearer ${canvasToken}`,
Accept: "application/json",
};
const options: RequestInit = { method, headers };
if (params) {
if (method === "post" || method === "put") {
options.body = JSON.stringify(params);
} else if (method === "get") {
// console.log(method, url, params, "parameters");
}
}
if (params?.path) {
Object.entries(params.path).forEach(([key, value]) => {
if (typeof value === "string") {
url = url.replace(`{${key}}`, value);
}
});
}
return fetch(url, options).then((res) => res.json());
}, env.FUMAGE_BASE_URL);