@scalar/api-client
Version:
the open source API testing client
97 lines (96 loc) • 3.08 kB
JavaScript
import { defineComponent as k, computed as w, watch as R, createBlock as p, openBlock as u, withCtx as d, createCommentVNode as $, createTextVNode as K, toDisplayString as b } from "vue";
import { REGEX as x } from "@scalar/oas-utils/helpers";
import V from "../../../components/ViewLayout/ViewLayoutCollapse.vue.js";
import C from "./RequestTable.vue.js";
import { useWorkspace as q } from "../../../store/store.js";
const B = /* @__PURE__ */ k({
__name: "RequestPathParams",
props: {
example: {},
operation: {},
paramKey: {},
title: {},
environment: {},
envVariables: {},
workspace: {},
invalidParams: {}
},
setup(a) {
const { requestMutators: c, requestExampleMutators: s } = q(), m = w(
() => a.example.parameters[a.paramKey].map((e) => ({
...e,
enum: e.enum
}))
), h = (e, r, n) => {
const i = a.example.parameters[a.paramKey], o = i[e]?.key;
if (o) {
if (r === "key") {
if (i[e]?.required)
return;
if (n) {
const t = encodeURIComponent(o), l = encodeURIComponent(n), P = new RegExp(`(?<=/):${t}(?=[/?#]|$)`, "g"), g = a.operation.path.replace(P, `:${l}`);
c.edit(a.operation.uid, "path", g);
} else {
i.splice(e, 1);
const t = new RegExp(`/:${encodeURIComponent(o)}(?=[/?#]|$)`, "g"), l = a.operation.path.replace(t, "");
c.edit(a.operation.uid, "path", l);
}
}
s.edit(
a.example.uid,
`parameters.${a.paramKey}.${e}.${r}`,
n
);
}
}, f = (e) => {
const r = m.value;
if (r.length > e) {
const n = [...r];
n.splice(e, 1), s.edit(
a.example.uid,
`parameters.${a.paramKey}`,
n
);
}
}, v = (e) => {
const r = e.match(x.PATH)?.map((t) => t.slice(1, -1)) || [], n = a.example.parameters[a.paramKey], i = new Map(n.map((t) => [t.key, t])), o = r.map(
(t) => i.get(t) || { key: t, value: "", enabled: !0 }
);
n.forEach((t) => {
!r.includes(t.key) && (t.value || t.required) && o.push(t);
}), n.splice(0, n.length, ...o), s.edit(a.example.uid, `parameters.${a.paramKey}`, n);
}, y = (e) => {
e && v(e);
};
return R(
() => a.operation.path,
(e) => {
e && y(e);
}
), (e, r) => (u(), p(V, {
itemCount: m.value.length
}, {
title: d(() => [
K(b(e.title), 1)
]),
default: d(() => [
m.value.length ? (u(), p(C, {
key: 0,
class: "flex-1",
columns: ["32px", "", ""],
envVariables: e.envVariables,
environment: e.environment,
invalidParams: e.invalidParams,
items: m.value,
workspace: e.workspace,
onUpdateRow: h,
onDeleteRow: f
}, null, 8, ["envVariables", "environment", "invalidParams", "items", "workspace"])) : $("", !0)
]),
_: 1
}, 8, ["itemCount"]));
}
});
export {
B as default
};