UNPKG

foca-openapi

Version:

根据openapi文档生成请求客户端

27 lines 972 B
// src/adapters/fetch.ts var fetchAdapter = (opts) => { const { fetch: fetcher = fetch, baseURL, fetchOptions = {} } = opts; return { async request(opts2, utils) { const url = baseURL + utils.uriConcatQuery(opts2.uri, opts2.query); const body = utils.formatBody(opts2.requestBodyType, opts2.body); const credentials = typeof opts2.credentials === "string" ? opts2.credentials : opts2.credentials === true ? "same-origin" : "omit"; const config = { ...fetchOptions, method: opts2.method, body: body instanceof FormData ? body : JSON.stringify(body), headers: { ...fetchOptions.headers || {}, ...opts2.headers }, credentials }; const response = await fetcher(url, opts2.onBeforeRequest?.(config) || config); return opts2.responseType === "json" ? response.json() : response.text(); } }; }; export { fetchAdapter }; //# sourceMappingURL=fetch.js.map