foca-openapi
Version:
根据openapi文档生成请求客户端
52 lines (51 loc) • 1.99 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/adapters/fetch.ts
var fetch_exports = {};
__export(fetch_exports, {
fetchAdapter: () => fetchAdapter
});
module.exports = __toCommonJS(fetch_exports);
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();
}
};
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
fetchAdapter
});
//# sourceMappingURL=fetch.js.map