@scalar/openapi-to-markdown 1.5.3 → 1.6.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/CHANGELOG.md +29 -0
- package/README.md +27 -1
- package/dist/create-markdown-from-openapi.d.ts +5 -2
- package/dist/create-markdown-from-openapi.d.ts.map +1 -1
- package/dist/create-markdown-from-openapi.js +7 -3
- package/dist/document-anchors.d.ts.map +1 -1
- package/dist/document-anchors.js +4 -2
- package/dist/document-examples.d.ts.map +1 -1
- package/dist/document-examples.js +10 -5
- package/dist/get-markdown-examples.d.ts.map +1 -1
- package/dist/get-markdown-examples.js +48 -24
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/load-document.d.ts +8 -1
- package/dist/load-document.d.ts.map +1 -1
- package/dist/load-document.js +34 -23
- package/dist/markdown/index.d.ts +5 -0
- package/dist/markdown/index.d.ts.map +1 -0
- package/dist/markdown/index.js +4 -0
- package/dist/markdown-nodes.d.ts.map +1 -1
- package/dist/markdown-nodes.js +1 -0
- package/dist/parse-description.d.ts.map +1 -1
- package/dist/parse-description.js +36 -18
- package/dist/render-document.d.ts.map +1 -1
- package/dist/render-document.js +50 -26
- package/dist/render-examples.d.ts.map +1 -1
- package/dist/render-examples.js +8 -4
- package/dist/render-operation-details.d.ts.map +1 -1
- package/dist/render-operation-details.js +28 -14
- package/dist/render-operation.d.ts.map +1 -1
- package/dist/render-operation.js +60 -31
- package/dist/render-schema.d.ts.map +1 -1
- package/dist/render-schema.js +145 -77
- package/dist/render-security.d.ts.map +1 -1
- package/dist/render-security.js +12 -6
- package/dist/render-tags.d.ts +7 -0
- package/dist/render-tags.d.ts.map +1 -0
- package/dist/render-tags.js +73 -0
- package/dist/restore-boolean-schemas.d.ts.map +1 -1
- package/dist/restore-boolean-schemas.js +22 -11
- package/dist/select-document.d.ts.map +1 -1
- package/dist/select-document.js +5 -1
- package/package.json +14 -9
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Keep tag ancestry visible without exceeding Markdown's six heading levels. */
|
|
2
|
+
export const getTagSections = (tags, openapiVersion) => {
|
|
3
|
+
const nested = /^3\.2\./.test(openapiVersion);
|
|
4
|
+
const label = (tag) => (nested ? (tag.summary ?? tag.name) : tag.name);
|
|
5
|
+
const byName = new Map(tags.map((tag) => [tag.name, tag]));
|
|
6
|
+
// Duplicate names cannot identify a parent unambiguously. Preserve every declaration.
|
|
7
|
+
if (!nested || byName.size !== tags.length) {
|
|
8
|
+
return tags.map((tag) => ({ tag, title: label(tag) }));
|
|
9
|
+
}
|
|
10
|
+
const titles = new Map();
|
|
11
|
+
const parents = new Map();
|
|
12
|
+
const invalid = new Set();
|
|
13
|
+
for (const tag of tags) {
|
|
14
|
+
const chain = [];
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
const pending = [tag];
|
|
17
|
+
while (pending.length) {
|
|
18
|
+
const current = pending.pop();
|
|
19
|
+
if (seen.has(current.name) || invalid.has(current.name)) {
|
|
20
|
+
// Invalid cycles and chains leading into them stay flat, like reference navigation.
|
|
21
|
+
for (const member of chain) {
|
|
22
|
+
titles.set(member.name, label(member));
|
|
23
|
+
invalid.add(member.name);
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
if (titles.has(current.name)) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
seen.add(current.name);
|
|
31
|
+
chain.push(current);
|
|
32
|
+
const parent = current.parent === undefined ? undefined : byName.get(current.parent);
|
|
33
|
+
if (parent) {
|
|
34
|
+
pending.push(parent);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const current of chain.reverse()) {
|
|
38
|
+
if (titles.has(current.name)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const parentTitle = current.parent === undefined ? undefined : titles.get(current.parent);
|
|
42
|
+
titles.set(current.name, parentTitle === undefined ? label(current) : `${parentTitle} › ${label(current)}`);
|
|
43
|
+
if (parentTitle !== undefined && current.parent !== undefined) {
|
|
44
|
+
parents.set(current.name, current.parent);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const children = new Map();
|
|
49
|
+
const roots = [];
|
|
50
|
+
for (const tag of tags) {
|
|
51
|
+
const parent = parents.get(tag.name);
|
|
52
|
+
if (parent === undefined) {
|
|
53
|
+
roots.push(tag);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const siblings = children.get(parent) ?? [];
|
|
57
|
+
siblings.push(tag);
|
|
58
|
+
children.set(parent, siblings);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const sections = [];
|
|
62
|
+
const pending = roots.reverse();
|
|
63
|
+
while (pending.length) {
|
|
64
|
+
const tag = pending.pop();
|
|
65
|
+
sections.push({ tag, title: titles.get(tag.name) });
|
|
66
|
+
// Use a stack instead of recursion so deeply nested descriptions cannot exhaust the call stack.
|
|
67
|
+
const siblings = children.get(tag.name) ?? [];
|
|
68
|
+
for (const child of [...siblings].reverse()) {
|
|
69
|
+
pending.push(child);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return sections;
|
|
73
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restore-boolean-schemas.d.ts","sourceRoot":"","sources":["../src/restore-boolean-schemas.ts"],"names":[],"mappings":"AAEA,kGAAkG;AAClG,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAA;AAmB1D;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,cAAc,EAAE,KAAK,MAAM,KAAG,cAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"restore-boolean-schemas.d.ts","sourceRoot":"","sources":["../src/restore-boolean-schemas.ts"],"names":[],"mappings":"AAEA,kGAAkG;AAClG,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAA;AAmB1D;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,cAAc,EAAE,KAAK,MAAM,KAAG,cAAc,GAAG,SAuBzF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAChC,QAAQ,OAAO,EACf,QAAQ,OAAO,EACf,WAAU,cAA2B,KACpC,IAoCF,CAAA"}
|
|
@@ -20,21 +20,27 @@ const schemaFields = new Set([
|
|
|
20
20
|
* is not part of the schema tree, such as example payloads and schema metadata.
|
|
21
21
|
*/
|
|
22
22
|
export const getChildPosition = (position, key) => {
|
|
23
|
-
if (position === 'map')
|
|
23
|
+
if (position === 'map') {
|
|
24
24
|
return 'schema';
|
|
25
|
+
}
|
|
25
26
|
if (position === 'schema') {
|
|
26
|
-
if (schemaMaps.has(key))
|
|
27
|
+
if (schemaMaps.has(key)) {
|
|
27
28
|
return 'map';
|
|
28
|
-
|
|
29
|
+
}
|
|
30
|
+
if (schemaArrays.has(key) || schemaFields.has(key)) {
|
|
29
31
|
return 'schema';
|
|
32
|
+
}
|
|
30
33
|
return undefined;
|
|
31
34
|
}
|
|
32
|
-
if (key === 'schema' || key === 'itemSchema')
|
|
35
|
+
if (key === 'schema' || key === 'itemSchema') {
|
|
33
36
|
return 'schema';
|
|
34
|
-
|
|
37
|
+
}
|
|
38
|
+
if (key === 'schemas') {
|
|
35
39
|
return 'map';
|
|
36
|
-
|
|
40
|
+
}
|
|
41
|
+
if (['example', 'examples', 'default', 'const', 'enum'].includes(key)) {
|
|
37
42
|
return undefined;
|
|
43
|
+
}
|
|
38
44
|
return 'document';
|
|
39
45
|
};
|
|
40
46
|
/**
|
|
@@ -45,16 +51,19 @@ export const getChildPosition = (position, key) => {
|
|
|
45
51
|
export const restoreBooleanSchemas = (source, target, position = 'document') => {
|
|
46
52
|
const seen = new WeakSet();
|
|
47
53
|
const visit = (original, coerced, context) => {
|
|
48
|
-
if (context === 'schema' && typeof original === 'boolean')
|
|
54
|
+
if (context === 'schema' && typeof original === 'boolean') {
|
|
49
55
|
return original;
|
|
50
|
-
|
|
56
|
+
}
|
|
57
|
+
if (!original || typeof original !== 'object' || !coerced || typeof coerced !== 'object' || seen.has(coerced)) {
|
|
51
58
|
return coerced;
|
|
59
|
+
}
|
|
52
60
|
seen.add(coerced);
|
|
53
61
|
if (Array.isArray(original) && Array.isArray(coerced)) {
|
|
54
62
|
for (const [index, value] of original.entries()) {
|
|
55
63
|
const property = Object.getOwnPropertyDescriptor(coerced, index);
|
|
56
|
-
if (!property || !('value' in property))
|
|
64
|
+
if (!property || !('value' in property)) {
|
|
57
65
|
continue;
|
|
66
|
+
}
|
|
58
67
|
Object.defineProperty(coerced, index, { ...property, value: visit(value, property.value, context) });
|
|
59
68
|
}
|
|
60
69
|
}
|
|
@@ -63,11 +72,13 @@ export const restoreBooleanSchemas = (source, target, position = 'document') =>
|
|
|
63
72
|
// Never follow inherited values or invoke setters, including __proto__.
|
|
64
73
|
// Defining an own data property still preserves those names in schema maps.
|
|
65
74
|
const property = Object.getOwnPropertyDescriptor(coerced, key);
|
|
66
|
-
if (!property || !('value' in property))
|
|
75
|
+
if (!property || !('value' in property)) {
|
|
67
76
|
continue;
|
|
77
|
+
}
|
|
68
78
|
const childContext = getChildPosition(context, key);
|
|
69
|
-
if (childContext === undefined)
|
|
79
|
+
if (childContext === undefined) {
|
|
70
80
|
continue;
|
|
81
|
+
}
|
|
71
82
|
Object.defineProperty(coerced, key, { ...property, value: visit(value, property.value, childContext) });
|
|
72
83
|
}
|
|
73
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-document.d.ts","sourceRoot":"","sources":["../src/select-document.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAA;AACjF,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,8DAA8D,CAAA;AAEnH,gFAAgF;AAChF,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,e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AU,eAAe,KAAG,cAWhE,CAAA;AAwDD;;;GAGG;AACH,eAAO,MAAM,cAAc,GACzB,UAAU,eAAe,EACzB,UAAS,oBAAyB,EAClC,SAAQ,cAA+C,KACtD,eA+NF,CAAA"}
|
package/dist/select-document.js
CHANGED
|
@@ -338,7 +338,11 @@ export const selectDocument = (document, options = {}, lookup = createDocumentLo
|
|
|
338
338
|
for (const [key, child] of Object.entries(value)) {
|
|
339
339
|
// Names such as "example" are valid map entries; only keyword positions hold opaque data.
|
|
340
340
|
if (key !== '$ref-value' && (namedLevels || (!opaqueValues.has(key) && !key.startsWith('x-')))) {
|
|
341
|
-
|
|
341
|
+
let childNamedLevels = namedLevels - 1;
|
|
342
|
+
if (!namedLevels) {
|
|
343
|
+
const mapLevels = namedMaps.has(key) ? 1 : 0;
|
|
344
|
+
childNamedLevels = key === 'callbacks' ? 2 : mapLevels;
|
|
345
|
+
}
|
|
342
346
|
visit(child, childNamedLevels);
|
|
343
347
|
}
|
|
344
348
|
}
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"llm",
|
|
17
17
|
"swagger"
|
|
18
18
|
],
|
|
19
|
-
"version": "1.
|
|
19
|
+
"version": "1.6.0",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=22"
|
|
22
22
|
},
|
|
@@ -33,6 +33,11 @@
|
|
|
33
33
|
"import": "./dist/browser.js",
|
|
34
34
|
"types": "./dist/browser.d.ts",
|
|
35
35
|
"default": "./dist/browser.js"
|
|
36
|
+
},
|
|
37
|
+
"./markdown": {
|
|
38
|
+
"import": "./dist/markdown/index.js",
|
|
39
|
+
"types": "./dist/markdown/index.d.ts",
|
|
40
|
+
"default": "./dist/markdown/index.js"
|
|
36
41
|
}
|
|
37
42
|
},
|
|
38
43
|
"files": [
|
|
@@ -40,11 +45,11 @@
|
|
|
40
45
|
"CHANGELOG.md"
|
|
41
46
|
],
|
|
42
47
|
"dependencies": {
|
|
43
|
-
"@scalar/code-highlight": "0.4.
|
|
44
|
-
"@scalar/helpers": "0.16.
|
|
45
|
-
"@scalar/json-magic": "0.
|
|
46
|
-
"@scalar/openapi-upgrader": "0.4.
|
|
47
|
-
"@scalar/workspace-store": "0.68.
|
|
48
|
+
"@scalar/code-highlight": "0.4.10",
|
|
49
|
+
"@scalar/helpers": "0.16.4",
|
|
50
|
+
"@scalar/json-magic": "0.16.0",
|
|
51
|
+
"@scalar/openapi-upgrader": "0.4.5",
|
|
52
|
+
"@scalar/workspace-store": "0.68.4",
|
|
48
53
|
"rehype-parse": "^9.0.1",
|
|
49
54
|
"rehype-remark": "^10.0.1",
|
|
50
55
|
"rehype-sanitize": "^6.0.0",
|
|
@@ -54,9 +59,9 @@
|
|
|
54
59
|
"unified": "^11.0.5"
|
|
55
60
|
},
|
|
56
61
|
"devDependencies": {
|
|
57
|
-
"@scalar/components": "0.
|
|
58
|
-
"@scalar/galaxy": "0.7.
|
|
59
|
-
"@scalar/themes": "0.19.
|
|
62
|
+
"@scalar/components": "0.32.0",
|
|
63
|
+
"@scalar/galaxy": "0.7.2",
|
|
64
|
+
"@scalar/themes": "0.19.2",
|
|
60
65
|
"@tailwindcss/vite": "^4.3.3",
|
|
61
66
|
"@types/mdast": "^4.0.4",
|
|
62
67
|
"@vitejs/plugin-vue": "^6.0.8",
|