@scalar/openapi-to-markdown 1.7.6 → 1.7.8
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 +12 -0
- package/dist/load-document.d.ts.map +1 -1
- package/dist/load-document.js +5 -5
- package/dist/object-kinds.d.ts +2 -0
- package/dist/object-kinds.d.ts.map +1 -1
- package/dist/object-kinds.js +2 -0
- package/dist/restore-boolean-schemas.d.ts +4 -2
- package/dist/restore-boolean-schemas.d.ts.map +1 -1
- package/dist/restore-boolean-schemas.js +19 -7
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @scalar/openapi-to-markdown
|
|
2
2
|
|
|
3
|
+
## 1.7.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#11074](https://github.com/scalar/scalar/pull/11074): Link references and keep boolean schemas inside OpenAPI objects named like keywords, such as a `default` response, a header named `schema` or a callback named `example`, so their schemas render with fields and examples instead of `any` and `null`.
|
|
8
|
+
|
|
9
|
+
## 1.7.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#11011](https://github.com/scalar/scalar/pull/11011): Make Vite configuration imports compatible with the native config loader.
|
|
14
|
+
|
|
3
15
|
## 1.7.6
|
|
4
16
|
|
|
5
17
|
No changes in this release.
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAkMrE,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
|
@@ -36,8 +36,8 @@ const attachRefValues = (document, schemas = getSchemas(document), { detectOnly
|
|
|
36
36
|
let kind = 'document';
|
|
37
37
|
let parent = document;
|
|
38
38
|
for (const key of segments) {
|
|
39
|
+
position = Array.isArray(parent) ? position : position && getChildPosition(position, key, kind);
|
|
39
40
|
kind = kind && getChildKind(kind, key);
|
|
40
|
-
position = Array.isArray(parent) ? position : position && getChildPosition(position, key);
|
|
41
41
|
// Arbitrary extension and example data has not passed an OpenAPI object schema.
|
|
42
42
|
if (position === 'document' && kind === undefined) {
|
|
43
43
|
position = undefined;
|
|
@@ -63,7 +63,7 @@ const attachRefValues = (document, schemas = getSchemas(document), { detectOnly
|
|
|
63
63
|
return resolved;
|
|
64
64
|
};
|
|
65
65
|
// Cast dropped targets like the objects they stand in for, so the renderer never sees uncoerced shapes.
|
|
66
|
-
const castFallback = (value, schema, position) => {
|
|
66
|
+
const castFallback = (value, schema, position, kind) => {
|
|
67
67
|
// OpenAPI 3.1 keeps boolean schemas, and a nested reference is linked once it is walked.
|
|
68
68
|
if (value === undefined || (fallback?.booleanSchemas && position === 'schema' && typeof value === 'boolean')) {
|
|
69
69
|
return value;
|
|
@@ -93,7 +93,7 @@ const attachRefValues = (document, schemas = getSchemas(document), { detectOnly
|
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
95
|
if (fallback?.booleanSchemas) {
|
|
96
|
-
restoreBooleanSchemas(value, cast, position);
|
|
96
|
+
restoreBooleanSchemas(value, cast, position, kind);
|
|
97
97
|
}
|
|
98
98
|
casts.set(schema, cast);
|
|
99
99
|
}
|
|
@@ -126,7 +126,7 @@ const attachRefValues = (document, schemas = getSchemas(document), { detectOnly
|
|
|
126
126
|
const expectedSchema = getTargetSchema(position, kind);
|
|
127
127
|
const schema = resolved?.schema === expectedSchema ? undefined : expectedSchema;
|
|
128
128
|
// Point to the target instead of copying it into every reference.
|
|
129
|
-
const target = schema ? castFallback(resolved?.value, schema, position ?? 'document') : resolved?.value;
|
|
129
|
+
const target = schema ? castFallback(resolved?.value, schema, position ?? 'document', kind) : resolved?.value;
|
|
130
130
|
if (target !== undefined) {
|
|
131
131
|
Object.defineProperty(node, '$ref-value', {
|
|
132
132
|
value: target,
|
|
@@ -144,7 +144,7 @@ const attachRefValues = (document, schemas = getSchemas(document), { detectOnly
|
|
|
144
144
|
// Preserve the nearest resource base while walking into child schemas.
|
|
145
145
|
for (const [key, child] of Object.entries(node)) {
|
|
146
146
|
const childKind = kind && getChildKind(kind, key);
|
|
147
|
-
const childPosition = Array.isArray(node) ? position : position && getChildPosition(position, key);
|
|
147
|
+
const childPosition = Array.isArray(node) ? position : position && getChildPosition(position, key, kind);
|
|
148
148
|
visit(child, base, childPosition === 'document' && childKind === undefined ? undefined : childPosition, childKind);
|
|
149
149
|
}
|
|
150
150
|
};
|
package/dist/object-kinds.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export type KindPosition = ObjectKind | {
|
|
|
8
8
|
type TargetSchema = Parameters<typeof coerceValue>[0];
|
|
9
9
|
/** Returns the kind of the value stored under `key`, or `undefined` outside the known structure. */
|
|
10
10
|
export declare const getChildKind: (position: KindPosition, key: string) => KindPosition | undefined;
|
|
11
|
+
/** Whether the keys under this position are author-chosen names, such as status codes and callback expressions, rather than fixed fields. */
|
|
12
|
+
export declare const hasNamedChildren: (position: KindPosition) => boolean;
|
|
11
13
|
/** Strict schemas for the objects that a Reference Object can stand in for. */
|
|
12
14
|
export declare const referenceTargetSchemas: Partial<Record<ObjectKind, TargetSchema>>;
|
|
13
15
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-kinds.d.ts","sourceRoot":"","sources":["../src/object-kinds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAA;AAejF,gFAAgF;AAChF,MAAM,MAAM,UAAU,GAClB,UAAU,GACV,YAAY,GACZ,UAAU,GACV,WAAW,GACX,UAAU,GACV,UAAU,GACV,aAAa,GACb,WAAW,GACX,UAAU,GACV,WAAW,GACX,QAAQ,GACR,SAAS,GACT,MAAM,GACN,gBAAgB,CAAA;AAEpB,iGAAiG;AACjG,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAA;AAE9D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAmDrD,oGAAoG;AACpG,eAAO,MAAM,YAAY,GAAI,UAAU,YAAY,EAAE,KAAK,MAAM,KAAG,YAAY,GAAG,SAMjF,CAAA;AAED,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,CAY5E,CAAA"}
|
|
1
|
+
{"version":3,"file":"object-kinds.d.ts","sourceRoot":"","sources":["../src/object-kinds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAA;AAejF,gFAAgF;AAChF,MAAM,MAAM,UAAU,GAClB,UAAU,GACV,YAAY,GACZ,UAAU,GACV,WAAW,GACX,UAAU,GACV,UAAU,GACV,aAAa,GACb,WAAW,GACX,UAAU,GACV,WAAW,GACX,QAAQ,GACR,SAAS,GACT,MAAM,GACN,gBAAgB,CAAA;AAEpB,iGAAiG;AACjG,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAA;AAE9D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;AAmDrD,oGAAoG;AACpG,eAAO,MAAM,YAAY,GAAI,UAAU,YAAY,EAAE,KAAK,MAAM,KAAG,YAAY,GAAG,SAMjF,CAAA;AAED,6IAA6I;AAC7I,eAAO,MAAM,gBAAgB,GAAI,UAAU,YAAY,KAAG,OACiB,CAAA;AAE3E,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,CAY5E,CAAA"}
|
package/dist/object-kinds.js
CHANGED
|
@@ -54,6 +54,8 @@ export const getChildKind = (position, key) => {
|
|
|
54
54
|
const children = childKinds[position];
|
|
55
55
|
return children?.[key] ?? children?.['*'];
|
|
56
56
|
};
|
|
57
|
+
/** Whether the keys under this position are author-chosen names, such as status codes and callback expressions, rather than fixed fields. */
|
|
58
|
+
export const hasNamedChildren = (position) => typeof position !== 'string' || childKinds[position]?.['*'] !== undefined;
|
|
57
59
|
/** Strict schemas for the objects that a Reference Object can stand in for. */
|
|
58
60
|
export const referenceTargetSchemas = {
|
|
59
61
|
pathItem: PathItemObjectSchema,
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { type KindPosition } from './object-kinds.js';
|
|
1
2
|
/** Where a value sits in an OpenAPI description: a schema, a map of schemas, or anything else. */
|
|
2
3
|
export type SchemaPosition = 'document' | 'schema' | 'map';
|
|
3
4
|
/**
|
|
4
5
|
* Returns the position of the value stored under `key`, or `undefined` when that value
|
|
5
6
|
* is not part of the schema tree, such as example payloads and schema metadata.
|
|
7
|
+
* `kind` is the OpenAPI object that holds `key`, if known.
|
|
6
8
|
*/
|
|
7
|
-
export declare const getChildPosition: (position: SchemaPosition, key: string) => SchemaPosition | undefined;
|
|
9
|
+
export declare const getChildPosition: (position: SchemaPosition, key: string, kind?: KindPosition) => SchemaPosition | undefined;
|
|
8
10
|
/**
|
|
9
11
|
* The workspace schema currently casts boolean JSON Schemas into empty objects.
|
|
10
12
|
* Restore them only in schema positions, never in example payloads or metadata.
|
|
11
13
|
* TODO: Remove this bridge when the shared schema accepts boolean JSON Schemas.
|
|
12
14
|
*/
|
|
13
|
-
export declare const restoreBooleanSchemas: (source: unknown, target: unknown, position?: SchemaPosition) => void;
|
|
15
|
+
export declare const restoreBooleanSchemas: (source: unknown, target: unknown, position?: SchemaPosition, kind?: KindPosition | undefined) => void;
|
|
14
16
|
//# sourceMappingURL=restore-boolean-schemas.d.ts.map
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"restore-boolean-schemas.d.ts","sourceRoot":"","sources":["../src/restore-boolean-schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,YAAY,EAAkC,MAAM,gBAAgB,CAAA;AAElF,kGAAkG;AAClG,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAA;AAmB1D;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAU,cAAc,EACxB,KAAK,MAAM,EACX,OAAO,YAAY,KAClB,cAAc,GAAG,SA2BnB,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAChC,QAAQ,OAAO,EACf,QAAQ,OAAO,EACf,WAAU,cAA2B,EACrC,OAAM,YAAY,GAAG,SAAsB,KAC1C,IA+CF,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isObject } from '@scalar/helpers/object/is-object';
|
|
2
|
+
import { getChildKind, hasNamedChildren } from './object-kinds.js';
|
|
2
3
|
const schemaMaps = new Set(['properties', 'patternProperties', '$defs', 'definitions', 'dependentSchemas']);
|
|
3
4
|
const schemaArrays = new Set(['allOf', 'anyOf', 'oneOf', 'prefixItems']);
|
|
4
5
|
const schemaFields = new Set([
|
|
@@ -18,8 +19,9 @@ const schemaFields = new Set([
|
|
|
18
19
|
/**
|
|
19
20
|
* Returns the position of the value stored under `key`, or `undefined` when that value
|
|
20
21
|
* is not part of the schema tree, such as example payloads and schema metadata.
|
|
22
|
+
* `kind` is the OpenAPI object that holds `key`, if known.
|
|
21
23
|
*/
|
|
22
|
-
export const getChildPosition = (position, key) => {
|
|
24
|
+
export const getChildPosition = (position, key, kind) => {
|
|
23
25
|
if (position === 'map') {
|
|
24
26
|
return 'schema';
|
|
25
27
|
}
|
|
@@ -32,6 +34,10 @@ export const getChildPosition = (position, key) => {
|
|
|
32
34
|
}
|
|
33
35
|
return undefined;
|
|
34
36
|
}
|
|
37
|
+
// A `default` response or a header named `schema` is an OpenAPI object, not a keyword.
|
|
38
|
+
if (kind !== undefined && hasNamedChildren(kind)) {
|
|
39
|
+
return 'document';
|
|
40
|
+
}
|
|
35
41
|
if (key === 'schema' || key === 'itemSchema') {
|
|
36
42
|
return 'schema';
|
|
37
43
|
}
|
|
@@ -48,9 +54,9 @@ export const getChildPosition = (position, key) => {
|
|
|
48
54
|
* Restore them only in schema positions, never in example payloads or metadata.
|
|
49
55
|
* TODO: Remove this bridge when the shared schema accepts boolean JSON Schemas.
|
|
50
56
|
*/
|
|
51
|
-
export const restoreBooleanSchemas = (source, target, position = 'document') => {
|
|
57
|
+
export const restoreBooleanSchemas = (source, target, position = 'document', kind = 'document') => {
|
|
52
58
|
const seen = new WeakSet();
|
|
53
|
-
const visit = (original, coerced, context) => {
|
|
59
|
+
const visit = (original, coerced, context, contextKind) => {
|
|
54
60
|
if (context === 'schema' && typeof original === 'boolean') {
|
|
55
61
|
return original;
|
|
56
62
|
}
|
|
@@ -64,7 +70,10 @@ export const restoreBooleanSchemas = (source, target, position = 'document') =>
|
|
|
64
70
|
if (!property || !('value' in property)) {
|
|
65
71
|
continue;
|
|
66
72
|
}
|
|
67
|
-
Object.defineProperty(coerced, index, {
|
|
73
|
+
Object.defineProperty(coerced, index, {
|
|
74
|
+
...property,
|
|
75
|
+
value: visit(value, property.value, context, contextKind && getChildKind(contextKind, String(index))),
|
|
76
|
+
});
|
|
68
77
|
}
|
|
69
78
|
}
|
|
70
79
|
else if (isObject(original) && isObject(coerced)) {
|
|
@@ -75,14 +84,17 @@ export const restoreBooleanSchemas = (source, target, position = 'document') =>
|
|
|
75
84
|
if (!property || !('value' in property)) {
|
|
76
85
|
continue;
|
|
77
86
|
}
|
|
78
|
-
const childContext = getChildPosition(context, key);
|
|
87
|
+
const childContext = getChildPosition(context, key, contextKind);
|
|
79
88
|
if (childContext === undefined) {
|
|
80
89
|
continue;
|
|
81
90
|
}
|
|
82
|
-
Object.defineProperty(coerced, key, {
|
|
91
|
+
Object.defineProperty(coerced, key, {
|
|
92
|
+
...property,
|
|
93
|
+
value: visit(value, property.value, childContext, contextKind && getChildKind(contextKind, key)),
|
|
94
|
+
});
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
return coerced;
|
|
86
98
|
};
|
|
87
|
-
visit(source, target, position);
|
|
99
|
+
visit(source, target, position, kind);
|
|
88
100
|
};
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"llm",
|
|
17
17
|
"swagger"
|
|
18
18
|
],
|
|
19
|
-
"version": "1.7.
|
|
19
|
+
"version": "1.7.8",
|
|
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.18.
|
|
50
|
-
"@scalar/json-magic": "0.
|
|
51
|
-
"@scalar/openapi-upgrader": "0.4.
|
|
52
|
-
"@scalar/workspace-store": "0.
|
|
48
|
+
"@scalar/code-highlight": "0.4.15",
|
|
49
|
+
"@scalar/helpers": "0.18.1",
|
|
50
|
+
"@scalar/json-magic": "0.20.1",
|
|
51
|
+
"@scalar/openapi-upgrader": "0.4.11",
|
|
52
|
+
"@scalar/workspace-store": "0.73.0",
|
|
53
53
|
"rehype-parse": "^9.0.1",
|
|
54
54
|
"rehype-remark": "^10.0.1",
|
|
55
55
|
"rehype-sanitize": "^6.0.0",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"unified": "^11.0.5"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@scalar/components": "0.
|
|
63
|
-
"@scalar/galaxy": "0.7.
|
|
64
|
-
"@scalar/themes": "0.20.
|
|
62
|
+
"@scalar/components": "0.35.1",
|
|
63
|
+
"@scalar/galaxy": "0.7.4",
|
|
64
|
+
"@scalar/themes": "0.20.2",
|
|
65
65
|
"@tailwindcss/vite": "^4.3.3",
|
|
66
66
|
"@types/mdast": "^4.0.4",
|
|
67
67
|
"@vitejs/plugin-vue": "^6.0.10",
|