rapidoc 11.0.1 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -31
- package/dist/rapidoc-min.js +1424 -213
- package/dist/rapidoc-static-min.js +13542 -0
- package/package.json +47 -35
- package/src/components/api-request.ts +869 -0
- package/src/components/api-response.ts +509 -0
- package/src/components/json-tree.ts +171 -0
- package/src/components/schema-base-element.ts +315 -0
- package/src/components/schema-table.ts +430 -0
- package/src/components/schema-tree.ts +386 -0
- package/src/components/tag-input.ts +184 -0
- package/src/index.js +6 -0
- package/src/oauth-receiver.ts +29 -0
- package/src/rapidoc-mini.ts +582 -0
- package/src/rapidoc.ts +1808 -0
- package/src/static/index.d.ts +149 -0
- package/src/static/index.js +62 -0
- package/src/static/navigation.js +497 -0
- package/src/static/render.js +490 -0
- package/src/static/serializer.js +216 -0
- package/src/styles/auth-styles.js +318 -0
- package/src/styles/border-styles.js +24 -0
- package/src/styles/css-bundle.js +129 -0
- package/src/styles/custom-styles.js +8 -0
- package/src/styles/dialog-box-styles.js +102 -0
- package/src/styles/endpoint-styles.js +559 -0
- package/src/styles/flex-styles.js +16 -0
- package/src/styles/font-styles.js +432 -0
- package/src/styles/info-styles.js +36 -0
- package/src/styles/input-styles.js +555 -0
- package/src/styles/layout-styles.js +396 -0
- package/src/styles/microlighter-styles.js +99 -0
- package/src/styles/nav-styles.js +609 -0
- package/src/styles/param-list-styles.js +261 -0
- package/src/styles/schema-styles.js +288 -0
- package/src/styles/tab-styles.js +106 -0
- package/src/styles/theme-tokens.js +582 -0
- package/src/templates/advanced-search-dialog-template.js +94 -0
- package/src/templates/api-response-template.js +219 -0
- package/src/templates/callback-template.js +86 -0
- package/src/templates/code-samples-template.js +52 -0
- package/src/templates/components-template.js +86 -0
- package/src/templates/downloads-template.js +85 -0
- package/src/templates/endpoint-template.js +386 -0
- package/src/templates/expanded-endpoint-template.js +266 -0
- package/src/templates/focused-endpoint-template.js +145 -0
- package/src/templates/header-template.js +92 -0
- package/src/templates/logo-template.js +21 -0
- package/src/templates/main-body-template.js +102 -0
- package/src/templates/navbar-template.js +489 -0
- package/src/templates/overview-template.js +104 -0
- package/src/templates/request-body-template.js +651 -0
- package/src/templates/request-params-template.js +474 -0
- package/src/templates/security-scheme-template.js +1263 -0
- package/src/templates/server-template.js +152 -0
- package/src/utils/auto-color-scheme.js +99 -0
- package/src/utils/bind-navbar.js +175 -0
- package/src/utils/color-utils.js +59 -0
- package/src/utils/common-utils.js +191 -0
- package/src/utils/curl-utils.js +123 -0
- package/src/utils/highlighter.js +416 -0
- package/src/utils/markdown-utils.js +110 -0
- package/src/utils/mcp/common.js +467 -0
- package/src/utils/mcp/generators/csharp.js +242 -0
- package/src/utils/mcp/generators/go.js +298 -0
- package/src/utils/mcp/generators/java.js +330 -0
- package/src/utils/mcp/generators/python.js +248 -0
- package/src/utils/mcp/generators/rust.js +281 -0
- package/src/utils/mcp/generators/typescript.js +290 -0
- package/src/utils/mcp-generator.js +143 -0
- package/src/utils/mock-interceptor.js +508 -0
- package/src/utils/oauth-utils.js +87 -0
- package/src/utils/request-utils.js +203 -0
- package/src/utils/response-utils.js +203 -0
- package/src/utils/sanitize.js +57 -0
- package/src/utils/schema-utils.js +1927 -0
- package/src/utils/slugger.js +189 -0
- package/src/utils/spec-parser.js +915 -0
- package/src/utils/url-utils.js +211 -0
- package/src/utils/xml-utils.js +61 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import Slugger from "github-slugger";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts any string (camelCase, PascalCase, snake_case, spaces, slashes) to clean kebab-case.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} str
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
export function toKebabCase(str) {
|
|
10
|
+
return String(str || "")
|
|
11
|
+
.trim()
|
|
12
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1-$2")
|
|
13
|
+
.replace(/([A-Z])([A-Z][a-z])/g, "$1-$2")
|
|
14
|
+
.replace(/[_\s/\\.]+/g, "-")
|
|
15
|
+
.replace(/[^a-zA-Z0-9-]/g, "")
|
|
16
|
+
.replace(/-+/g, "-")
|
|
17
|
+
.replace(/^-+|-+$/g, "")
|
|
18
|
+
.toLowerCase();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Clamps a slug at a word boundary to prevent URL bloat from lengthy summaries.
|
|
23
|
+
*
|
|
24
|
+
* @param {string} slug
|
|
25
|
+
* @param {number} [maxLen=40]
|
|
26
|
+
* @returns {string}
|
|
27
|
+
*/
|
|
28
|
+
export function clampWordBoundary(slug, maxLen = 40) {
|
|
29
|
+
if (!slug || slug.length <= maxLen) return slug;
|
|
30
|
+
const cut = slug.slice(0, maxLen);
|
|
31
|
+
const lastHyphen = cut.lastIndexOf("-");
|
|
32
|
+
return lastHyphen > 8 ? cut.slice(0, lastHyphen) : cut;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Anchor for an operation built from its method and path only (e.g. "get-routes-id-estimate"). It changes
|
|
37
|
+
* only when the endpoint itself changes, so every operation can also be reached by it (see getTargetElement).
|
|
38
|
+
*
|
|
39
|
+
* @param {string} method
|
|
40
|
+
* @param {string} path
|
|
41
|
+
* @returns {string}
|
|
42
|
+
*/
|
|
43
|
+
export function methodPathSlug(method, path) {
|
|
44
|
+
const cleanMethod = (method || "get").toLowerCase();
|
|
45
|
+
const cleanPath = (path || "")
|
|
46
|
+
.replace(/[{}]/g, "")
|
|
47
|
+
.replace(/[^a-zA-Z0-9]+/g, "-")
|
|
48
|
+
.replace(/^-+|-+$/g, "");
|
|
49
|
+
return cleanPath ? `${cleanMethod}-${cleanPath}` : cleanMethod;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Which field an operation's anchor is built from: 'operationId' (stable), 'summary' (changes when the
|
|
54
|
+
* summary is edited) or 'path' (method + path). Mirrors the candidate order of OperationSlugger.slugOp().
|
|
55
|
+
*
|
|
56
|
+
* @param {Object} op - Operation object with { operationId, summary }
|
|
57
|
+
* @returns {'operationId' | 'summary' | 'path'}
|
|
58
|
+
*/
|
|
59
|
+
export function operationAnchorSource(op = {}) {
|
|
60
|
+
if (typeof op.operationId === "string") {
|
|
61
|
+
const trimmed = op.operationId.trim();
|
|
62
|
+
if (
|
|
63
|
+
trimmed.length > 0 &&
|
|
64
|
+
trimmed.length <= 45 &&
|
|
65
|
+
!/^(endpoint|operation|method|api)[-_]?\d+$/i.test(trimmed) &&
|
|
66
|
+
toKebabCase(trimmed)
|
|
67
|
+
) {
|
|
68
|
+
return "operationId";
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (typeof op.summary === "string" && toKebabCase(op.summary.trim().slice(0, 100))) {
|
|
72
|
+
return "summary";
|
|
73
|
+
}
|
|
74
|
+
return "path";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Deterministic, collision-free operation anchor slugger for OpenAPI specs.
|
|
79
|
+
*/
|
|
80
|
+
export class OperationSlugger {
|
|
81
|
+
constructor() {
|
|
82
|
+
this.slugger = new Slugger();
|
|
83
|
+
this.used = new Set();
|
|
84
|
+
this.opMap = new Map();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
reset() {
|
|
88
|
+
this.slugger.reset();
|
|
89
|
+
this.used.clear();
|
|
90
|
+
this.opMap.clear();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Generates a clean operation slug candidate (without tag prefix).
|
|
95
|
+
*
|
|
96
|
+
* @param {Object} op - Operation object with { method, path, operationId, summary }
|
|
97
|
+
* @returns {string} Operation slug candidate
|
|
98
|
+
*/
|
|
99
|
+
slugOp(op = {}) {
|
|
100
|
+
const source = operationAnchorSource(op);
|
|
101
|
+
|
|
102
|
+
// Candidate 1: operationId (if concise: <= 45 chars and not a generic placeholder)
|
|
103
|
+
if (source === "operationId") {
|
|
104
|
+
return toKebabCase(op.operationId.trim());
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Candidate 2: summary (with early 100-char pre-slice and 40-char word-boundary clamp)
|
|
108
|
+
if (source === "summary") {
|
|
109
|
+
return clampWordBoundary(toKebabCase(op.summary.trim().slice(0, 100)), 40);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Candidate 3: Method + Clean Path (guaranteed fallback if both opId and summary are missing)
|
|
113
|
+
return methodPathSlug(op.method, op.path);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Generates a clean, unique elementId for an operation.
|
|
118
|
+
*
|
|
119
|
+
* @param {Object} op - Operation object with { method, path, operationId, summary }
|
|
120
|
+
* @param {string} [tagSlug=''] - Optional tag slug for hierarchical routing
|
|
121
|
+
* @returns {string} Unique elementId
|
|
122
|
+
*/
|
|
123
|
+
slug(op = {}, tagSlug = "") {
|
|
124
|
+
const opKey = tagSlug
|
|
125
|
+
? `${tagSlug}:${(op.method || "get").toLowerCase()} ${op.path || ""}`
|
|
126
|
+
: `${(op.method || "get").toLowerCase()} ${op.path || ""}`;
|
|
127
|
+
|
|
128
|
+
if (this.opMap.has(opKey)) {
|
|
129
|
+
return this.opMap.get(opKey);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
let candidate = this.slugOp(op);
|
|
133
|
+
|
|
134
|
+
// Smart semantic collision differentiator:
|
|
135
|
+
// If the base candidate has already been seen in this spec, attempt method-prefix first (e.g. post-webhooks)
|
|
136
|
+
if (this.used.has(candidate)) {
|
|
137
|
+
const method = (op.method || "get").toLowerCase();
|
|
138
|
+
const methodCandidate = `${method}-${candidate}`;
|
|
139
|
+
if (!this.used.has(methodCandidate)) {
|
|
140
|
+
candidate = methodCandidate;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Hierarchical style prefixes with tag if provided
|
|
145
|
+
if (tagSlug && tagSlug !== "general") {
|
|
146
|
+
candidate = `${tagSlug}--${candidate}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Guaranteed uniqueness via GitHub slugger registry
|
|
150
|
+
const finalSlug = this.slugger.slug(candidate);
|
|
151
|
+
this.used.add(finalSlug);
|
|
152
|
+
if (opKey) {
|
|
153
|
+
this.opMap.set(opKey, finalSlug);
|
|
154
|
+
}
|
|
155
|
+
return finalSlug;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Generates a clean elementId for a tag.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} name
|
|
162
|
+
* @returns {string}
|
|
163
|
+
*/
|
|
164
|
+
slugTag(name) {
|
|
165
|
+
return `tag--${toKebabCase(name)}`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Generates a clean elementId for a tag group.
|
|
170
|
+
*
|
|
171
|
+
* @param {string} name
|
|
172
|
+
* @returns {string}
|
|
173
|
+
*/
|
|
174
|
+
slugTagGroup(name) {
|
|
175
|
+
return `tag-group--${toKebabCase(name)}`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Factory helper to create an OperationSlugger instance.
|
|
181
|
+
*
|
|
182
|
+
* @param {Object} [options]
|
|
183
|
+
* @returns {OperationSlugger}
|
|
184
|
+
*/
|
|
185
|
+
export function createSlugger(options) {
|
|
186
|
+
return new OperationSlugger(options);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export default OperationSlugger;
|