oazapfts
Version:
OpenApi TypeScript client generator
91 lines (90 loc) • 2.85 kB
JavaScript
import { r as e, t, x as n } from "./context-BZ7CId2F.js";
import { d as r, l as i, n as a, u as o } from "./generateClientMethod-CQwJveeR.js";
import { UNSTABLE_OAZAPFTS_PLUGIN_PRECEDENCE as s, UNSTABLE_applyPlugins as c, UNSTABLE_createHooks as l, UNSTABLE_createPlugin as u } from "./plugin.js";
import d from "typescript";
import f from "@apidevtools/swagger-parser";
import { resolve as p } from "@oazapfts/resolve";
//#region src/internalPlugins/defaultComposeSource.ts
function m() {
return u((t) => {
t.composeSource.tap("defaultComposeSource", (t, n) => [
...t.imports.map(i),
o(t.defaults),
...t.init,
e(t.servers),
...t.aliases,
...n,
...t.enumAliases
]);
}, { precedence: s.LAZY });
}
//#endregion
//#region src/internalPlugins/defaultGenerateMethod.ts
function h() {
return u((e) => {
e.generateMethod.tapPromise("defaultGenerateMethod", async (t, n) => a(t.method, t.path, t.operation, t.pathItem, n, e));
}, { precedence: s.LAZY });
}
//#endregion
//#region src/internalPlugins/includeExcludeFilterEndpoint.ts
function g() {
return u((e) => {
e.filterEndpoint.tap("includeExcludeFilterEndpoint", (e, t, n) => {
if (!e) return !1;
let r = t.operation.tags;
return r && r.some((e) => n.opts?.exclude?.includes(e)) ? !1 : n.opts?.include ? !!(r && r.some((e) => n.opts.include?.includes(e))) : !0;
});
});
}
//#endregion
//#region src/internalPlugins/numericBooleanQueryParameters.ts
function _(e, t) {
return e.some((e) => {
let n = e.schema && p(e.schema, t);
return !!n && typeof n == "object" && n.type === "boolean";
});
}
function v() {
return u((e) => {
e.querySerializerArgs.tap("numericBooleanQueryParameters", (e, t, n) => !n.opts.numericBooleanQueryParameters || !_(t.query, n) ? e : [...e, d.factory.createPropertyAccessExpression(d.factory.createIdentifier("QS"), "numericBooleanReserved")]);
}, { precedence: s.LAZY });
}
//#endregion
//#region src/internalPlugins/index.ts
function y(e) {
return [
g(),
v(),
h(),
m()
];
}
//#endregion
//#region src/index.ts
async function b(e, n = {}) {
let r = await C(e), i = t(r, n);
return i.banner = [
r.info.title,
r.info.version,
i.banner
].filter(Boolean).join("\n"), S(await x(i, n.UNSTABLE_plugins));
}
async function x(e, t = []) {
let n = l();
return await c(n, [...y(e), ...t]), r(e, n);
}
function S(e) {
return n(e);
}
async function C(e) {
typeof e == "string" && e.startsWith("http") && (e = await (await fetch(e)).json());
let t = await f.bundle(e);
if (!w(t)) throw Error("Only OpenAPI v3 is supported\nYou may convert you spec with https://github.com/swagger-api/swagger-converter or swagger2openapi package");
return t;
}
function w(e) {
return "openapi" in e && e.openapi.startsWith("3");
}
//#endregion
export { S as i, b as n, C as r, x as t };
//# sourceMappingURL=src-CbQmhGca.js.map