docusaurus-plugin-openapi-docs 1.5.2 → 1.6.1
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 +20 -19
- package/lib/index.js +5 -0
- package/lib/markdown/createAuthentication.js +45 -13
- package/lib/markdown/createRequestSchema.js +35 -20
- package/lib/markdown/createResponseSchema.js +39 -22
- package/lib/markdown/createStatusCodes.js +3 -1
- package/lib/markdown/index.js +1 -1
- package/lib/markdown/utils.js +2 -2
- package/lib/openapi/createRequestExample.js +1 -1
- package/lib/openapi/createResponseExample.js +1 -1
- package/lib/openapi/openapi.js +7 -1
- package/lib/openapi/utils/loadAndResolveSpec.js +13 -0
- package/lib/options.js +3 -1
- package/lib/sidebars/index.js +3 -1
- package/lib/types.d.ts +1 -0
- package/package.json +8 -8
- package/src/index.ts +6 -0
- package/src/markdown/createAuthentication.ts +53 -17
- package/src/markdown/createRequestSchema.ts +104 -23
- package/src/markdown/createResponseSchema.ts +119 -34
- package/src/markdown/createStatusCodes.ts +38 -39
- package/src/markdown/index.ts +1 -1
- package/src/markdown/utils.ts +2 -2
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
- package/src/openapi/openapi.ts +7 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +15 -0
- package/src/options.ts +3 -1
- package/src/sidebars/index.ts +6 -1
- package/src/types.ts +1 -0
|
@@ -62,46 +62,45 @@ function createResponseHeaders(responseHeaders: any) {
|
|
|
62
62
|
create("ul", {
|
|
63
63
|
style: { marginLeft: "1rem" },
|
|
64
64
|
children: [
|
|
65
|
-
Object.entries(responseHeaders).map(
|
|
66
|
-
|
|
67
|
-
description,
|
|
68
|
-
|
|
69
|
-
example,
|
|
70
|
-
}: any = headerObj;
|
|
65
|
+
Object.entries(responseHeaders).map(
|
|
66
|
+
([headerName, headerObj]: [any, any]) => {
|
|
67
|
+
const { description, example }: any = headerObj;
|
|
68
|
+
const type = headerObj.schema?.type ?? "any";
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
70
|
+
return create("li", {
|
|
71
|
+
className: "schemaItem",
|
|
72
|
+
children: [
|
|
73
|
+
createDetailsSummary({
|
|
74
|
+
children: [
|
|
75
|
+
create("strong", { children: headerName }),
|
|
76
|
+
guard(type, () => [
|
|
77
|
+
create("span", {
|
|
78
|
+
style: { opacity: "0.6" },
|
|
79
|
+
children: ` ${type}`,
|
|
80
|
+
}),
|
|
81
|
+
]),
|
|
82
|
+
],
|
|
83
|
+
}),
|
|
84
|
+
create("div", {
|
|
85
|
+
children: [
|
|
86
|
+
guard(description, (description) =>
|
|
87
|
+
create("div", {
|
|
88
|
+
style: {
|
|
89
|
+
marginTop: ".5rem",
|
|
90
|
+
marginBottom: ".5rem",
|
|
91
|
+
},
|
|
92
|
+
children: [
|
|
93
|
+
guard(example, () => `Example: ${example}`),
|
|
94
|
+
createDescription(description),
|
|
95
|
+
],
|
|
96
|
+
})
|
|
97
|
+
),
|
|
98
|
+
],
|
|
99
|
+
}),
|
|
100
|
+
],
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
),
|
|
105
104
|
],
|
|
106
105
|
})
|
|
107
106
|
);
|
package/src/markdown/index.ts
CHANGED
|
@@ -88,7 +88,7 @@ export function createInfoPageMD({
|
|
|
88
88
|
}: InfoPageMetadata) {
|
|
89
89
|
return render([
|
|
90
90
|
`import ApiLogo from "@theme/ApiLogo";\n`,
|
|
91
|
-
`import
|
|
91
|
+
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
92
92
|
`import TabItem from "@theme/TabItem";\n`,
|
|
93
93
|
`import Export from "@theme/ApiDemoPanel/Export";\n\n`,
|
|
94
94
|
|
package/src/markdown/utils.ts
CHANGED
|
@@ -24,7 +24,7 @@ export function guard<T>(
|
|
|
24
24
|
value: T | undefined,
|
|
25
25
|
cb: (value: T) => Children
|
|
26
26
|
): string {
|
|
27
|
-
if (value) {
|
|
27
|
+
if (!!value) {
|
|
28
28
|
const children = cb(value);
|
|
29
29
|
return render(children);
|
|
30
30
|
}
|
|
@@ -45,5 +45,5 @@ export function render(children: Children): string {
|
|
|
45
45
|
export const lessThan =
|
|
46
46
|
/<(?!(=|button|\s?\/button|details|\s?\/details|summary|\s?\/summary|hr|\s?\/hr|br|\s?\/br|span|\s?\/span|strong|\s?\/strong|small|\s?\/small|table|\s?\/table|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|a|\s?\/a|li|\s?\/li|ol|\s?\/ol|ul|\s?\/ul|img|\s?\/img|div|\s?\/div|center|\s?\/center))/gu;
|
|
47
47
|
export const greaterThan =
|
|
48
|
-
/(?<!(button|details|summary|hr|br|span|strong|small|table|td|tr|th|h1|h2|h3|h4|h5|h6|title|p|em|b|i|u|strike|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/gu;
|
|
48
|
+
/(?<!(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|a|tag|li|ol|ul|img|div|center|\/|\s|"|'))>/gu;
|
|
49
49
|
export const codeFence = /`{1,3}[\s\S]*?`{1,3}/g;
|
|
@@ -31,7 +31,7 @@ const primitives: Primitives = {
|
|
|
31
31
|
default: () => "string",
|
|
32
32
|
email: () => "user@example.com",
|
|
33
33
|
date: () => new Date().toISOString().substring(0, 10),
|
|
34
|
-
"date-time": () => new Date().toISOString()
|
|
34
|
+
"date-time": () => new Date().toISOString(),
|
|
35
35
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
36
36
|
hostname: () => "example.com",
|
|
37
37
|
ipv4: () => "198.51.100.42",
|
|
@@ -31,7 +31,7 @@ const primitives: Primitives = {
|
|
|
31
31
|
default: () => "string",
|
|
32
32
|
email: () => "user@example.com",
|
|
33
33
|
date: () => new Date().toISOString().substring(0, 10),
|
|
34
|
-
"date-time": () => new Date().toISOString()
|
|
34
|
+
"date-time": () => new Date().toISOString(),
|
|
35
35
|
uuid: () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
|
|
36
36
|
hostname: () => "example.com",
|
|
37
37
|
ipv4: () => "198.51.100.42",
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -88,7 +88,7 @@ function createItems(
|
|
|
88
88
|
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
89
89
|
const infoId = kebabCase(infoIdSpaces);
|
|
90
90
|
|
|
91
|
-
if (openapiData.info.description) {
|
|
91
|
+
if (openapiData.info.description || openapiData.info.title) {
|
|
92
92
|
// Only create an info page if we have a description.
|
|
93
93
|
const infoDescription = openapiData.info?.description;
|
|
94
94
|
let splitDescription: any;
|
|
@@ -221,6 +221,9 @@ function createItems(
|
|
|
221
221
|
.replace(/\s+$/, "")
|
|
222
222
|
: "",
|
|
223
223
|
...(options?.proxy && { proxy: options.proxy }),
|
|
224
|
+
...(options?.hideSendButton && {
|
|
225
|
+
hide_send_button: options.hideSendButton,
|
|
226
|
+
}),
|
|
224
227
|
},
|
|
225
228
|
api: {
|
|
226
229
|
...defaults,
|
|
@@ -338,6 +341,9 @@ function createItems(
|
|
|
338
341
|
.replace(/\s+$/, "")
|
|
339
342
|
: "",
|
|
340
343
|
...(options?.proxy && { proxy: options.proxy }),
|
|
344
|
+
...(options?.hideSendButton && {
|
|
345
|
+
hide_send_button: options.hideSendButton,
|
|
346
|
+
}),
|
|
341
347
|
},
|
|
342
348
|
api: {
|
|
343
349
|
...defaults,
|
|
@@ -128,6 +128,21 @@ export async function loadAndResolveSpec(specUrlOrObject: object | string) {
|
|
|
128
128
|
const {
|
|
129
129
|
bundle: { parsed },
|
|
130
130
|
} = await bundle(bundleOpts);
|
|
131
|
+
|
|
132
|
+
//Pre-processing before resolving JSON refs
|
|
133
|
+
if (parsed.components) {
|
|
134
|
+
for (let [component, type] of Object.entries(parsed.components) as any) {
|
|
135
|
+
if (component === "schemas") {
|
|
136
|
+
for (let [schemaKey, schemaValue] of Object.entries(type) as any) {
|
|
137
|
+
const title: string | undefined = schemaValue["title"];
|
|
138
|
+
if (!title) {
|
|
139
|
+
schemaValue.title = schemaKey;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
131
146
|
const resolved = await resolveJsonRefs(parsed);
|
|
132
147
|
|
|
133
148
|
// Force serialization and replace circular $ref pointers
|
package/src/options.ts
CHANGED
|
@@ -9,7 +9,8 @@ import { Joi } from "@docusaurus/utils-validation";
|
|
|
9
9
|
|
|
10
10
|
const sidebarOptions = Joi.object({
|
|
11
11
|
groupPathsBy: Joi.string().valid("tag"),
|
|
12
|
-
|
|
12
|
+
// TODO: Remove "none" in 2.0, make it the default if not specified
|
|
13
|
+
categoryLinkSource: Joi.string().valid("tag", "info", "none"),
|
|
13
14
|
customProps: Joi.object(),
|
|
14
15
|
sidebarCollapsible: Joi.boolean(),
|
|
15
16
|
sidebarCollapsed: Joi.boolean(),
|
|
@@ -27,6 +28,7 @@ export const OptionsSchema = Joi.object({
|
|
|
27
28
|
outputDir: Joi.string().required(),
|
|
28
29
|
template: Joi.string(),
|
|
29
30
|
downloadUrl: Joi.string(),
|
|
31
|
+
hideSendButton: Joi.boolean(),
|
|
30
32
|
sidebarOptions: sidebarOptions,
|
|
31
33
|
version: Joi.string().when("versions", {
|
|
32
34
|
is: Joi.exist(),
|
package/src/sidebars/index.ts
CHANGED
|
@@ -41,7 +41,11 @@ function groupByTags(
|
|
|
41
41
|
tags: TagObject[][],
|
|
42
42
|
docPath: string
|
|
43
43
|
): ProcessedSidebar {
|
|
44
|
-
|
|
44
|
+
let { outputDir, label } = options;
|
|
45
|
+
|
|
46
|
+
// Remove trailing slash before proceeding
|
|
47
|
+
outputDir = outputDir.replace(/\/$/, "");
|
|
48
|
+
|
|
45
49
|
const {
|
|
46
50
|
sidebarCollapsed,
|
|
47
51
|
sidebarCollapsible,
|
|
@@ -214,6 +218,7 @@ export default function generateSidebarSlice(
|
|
|
214
218
|
docPath: string
|
|
215
219
|
) {
|
|
216
220
|
let sidebarSlice: ProcessedSidebar = [];
|
|
221
|
+
|
|
217
222
|
if (sidebarOptions.groupPathsBy === "tag") {
|
|
218
223
|
sidebarSlice = groupByTags(
|
|
219
224
|
api as ApiPageMetadata[],
|