@scalar/api-reference
Version:
Generate beautiful API references from OpenAPI documents
35 lines (34 loc) • 1.27 kB
JavaScript
import { isSchema } from "@scalar/workspace-store/schemas/v3.1/strict/type-guards";
const TYPE_DESCRIPTIONS = {
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"
}
};
const getPropertyDescription = (value) => {
if (!isSchema(value)) {
return null;
}
const type = Array.isArray(value.type) ? value.type[0] : value.type;
if (!type) {
return null;
}
const typeDescriptions = TYPE_DESCRIPTIONS[type];
if (!typeDescriptions) {
return null;
}
const format = "format" in value && value.format || "contentEncoding" in value && value.contentEncoding || "_default";
return typeDescriptions[format] ?? null;
};
export {
getPropertyDescription
};