UNPKG

@scalar/api-client

Version:

the open source API testing client

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