docusaurus-plugin-openapi-docs 0.0.0-740 → 0.0.0-751
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 +86 -61
- package/lib/index.js +23 -23
- package/lib/markdown/createAuthentication.js +4 -3
- package/lib/markdown/createCallbacks.js +4 -2
- package/lib/markdown/createContactInfo.js +2 -11
- package/lib/markdown/createDeprecationNotice.js +6 -3
- package/lib/markdown/createDescription.js +1 -8
- package/lib/markdown/createHeading.js +4 -3
- package/lib/markdown/createRequestHeader.d.ts +1 -1
- package/lib/markdown/createRequestHeader.js +10 -1
- package/lib/markdown/createSchema.js +26 -40
- package/lib/markdown/createSchema.test.js +78 -2
- package/lib/markdown/createVersionBadge.js +1 -1
- package/lib/markdown/index.js +5 -2
- package/lib/markdown/utils.d.ts +4 -1
- package/lib/markdown/utils.js +11 -4
- package/lib/openapi/types.d.ts +1 -1
- package/lib/openapi/utils/utils/openapi.js +1 -1
- package/package.json +9 -7
- package/src/index.ts +33 -30
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +222 -1
- package/src/markdown/createAuthentication.ts +10 -5
- package/src/markdown/createCallbacks.ts +10 -4
- package/src/markdown/createContactInfo.ts +2 -13
- package/src/markdown/createDeprecationNotice.ts +2 -2
- package/src/markdown/createDescription.ts +2 -9
- package/src/markdown/createHeading.ts +10 -5
- package/src/markdown/createRequestHeader.ts +15 -1
- package/src/markdown/createSchema.test.ts +92 -3
- package/src/markdown/createSchema.ts +30 -46
- package/src/markdown/createVersionBadge.ts +8 -4
- package/src/markdown/index.ts +5 -2
- package/src/markdown/utils.ts +18 -4
- package/src/openapi/types.ts +1 -1
- package/src/openapi/utils/services/OpenAPIParser.ts +2 -2
- package/src/openapi/utils/utils/openapi.ts +1 -1
|
@@ -11,6 +11,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createNodes = exports.mergeAllOf = void 0;
|
|
13
13
|
const clsx_1 = __importDefault(require("clsx"));
|
|
14
|
+
const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
|
|
14
15
|
const createArrayBracket_1 = require("./createArrayBracket");
|
|
15
16
|
const createDescription_1 = require("./createDescription");
|
|
16
17
|
const createDetails_1 = require("./createDetails");
|
|
@@ -141,70 +142,52 @@ function createProperties(schema) {
|
|
|
141
142
|
* For handling additionalProperties.
|
|
142
143
|
*/
|
|
143
144
|
function createAdditionalProperties(schema) {
|
|
144
|
-
var _a
|
|
145
|
+
var _a;
|
|
145
146
|
const additionalProperties = schema.additionalProperties;
|
|
146
|
-
|
|
147
|
+
if (!additionalProperties)
|
|
148
|
+
return [];
|
|
147
149
|
// Handle free-form objects
|
|
148
|
-
if (
|
|
150
|
+
if (additionalProperties === true || (0, isEmpty_1.default)(additionalProperties)) {
|
|
149
151
|
return (0, utils_1.create)("SchemaItem", {
|
|
150
152
|
name: "property name*",
|
|
151
153
|
required: false,
|
|
152
154
|
schemaName: "any",
|
|
153
|
-
qualifierMessage: (0, schema_1.getQualifierMessage)(schema
|
|
155
|
+
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
154
156
|
schema: schema,
|
|
155
157
|
collapsible: false,
|
|
156
158
|
discriminator: false,
|
|
157
159
|
});
|
|
158
160
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
// objects, arrays, complex schemas
|
|
162
|
+
if (additionalProperties.properties ||
|
|
163
|
+
additionalProperties.items ||
|
|
164
|
+
additionalProperties.allOf ||
|
|
165
|
+
additionalProperties.additionalProperties ||
|
|
166
|
+
additionalProperties.oneOf ||
|
|
167
|
+
additionalProperties.anyOf) {
|
|
166
168
|
const title = additionalProperties.title;
|
|
167
169
|
const schemaName = (0, schema_1.getSchemaName)(additionalProperties);
|
|
168
170
|
const required = (_a = schema.required) !== null && _a !== void 0 ? _a : false;
|
|
169
171
|
return createDetailsNode("property name*", title !== null && title !== void 0 ? title : schemaName, additionalProperties, required, schema.nullable);
|
|
170
172
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
if (additionalProperties !== undefined) {
|
|
178
|
-
const type = (_j = (_h = schema.additionalProperties) === null || _h === void 0 ? void 0 : _h.additionalProperties) === null || _j === void 0 ? void 0 : _j.type;
|
|
179
|
-
const schemaName = (0, schema_1.getSchemaName)((_k = schema.additionalProperties) === null || _k === void 0 ? void 0 : _k.additionalProperties);
|
|
180
|
-
return (0, utils_1.create)("SchemaItem", {
|
|
181
|
-
name: "property name*",
|
|
182
|
-
required: false,
|
|
183
|
-
schemaName: schemaName !== null && schemaName !== void 0 ? schemaName : type,
|
|
184
|
-
qualifierMessage: (_l = schema.additionalProperties) !== null && _l !== void 0 ? _l : (0, schema_1.getQualifierMessage)(schema.additionalProperties),
|
|
185
|
-
schema: schema,
|
|
186
|
-
collapsible: false,
|
|
187
|
-
discriminator: false,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
const schemaName = (0, schema_1.getSchemaName)(schema.additionalProperties);
|
|
173
|
+
// primitive types
|
|
174
|
+
if (additionalProperties.type === "string" ||
|
|
175
|
+
additionalProperties.type === "boolean" ||
|
|
176
|
+
additionalProperties.type === "integer" ||
|
|
177
|
+
additionalProperties.type === "number") {
|
|
178
|
+
const schemaName = (0, schema_1.getSchemaName)(additionalProperties);
|
|
191
179
|
return (0, utils_1.create)("SchemaItem", {
|
|
192
180
|
name: "property name*",
|
|
193
181
|
required: false,
|
|
194
182
|
schemaName: schemaName,
|
|
195
183
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
196
|
-
schema:
|
|
184
|
+
schema: additionalProperties,
|
|
197
185
|
collapsible: false,
|
|
198
186
|
discriminator: false,
|
|
199
187
|
});
|
|
200
188
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
schema: val,
|
|
204
|
-
required: Array.isArray(schema.required)
|
|
205
|
-
? schema.required.includes(key)
|
|
206
|
-
: false,
|
|
207
|
-
}));
|
|
189
|
+
// unknown
|
|
190
|
+
return [];
|
|
208
191
|
}
|
|
209
192
|
/**
|
|
210
193
|
* For handling items.
|
|
@@ -593,7 +576,10 @@ function createNodes(schema, schemaType) {
|
|
|
593
576
|
}
|
|
594
577
|
if (schema.allOf !== undefined) {
|
|
595
578
|
const { mergedSchemas } = mergeAllOf(schema.allOf);
|
|
596
|
-
|
|
579
|
+
if (mergedSchemas.oneOf !== undefined ||
|
|
580
|
+
mergedSchemas.anyOf !== undefined) {
|
|
581
|
+
nodes.push(createAnyOneOf(mergedSchemas));
|
|
582
|
+
}
|
|
597
583
|
if (mergedSchemas.properties !== undefined) {
|
|
598
584
|
nodes.push(createProperties(mergedSchemas));
|
|
599
585
|
}
|
|
@@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
const prettier = __importStar(require("prettier"));
|
|
33
33
|
const createSchema_1 = require("./createSchema");
|
|
34
34
|
describe("createNodes", () => {
|
|
35
|
-
it("should create readable MODs for oneOf primitive properties", () => {
|
|
35
|
+
it("should create readable MODs for oneOf primitive properties", async () => {
|
|
36
36
|
const schema = {
|
|
37
37
|
"x-tags": ["clown"],
|
|
38
38
|
type: "object",
|
|
@@ -69,6 +69,82 @@ describe("createNodes", () => {
|
|
|
69
69
|
},
|
|
70
70
|
},
|
|
71
71
|
};
|
|
72
|
-
expect((0, createSchema_1.createNodes)(schema, "request").map((md) => prettier.format(md, { parser: "babel" }))).toMatchSnapshot();
|
|
72
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
73
|
+
});
|
|
74
|
+
describe("additionalProperties", () => {
|
|
75
|
+
it.each([
|
|
76
|
+
[
|
|
77
|
+
{
|
|
78
|
+
allOf: [
|
|
79
|
+
{
|
|
80
|
+
oneOf: [
|
|
81
|
+
{
|
|
82
|
+
type: "object",
|
|
83
|
+
properties: {
|
|
84
|
+
type: {
|
|
85
|
+
type: "string",
|
|
86
|
+
enum: ["nose"],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
required: ["type"],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
type: "object",
|
|
93
|
+
properties: {
|
|
94
|
+
type: {
|
|
95
|
+
type: "string",
|
|
96
|
+
enum: ["mouth"],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
required: ["type"],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
type: {
|
|
105
|
+
type: "string",
|
|
106
|
+
enum: ["eyes"],
|
|
107
|
+
},
|
|
108
|
+
default: {
|
|
109
|
+
type: "string",
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
required: ["type"],
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: {
|
|
119
|
+
description: {
|
|
120
|
+
type: "string",
|
|
121
|
+
description: "Description of the body part.",
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
required: ["description"],
|
|
125
|
+
},
|
|
126
|
+
],
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
{
|
|
131
|
+
type: "array",
|
|
132
|
+
items: { type: "object", properties: { a: "string", b: "number" } },
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
[{ type: "string" }],
|
|
136
|
+
[{ type: "number" }],
|
|
137
|
+
[{ type: "integer" }],
|
|
138
|
+
[{ type: "boolean" }],
|
|
139
|
+
[false],
|
|
140
|
+
[true],
|
|
141
|
+
[{}],
|
|
142
|
+
])("should handle additionalProperties: %p", async (additionalProperties) => {
|
|
143
|
+
const schema = {
|
|
144
|
+
type: "object",
|
|
145
|
+
additionalProperties,
|
|
146
|
+
};
|
|
147
|
+
expect(await Promise.all((0, createSchema_1.createNodes)(schema, "request").map(async (md) => await prettier.format(md, { parser: "babel" })))).toMatchSnapshot();
|
|
148
|
+
});
|
|
73
149
|
});
|
|
74
150
|
});
|
package/lib/markdown/index.js
CHANGED
|
@@ -39,9 +39,10 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
39
39
|
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
40
40
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
41
41
|
`import Markdown from "@theme/Markdown";\n`,
|
|
42
|
+
`import Heading from "@theme/Heading";\n`,
|
|
42
43
|
`import OperationTabs from "@theme/OperationTabs";\n`,
|
|
43
44
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
44
|
-
(0, createHeading_1.createHeading)(title
|
|
45
|
+
(0, createHeading_1.createHeading)(title),
|
|
45
46
|
(0, createMethodEndpoint_1.createMethodEndpoint)(method, path),
|
|
46
47
|
infoPath && (0, createAuthorization_1.createAuthorization)(infoPath),
|
|
47
48
|
frontMatter.show_extensions
|
|
@@ -66,12 +67,13 @@ exports.createApiPageMD = createApiPageMD;
|
|
|
66
67
|
function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService, logo, darkLogo, }, securitySchemes, downloadUrl, }) {
|
|
67
68
|
return (0, utils_1.render)([
|
|
68
69
|
`import ApiLogo from "@theme/ApiLogo";\n`,
|
|
70
|
+
`import Heading from "@theme/Heading";\n`,
|
|
69
71
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
70
72
|
`import TabItem from "@theme/TabItem";\n`,
|
|
71
73
|
`import Export from "@theme/ApiExplorer/Export";\n\n`,
|
|
72
74
|
(0, createVersionBadge_1.createVersionBadge)(version),
|
|
73
75
|
(0, createDownload_1.createDownload)(downloadUrl),
|
|
74
|
-
(0, createHeading_1.createHeading)(title
|
|
76
|
+
(0, createHeading_1.createHeading)(title),
|
|
75
77
|
(0, createLogo_1.createLogo)(logo, darkLogo),
|
|
76
78
|
(0, createDescription_1.createDescription)(description),
|
|
77
79
|
(0, createAuthentication_1.createAuthentication)(securitySchemes),
|
|
@@ -91,6 +93,7 @@ function createSchemaPageMD({ schema }) {
|
|
|
91
93
|
`import DiscriminatorTabs from "@theme/DiscriminatorTabs";\n`,
|
|
92
94
|
`import SchemaItem from "@theme/SchemaItem";\n`,
|
|
93
95
|
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
96
|
+
`import Heading from "@theme/Heading";\n`,
|
|
94
97
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
95
98
|
(0, createHeading_1.createHeading)(title.replace(utils_1.lessThan, "<").replace(utils_1.greaterThan, ">")),
|
|
96
99
|
(0, createDescription_1.createDescription)(description),
|
package/lib/markdown/utils.d.ts
CHANGED
|
@@ -2,7 +2,10 @@ export type Children = string | undefined | (string | string[] | undefined)[];
|
|
|
2
2
|
export type Props = Record<string, any> & {
|
|
3
3
|
children?: Children;
|
|
4
4
|
};
|
|
5
|
-
export
|
|
5
|
+
export type Options = {
|
|
6
|
+
inline?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function create(tag: string, props: Props, options?: Options): string;
|
|
6
9
|
export declare function guard<T>(value: T | undefined, cb: (value: T) => Children): string;
|
|
7
10
|
export declare function render(children: Children): string;
|
|
8
11
|
export declare const lessThan: RegExp;
|
package/lib/markdown/utils.js
CHANGED
|
@@ -7,13 +7,20 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.clean = exports.codeBlock = exports.curlyBrackets = exports.codeFence = exports.greaterThan = exports.lessThan = exports.render = exports.guard = exports.create = void 0;
|
|
10
|
-
function create(tag, props) {
|
|
10
|
+
function create(tag, props, options = {}) {
|
|
11
11
|
const { children, ...rest } = props;
|
|
12
12
|
let propString = "";
|
|
13
13
|
for (const [key, value] of Object.entries(rest)) {
|
|
14
|
-
propString +=
|
|
14
|
+
propString += `\n ${key}={${JSON.stringify(value)}}`;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
let indentedChildren = render(children).replace(/^/gm, " ");
|
|
17
|
+
if (options.inline) {
|
|
18
|
+
propString += `\n children={${JSON.stringify(children)}}`;
|
|
19
|
+
indentedChildren = "";
|
|
20
|
+
}
|
|
21
|
+
propString += propString ? "\n" : "";
|
|
22
|
+
indentedChildren += indentedChildren ? "\n" : "";
|
|
23
|
+
return `<${tag}${propString}>\n${indentedChildren}</${tag}>`;
|
|
17
24
|
}
|
|
18
25
|
exports.create = create;
|
|
19
26
|
function guard(value, cb) {
|
|
@@ -35,7 +42,7 @@ function render(children) {
|
|
|
35
42
|
}
|
|
36
43
|
exports.render = render;
|
|
37
44
|
// Regex to selectively URL-encode '>' and '<' chars
|
|
38
|
-
exports.lessThan =
|
|
45
|
+
exports.lessThan = /<=?(?!(=|button|\s?\/button|code|\s?\/code|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|thead|\s?\/thead|tbody|\s?\/tbody|td|\s?\/td|tr|\s?\/tr|th|\s?\/th|h1|\s?\/h1|h2|\s?\/h2|h3|\s?\/h3|h4|\s?\/h4|h5|\s?\/h5|h6|\s?\/h6|title|\s?\/title|p|\s?\/p|em|\s?\/em|b|\s?\/b|i|\s?\/i|u|\s?\/u|strike|\s?\/strike|bold|\s?\/bold|a|\s?\/a|table|\s?\/table|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|svg|\s?\/svg|div|\s?\/div|center|\s?\/center))/gu;
|
|
39
46
|
exports.greaterThan = /(?<!(button|code|details|summary|hr|br|span|strong|small|table|thead|tbody|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|bold|a|li|ol|ul|img|svg|div|center|\/|\s|"|'))>/gu;
|
|
40
47
|
exports.codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
41
48
|
exports.curlyBrackets = /([{}])/g;
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -269,7 +269,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
|
|
|
269
269
|
not?: SchemaObject;
|
|
270
270
|
items?: SchemaObject;
|
|
271
271
|
properties?: Map<SchemaObject>;
|
|
272
|
-
additionalProperties?:
|
|
272
|
+
additionalProperties?: boolean | SchemaObject;
|
|
273
273
|
nullable?: boolean;
|
|
274
274
|
discriminator?: DiscriminatorObject;
|
|
275
275
|
readOnly?: boolean;
|
|
@@ -534,7 +534,7 @@ exports.setSecuritySchemePrefix = setSecuritySchemePrefix;
|
|
|
534
534
|
const shortenHTTPVerb = (verb) => ({
|
|
535
535
|
delete: "del",
|
|
536
536
|
options: "opts",
|
|
537
|
-
}[verb] || verb
|
|
537
|
+
})[verb] || verb;
|
|
538
538
|
exports.shortenHTTPVerb = shortenHTTPVerb;
|
|
539
539
|
function isRedocExtension(key) {
|
|
540
540
|
const redocExtensions = {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-plugin-openapi-docs",
|
|
3
3
|
"description": "OpenAPI plugin for Docusaurus.",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-751",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -28,24 +28,26 @@
|
|
|
28
28
|
"watch": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@docusaurus/types": "
|
|
31
|
+
"@docusaurus/types": "^3.0.1",
|
|
32
32
|
"@types/fs-extra": "^9.0.13",
|
|
33
33
|
"@types/json-pointer": "^1.0.31",
|
|
34
34
|
"@types/json-schema": "^7.0.9",
|
|
35
35
|
"@types/lodash": "^4.14.176",
|
|
36
|
-
"@types/mustache": "^4.1.2"
|
|
36
|
+
"@types/mustache": "^4.1.2",
|
|
37
|
+
"eslint-plugin-prettier": "^5.0.1"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
40
|
"@apidevtools/json-schema-ref-parser": "^11.5.4",
|
|
40
|
-
"@docusaurus/plugin-content-docs": "
|
|
41
|
-
"@docusaurus/utils": "
|
|
42
|
-
"@docusaurus/utils-validation": "
|
|
41
|
+
"@docusaurus/plugin-content-docs": "^3.0.1",
|
|
42
|
+
"@docusaurus/utils": "^3.0.1",
|
|
43
|
+
"@docusaurus/utils-validation": "^3.0.1",
|
|
43
44
|
"@redocly/openapi-core": "^1.10.5",
|
|
44
45
|
"chalk": "^4.1.2",
|
|
45
46
|
"clsx": "^1.1.1",
|
|
46
47
|
"fs-extra": "^9.0.1",
|
|
47
48
|
"json-pointer": "^0.6.2",
|
|
48
49
|
"json-schema-merge-allof": "^0.8.1",
|
|
50
|
+
"json5": "^2.2.3",
|
|
49
51
|
"lodash": "^4.17.20",
|
|
50
52
|
"mustache": "^4.2.0",
|
|
51
53
|
"openapi-to-postmanv2": "^4.21.0",
|
|
@@ -60,5 +62,5 @@
|
|
|
60
62
|
"engines": {
|
|
61
63
|
"node": ">=14"
|
|
62
64
|
},
|
|
63
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "87427f0ab49405d1aef03436e5c5babc9641dd45"
|
|
64
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import zlib from "zlib";
|
|
|
12
12
|
import type { LoadContext, Plugin } from "@docusaurus/types";
|
|
13
13
|
import { Globby, posixPath } from "@docusaurus/utils";
|
|
14
14
|
import chalk from "chalk";
|
|
15
|
+
import JSON5 from "json5";
|
|
15
16
|
import { render } from "mustache";
|
|
16
17
|
|
|
17
18
|
import {
|
|
@@ -166,21 +167,26 @@ export default function pluginOpenAPIDocs(
|
|
|
166
167
|
tagGroups
|
|
167
168
|
);
|
|
168
169
|
|
|
169
|
-
|
|
170
|
+
let sidebarSliceTemplate = `import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";\n\n`;
|
|
171
|
+
sidebarSliceTemplate += `const sidebar: SidebarsConfig = {{{slice}}};\n\n`;
|
|
172
|
+
sidebarSliceTemplate += `export default sidebar.apisidebar;\n`;
|
|
170
173
|
|
|
171
174
|
const view = render(sidebarSliceTemplate, {
|
|
172
|
-
slice:
|
|
175
|
+
slice: JSON5.stringify(
|
|
176
|
+
{ apisidebar: sidebarSlice },
|
|
177
|
+
{ space: 2, quote: '"' }
|
|
178
|
+
),
|
|
173
179
|
});
|
|
174
180
|
|
|
175
|
-
if (!fs.existsSync(`${outputDir}/sidebar.
|
|
181
|
+
if (!fs.existsSync(`${outputDir}/sidebar.ts`)) {
|
|
176
182
|
try {
|
|
177
|
-
fs.writeFileSync(`${outputDir}/sidebar.
|
|
183
|
+
fs.writeFileSync(`${outputDir}/sidebar.ts`, view, "utf8");
|
|
178
184
|
console.log(
|
|
179
|
-
chalk.green(`Successfully created "${outputDir}/sidebar.
|
|
185
|
+
chalk.green(`Successfully created "${outputDir}/sidebar.ts"`)
|
|
180
186
|
);
|
|
181
187
|
} catch (err) {
|
|
182
188
|
console.error(
|
|
183
|
-
chalk.red(`Failed to write "${outputDir}/sidebar.
|
|
189
|
+
chalk.red(`Failed to write "${outputDir}/sidebar.ts"`),
|
|
184
190
|
chalk.yellow(err)
|
|
185
191
|
);
|
|
186
192
|
}
|
|
@@ -473,11 +479,7 @@ custom_edit_url: null
|
|
|
473
479
|
cwd: path.resolve(apiDir),
|
|
474
480
|
deep: 1,
|
|
475
481
|
});
|
|
476
|
-
const
|
|
477
|
-
cwd: path.resolve(apiDir, "schemas"),
|
|
478
|
-
deep: 1,
|
|
479
|
-
});
|
|
480
|
-
const sidebarFile = await Globby(["sidebar.{js,ts}"], {
|
|
482
|
+
const sidebarFile = await Globby(["sidebar.js", "sidebar.ts"], {
|
|
481
483
|
cwd: path.resolve(apiDir),
|
|
482
484
|
deep: 1,
|
|
483
485
|
});
|
|
@@ -494,20 +496,17 @@ custom_edit_url: null
|
|
|
494
496
|
})
|
|
495
497
|
);
|
|
496
498
|
|
|
497
|
-
|
|
498
|
-
fs.
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
)
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
})
|
|
510
|
-
);
|
|
499
|
+
try {
|
|
500
|
+
fs.rmSync(`${apiDir}/schemas`, { recursive: true });
|
|
501
|
+
console.log(chalk.green(`Cleanup succeeded for "${apiDir}/schemas"`));
|
|
502
|
+
} catch (err: any) {
|
|
503
|
+
if (err.code !== "ENOENT") {
|
|
504
|
+
console.error(
|
|
505
|
+
chalk.red(`Cleanup failed for "${apiDir}/schemas"`),
|
|
506
|
+
chalk.yellow(err)
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
511
510
|
|
|
512
511
|
sidebarFile.map((sidebar) =>
|
|
513
512
|
fs.unlink(`${apiDir}/${sidebar}`, (err) => {
|
|
@@ -538,7 +537,11 @@ custom_edit_url: null
|
|
|
538
537
|
|
|
539
538
|
const versionsJson = JSON.stringify(versionsArray, null, 2);
|
|
540
539
|
try {
|
|
541
|
-
fs.writeFileSync(
|
|
540
|
+
fs.writeFileSync(
|
|
541
|
+
`${outputDir}/versions.json`,
|
|
542
|
+
versionsJson + "\n",
|
|
543
|
+
"utf8"
|
|
544
|
+
);
|
|
542
545
|
console.log(
|
|
543
546
|
chalk.green(`Successfully created "${outputDir}/versions.json"`)
|
|
544
547
|
);
|
|
@@ -574,7 +577,7 @@ custom_edit_url: null
|
|
|
574
577
|
cli
|
|
575
578
|
.command(`gen-api-docs`)
|
|
576
579
|
.description(
|
|
577
|
-
`Generates OpenAPI docs in MDX file format and sidebar.
|
|
580
|
+
`Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).`
|
|
578
581
|
)
|
|
579
582
|
.usage("<id>")
|
|
580
583
|
.arguments("<id>")
|
|
@@ -632,7 +635,7 @@ custom_edit_url: null
|
|
|
632
635
|
cli
|
|
633
636
|
.command(`gen-api-docs:version`)
|
|
634
637
|
.description(
|
|
635
|
-
`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.
|
|
638
|
+
`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if enabled).`
|
|
636
639
|
)
|
|
637
640
|
.usage("<id:version>")
|
|
638
641
|
.arguments("<id:version>")
|
|
@@ -724,7 +727,7 @@ custom_edit_url: null
|
|
|
724
727
|
cli
|
|
725
728
|
.command(`clean-api-docs`)
|
|
726
729
|
.description(
|
|
727
|
-
`Clears the generated OpenAPI docs MDX files and sidebar.
|
|
730
|
+
`Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).`
|
|
728
731
|
)
|
|
729
732
|
.usage("<id>")
|
|
730
733
|
.arguments("<id>")
|
|
@@ -775,7 +778,7 @@ custom_edit_url: null
|
|
|
775
778
|
cli
|
|
776
779
|
.command(`clean-api-docs:version`)
|
|
777
780
|
.description(
|
|
778
|
-
`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.
|
|
781
|
+
`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts (if enabled).`
|
|
779
782
|
)
|
|
780
783
|
.usage("<id:version>")
|
|
781
784
|
.arguments("<id:version>")
|