typed-openapi icon indicating copy to clipboard operation
typed-openapi copied to clipboard

Path parameters not automatically replaced?

Open trevorpfiz opened this issue 1 year ago • 4 comments

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);

trevorpfiz avatar Dec 02 '23 05:12 trevorpfiz