@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
189 lines (188 loc) • 8.04 kB
JavaScript
import { defineComponent as w, computed as t, createBlock as d, openBlock as n, resolveDynamicComponent as A, normalizeClass as T, withCtx as c, createCommentVNode as s, createElementBlock as o, createVNode as m, createSlots as q, unref as i, toDisplayString as v, Fragment as f, createTextVNode as P, renderList as E } from "vue";
import { ScalarMarkdown as O } from "@scalar/components";
import { isDefined as F } from "@scalar/helpers/array/is-defined";
import { getResolvedRef as y } from "@scalar/workspace-store/helpers/get-resolved-ref";
import { isArraySchema as u } from "@scalar/workspace-store/schemas/v3.1/strict/type-guards";
import { isTypeObject as M } from "./helpers/is-type-object.js";
import { optimizeValueForDisplay as $ } from "./helpers/optimize-value-for-display.js";
import { compositions as I } from "./helpers/schema-composition.js";
import C from "./Schema.vue.js";
import z from "./SchemaComposition.vue.js";
import U from "./SchemaEnumValues.vue.js";
import Z from "./SchemaPropertyHeading.vue.js";
import L from "../../Anchor/WithBreadcrumb.vue2.js";
import G from "../../../features/specification-extension/SpecificationExtension.vue2.js";
const J = {
key: 0,
class: "property-name-pattern-properties"
}, K = {
key: 1,
class: "property-name-additional-properties"
}, Q = {
key: 1,
class: "property-description"
}, W = {
key: 2,
class: "property-description"
}, X = {
key: 4,
class: "children"
}, Y = {
key: 0,
class: "children"
}, de = /* @__PURE__ */ w({
__name: "SchemaProperty",
props: {
is: {},
schema: {},
noncollapsible: { type: Boolean },
level: { default: 0 },
name: {},
required: { type: Boolean, default: !1 },
compact: { type: Boolean, default: !1 },
discriminator: {},
description: {},
hideModelNames: { type: Boolean, default: !1 },
hideHeading: { type: Boolean },
variant: {},
breadcrumb: {},
options: {}
},
setup(j) {
const p = j, b = {
integer: {
_default: "Integer numbers.",
int32: "Signed 32-bit integers (commonly used integer type).",
int64: "Signed 64-bit integers (long type)."
},
string: {
date: "full-date notation as defined by RFC 3339, section 5.6, for example, 2017-07-21",
"date-time": "the date-time notation as defined by RFC 3339, section 5.6, for example, 2017-07-21T17:32:28Z",
password: "a hint to UIs to mask the input",
base64: "base64-encoded characters, for example, U3dhZ2dlciByb2Nrcw==",
byte: "base64-encoded characters, for example, U3dhZ2dlciByb2Nrcw==",
binary: "binary data, used to describe files"
}
}, h = (e) => !e || !b[e.type] ? null : b[e.type][e.format || e.contentEncoding || "_default"], B = (e) => e?.enum || e?.items?.enum || [], a = t(() => $(p.schema)), g = t(() => {
const e = a.value;
return !e || "properties" in e || "additionalProperties" in e || "patternProperties" in e || e?.allOf || e?.allOf ? null : p.description || e?.description || null;
}), N = (e, r, l) => r || e?.deprecated || e?.const !== void 0 || e?.enum && e.enum.length === 1 || e?.type || e?.nullable === !0 || e?.writeOnly || e?.readOnly || l, k = t(() => {
const e = a.value;
if (!e || !u(e) || typeof e.items != "object")
return !1;
const r = e.items;
return "type" in r && r.type && (Array.isArray(r.type) ? r.type.includes("object") : ["object"].includes(r.type)) || "properties" in r || "$ref" in r || "discriminator" in r || "allOf" in r || "oneOf" in r || "anyOf" in r;
}), S = (e) => {
const r = a.value;
return r && u(r) === !1 || !r?.items || typeof r.items != "object" || !(e in r.items) ? !1 : !k.value;
}, R = t(() => k.value), D = t(() => {
if (!a.value)
return !1;
const e = a.value, r = M(e), l = "properties" in e || "additionalProperties" in e;
return r && l;
}), H = t(() => p.level <= 1), V = t(() => a.value ? I.map((e) => a.value?.[e] && !(u(a.value) && a.value?.items && typeof e == "string" && typeof a.value.items == "object" && e in a.value.items) ? {
composition: e,
value: a.value
} : S(e) && a.value && u(a.value) && a.value.items ? {
composition: e,
value: a.value.items
} : null).filter(F) : []);
return (e, r) => (n(), d(A(e.is ?? "li"), {
class: T(["property", [
`property--level-${e.level}`,
{
"property--compact": e.compact,
"property--deprecated": a.value?.deprecated
}
]])
}, {
default: c(() => [
N(a.value, e.name, e.required) ? (n(), d(Z, {
key: 0,
class: "group",
enum: B(a.value).length > 0,
hideModelNames: e.hideModelNames,
isDiscriminator: e.discriminator && e.discriminator.propertyName === e.name,
required: e.required,
value: a.value
}, q({ _: 2 }, [
e.name ? {
name: "name",
fn: c(() => [
m(i(L), {
breadcrumb: H.value && e.breadcrumb ? [...e.breadcrumb, e.name] : void 0
}, {
default: c(() => [
e.variant === "patternProperties" ? (n(), o("span", J, v(e.name), 1)) : e.variant === "additionalProperties" ? (n(), o("span", K, v(e.name), 1)) : (n(), o(f, { key: 2 }, [
P(v(e.name), 1)
], 64))
]),
_: 1
}, 8, ["breadcrumb"])
]),
key: "0"
} : void 0,
a.value?.example ? {
name: "example",
fn: c(() => [
P(" Example: " + v(a.value.example), 1)
]),
key: "1"
} : void 0
]), 1032, ["enum", "hideModelNames", "isDiscriminator", "required", "value"])) : s("", !0),
g.value ? (n(), o("div", Q, [
m(i(O), { value: g.value }, null, 8, ["value"])
])) : h(a.value) ? (n(), o("div", W, [
m(i(O), {
value: h(a.value) || ""
}, null, 8, ["value"])
])) : s("", !0),
(a.value?.enum || a.value && i(u)(a.value) && i(y)(a.value?.items)?.enum || []).length ? (n(), d(U, {
key: 3,
value: a.value
}, null, 8, ["value"])) : s("", !0),
D.value ? (n(), o("div", X, [
m(C, {
breadcrumb: e.breadcrumb && e.name ? [...e.breadcrumb, e.name] : void 0,
compact: e.compact,
level: e.level + 1,
name: e.name,
noncollapsible: e.noncollapsible,
options: e.options,
schema: a.value
}, null, 8, ["breadcrumb", "compact", "level", "name", "noncollapsible", "options", "schema"])
])) : s("", !0),
a.value && i(u)(a.value) && typeof a.value.items == "object" ? (n(), o(f, { key: 5 }, [
R.value ? (n(), o("div", Y, [
m(C, {
compact: e.compact,
level: e.level + 1,
name: e.name,
noncollapsible: e.noncollapsible,
options: e.options,
schema: i(y)(a.value.items)
}, null, 8, ["compact", "level", "name", "noncollapsible", "options", "schema"])
])) : s("", !0)
], 64)) : s("", !0),
(n(!0), o(f, null, E(V.value, (l) => (n(), d(z, {
key: l.composition,
breadcrumb: e.breadcrumb,
compact: e.compact,
composition: l.composition,
discriminator: e.schema?.discriminator,
hideHeading: e.hideHeading,
level: e.level,
name: e.name,
noncollapsible: e.noncollapsible,
options: e.options,
schema: i(y)(p.schema)
}, null, 8, ["breadcrumb", "compact", "composition", "discriminator", "hideHeading", "level", "name", "noncollapsible", "options", "schema"]))), 128)),
m(i(G), { value: a.value }, null, 8, ["value"])
]),
_: 1
}, 8, ["class"]));
}
});
export {
de as default
};