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