@scalar/openapi-to-markdown 1.7.4 → 1.7.5
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
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @scalar/openapi-to-markdown
|
|
2
2
|
|
|
3
|
+
## 1.7.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#10904](https://github.com/scalar/scalar/pull/10904): Share confined document loading between Markdown converters and include HTTP status codes in load errors.
|
|
8
|
+
|
|
3
9
|
## 1.7.4
|
|
4
10
|
|
|
5
11
|
## 1.7.3
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-markdown-from-openapi.d.ts","sourceRoot":"","sources":["../src/create-markdown-from-openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAA;AAEnG,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,iBAAiB,CAAA;AAExE,OAAO,EAAE,KAAK,oBAAoB,EAAwC,MAAM,mBAAmB,CAAA;AAEnG,KAAK,WAAW,GAAG,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;AACrE,0FAA0F;AAC1F,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC5D,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,6BAA6B,GACxC,OAAO,WAAW,EAClB,UAAU,mBAAmB,KAC5B,OAAO,CAAC,uBAAuB,CAQjC,CAAA;AAED,qFAAqF;AACrF,eAAO,MAAM,yBAAyB,GACpC,OAAO,WAAW,EAClB,UAAU,oBAAoB,GAAG;IAAE,eAAe,CAAC,EAAE,mBAAmB,CAAA;CAAE,KACzE,OAAO,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"create-markdown-from-openapi.d.ts","sourceRoot":"","sources":["../src/create-markdown-from-openapi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAA;AAEnG,OAAO,EAAE,KAAK,mBAAmB,EAAgB,MAAM,iBAAiB,CAAA;AAExE,OAAO,EAAE,KAAK,oBAAoB,EAAwC,MAAM,mBAAmB,CAAA;AAEnG,KAAK,WAAW,GAAG,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;AACrE,0FAA0F;AAC1F,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,oBAAoB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAA;CAC5D,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,6BAA6B,GACxC,OAAO,WAAW,EAClB,UAAU,mBAAmB,KAC5B,OAAO,CAAC,uBAAuB,CAQjC,CAAA;AAED,qFAAqF;AACrF,eAAO,MAAM,yBAAyB,GACpC,OAAO,WAAW,EAClB,UAAU,oBAAoB,GAAG;IAAE,eAAe,CAAC,EAAE,mBAAmB,CAAA;CAAE,KACzE,OAAO,CAAC,MAAM,CAIhB,CAAA"}
|
|
@@ -14,10 +14,7 @@ export const createOpenApiMarkdownRenderer = async (input, options) => {
|
|
|
14
14
|
};
|
|
15
15
|
/** Generate Markdown from an API description, optionally scoped to a single page. */
|
|
16
16
|
export const createMarkdownFromOpenApi = async (input, options) => {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return renderer.render(renderOptions);
|
|
21
|
-
}
|
|
22
|
-
return renderer.render(options);
|
|
17
|
+
const { documentLoading, ...renderOptions } = options ?? {};
|
|
18
|
+
const renderer = await createOpenApiMarkdownRenderer(input, documentLoading);
|
|
19
|
+
return renderer.render(renderOptions);
|
|
23
20
|
};
|
package/dist/load-document.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
+
import type { DocumentLoadOptions } from '@scalar/json-magic/bundle/plugins/node';
|
|
1
2
|
import { type OpenApiDocument } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
2
|
-
|
|
3
|
-
export type DocumentLoadOptions = {
|
|
4
|
-
/** Allow private-network requests only for trusted input. Defaults to false. */
|
|
5
|
-
allowPrivateNetworks?: boolean;
|
|
6
|
-
/** Approved directory for local files and references. File access is disabled when omitted. */
|
|
7
|
-
basePath?: string;
|
|
8
|
-
};
|
|
3
|
+
export type { DocumentLoadOptions } from '@scalar/json-magic/bundle/plugins/node';
|
|
9
4
|
/** Coerce one plain document and keep references linked to shared targets. */
|
|
10
5
|
export declare const loadDocument: (input: OpenApiDocument | Record<string, unknown> | string, options?: DocumentLoadOptions) => Promise<OpenApiDocument>;
|
|
11
6
|
//# sourceMappingURL=load-document.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-document.d.ts","sourceRoot":"","sources":["../src/load-document.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"load-document.d.ts","sourceRoot":"","sources":["../src/load-document.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAQjF,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,8DAA8D,CAAA;AAiMrE,YAAY,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAA;AAEjF,8EAA8E;AAC9E,eAAO,MAAM,YAAY,GACvB,OAAO,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EACzD,UAAS,mBAAwB,KAChC,OAAO,CAAC,eAAe,CAqEzB,CAAA"}
|
package/dist/load-document.js
CHANGED
|
@@ -4,7 +4,6 @@ import { bundle } from '@scalar/json-magic/bundle';
|
|
|
4
4
|
import { convertToLocalRef } from '@scalar/json-magic/helpers/convert-to-local-ref';
|
|
5
5
|
import { getId, getSchemas } from '@scalar/json-magic/helpers/get-schemas';
|
|
6
6
|
import { getValueByPath } from '@scalar/json-magic/helpers/get-value-by-path';
|
|
7
|
-
import { normalize } from '@scalar/json-magic/helpers/normalize';
|
|
8
7
|
import { getRaw } from '@scalar/json-magic/magic-proxy';
|
|
9
8
|
import { upgrade } from '@scalar/openapi-upgrader';
|
|
10
9
|
import { deepClone } from '@scalar/workspace-store/helpers/deep-clone';
|
|
@@ -154,42 +153,12 @@ const attachRefValues = (document, schemas = getSchemas(document), { detectOnly
|
|
|
154
153
|
};
|
|
155
154
|
/** Coerce one plain document and keep references linked to shared targets. */
|
|
156
155
|
export const loadDocument = async (input, options = {}) => {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const { fetchUrls, readFiles } = await import('@scalar/json-magic/bundle/plugins/node');
|
|
160
|
-
const urlLoader = fetchUrls({ blockPrivateNetworks: !options.allowPrivateNetworks });
|
|
161
|
-
const fileLoader = options.basePath === undefined ? undefined : readFiles({ basePath: options.basePath });
|
|
156
|
+
const { createDocumentLoader } = await import('@scalar/json-magic/bundle/plugins/node');
|
|
157
|
+
const loader = createDocumentLoader(options);
|
|
162
158
|
// Reference links are attached below, so never mutate the caller's document.
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// Inline JSON and YAML avoid the I/O path; URLs and files are loaded afterward.
|
|
167
|
-
else {
|
|
168
|
-
const normalized = normalize(input);
|
|
169
|
-
if (isObject(normalized)) {
|
|
170
|
-
raw = normalized;
|
|
171
|
-
}
|
|
172
|
-
else if (/^https?:\/\//i.test(input)) {
|
|
173
|
-
const result = await urlLoader.exec(input);
|
|
174
|
-
if (!result.ok) {
|
|
175
|
-
throw new Error('Failed to load OpenAPI document');
|
|
176
|
-
}
|
|
177
|
-
raw = result.data;
|
|
178
|
-
origin = input;
|
|
179
|
-
}
|
|
180
|
-
else {
|
|
181
|
-
if (!fileLoader) {
|
|
182
|
-
throw new Error('Local file access requires an explicit basePath');
|
|
183
|
-
}
|
|
184
|
-
const { resolve } = await import('node:path');
|
|
185
|
-
origin = resolve(input);
|
|
186
|
-
const result = await fileLoader.exec(origin);
|
|
187
|
-
if (!result.ok) {
|
|
188
|
-
throw new Error('Failed to load OpenAPI document');
|
|
189
|
-
}
|
|
190
|
-
raw = result.data;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
159
|
+
const { value: raw, origin } = typeof input === 'string'
|
|
160
|
+
? await loader.load(input, 'OpenAPI')
|
|
161
|
+
: { value: deepClone(getRaw(input)), origin: undefined };
|
|
193
162
|
if (!isObject(raw)) {
|
|
194
163
|
throw new Error('Failed to load OpenAPI document');
|
|
195
164
|
}
|
|
@@ -203,9 +172,8 @@ export const loadDocument = async (input, options = {}) => {
|
|
|
203
172
|
// Resolve external targets only when the initial local-reference pass finds them.
|
|
204
173
|
if (hasExternalReferences) {
|
|
205
174
|
const errors = [];
|
|
206
|
-
const plugins = fileLoader ? [urlLoader, fileLoader] : [urlLoader];
|
|
207
175
|
document = await bundle(upgraded, {
|
|
208
|
-
plugins,
|
|
176
|
+
plugins: loader.plugins,
|
|
209
177
|
origin,
|
|
210
178
|
treeShake: false,
|
|
211
179
|
hooks: { onResolveError: (node) => errors.push(`Failed to resolve ${node.$ref}`) },
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"llm",
|
|
17
17
|
"swagger"
|
|
18
18
|
],
|
|
19
|
-
"version": "1.7.
|
|
19
|
+
"version": "1.7.5",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=22.19.0"
|
|
22
22
|
},
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"CHANGELOG.md"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@scalar/code-highlight": "0.4.
|
|
49
|
-
"@scalar/helpers": "0.17.
|
|
50
|
-
"@scalar/json-magic": "0.
|
|
51
|
-
"@scalar/openapi-upgrader": "0.4.
|
|
52
|
-
"@scalar/workspace-store": "0.
|
|
48
|
+
"@scalar/code-highlight": "0.4.13",
|
|
49
|
+
"@scalar/helpers": "0.17.1",
|
|
50
|
+
"@scalar/json-magic": "0.19.0",
|
|
51
|
+
"@scalar/openapi-upgrader": "0.4.8",
|
|
52
|
+
"@scalar/workspace-store": "0.71.0",
|
|
53
53
|
"rehype-parse": "^9.0.1",
|
|
54
54
|
"rehype-remark": "^10.0.1",
|
|
55
55
|
"rehype-sanitize": "^6.0.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"unified": "^11.0.5"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@scalar/components": "0.
|
|
62
|
+
"@scalar/components": "0.34.0",
|
|
63
63
|
"@scalar/galaxy": "0.7.2",
|
|
64
64
|
"@scalar/themes": "0.20.0",
|
|
65
65
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"tailwindcss": "^4.3.3",
|
|
71
71
|
"tsx": "4.23.15",
|
|
72
72
|
"vite": "8.3.4",
|
|
73
|
-
"vitest": "
|
|
73
|
+
"vitest": "5.0.5",
|
|
74
74
|
"vue": "^3.5.44",
|
|
75
75
|
"vue-tsc": "3.3.11"
|
|
76
76
|
},
|