docusaurus-plugin-openapi-docs 1.0.3 → 1.0.6
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 +104 -15
- package/lib/index.d.ts +6 -1
- package/lib/index.js +181 -17
- package/lib/markdown/createParamsDetails.js +2 -0
- package/lib/markdown/createSchemaDetails.js +2 -0
- package/lib/markdown/index.js +1 -1
- package/lib/openapi/openapi.d.ts +2 -2
- package/lib/openapi/openapi.js +6 -3
- package/lib/openapi/openapi.test.js +1 -1
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +1 -1
- package/lib/openapi/utils/loadAndBundleSpec.js +36 -1
- package/lib/options.d.ts +0 -2
- package/lib/options.js +36 -7
- package/lib/sidebars/index.d.ts +1 -1
- package/lib/sidebars/index.js +11 -10
- package/lib/sidebars/utils.d.ts +2 -0
- package/lib/sidebars/utils.js +31 -0
- package/lib/types.d.ts +22 -9
- package/package.json +3 -2
- package/src/index.ts +227 -17
- package/src/markdown/createParamsDetails.ts +2 -0
- package/src/markdown/createSchemaDetails.ts +2 -0
- package/src/markdown/index.ts +1 -1
- package/src/openapi/openapi.test.ts +1 -1
- package/src/openapi/openapi.ts +12 -3
- package/src/openapi/utils/loadAndBundleSpec.ts +32 -1
- package/src/options.ts +41 -8
- package/src/sidebars/index.ts +15 -10
- package/src/sidebars/utils.ts +29 -0
- package/src/types.ts +22 -8
|
@@ -7,16 +7,39 @@
|
|
|
7
7
|
|
|
8
8
|
// @ts-nocheck
|
|
9
9
|
|
|
10
|
+
import $RefParser from "@apidevtools/json-schema-ref-parser";
|
|
10
11
|
import type { Source, Document } from "@redocly/openapi-core";
|
|
11
12
|
import { bundle } from "@redocly/openapi-core/lib/bundle";
|
|
12
13
|
import type { ResolvedConfig } from "@redocly/openapi-core/lib/config";
|
|
13
14
|
import { Config } from "@redocly/openapi-core/lib/config/config";
|
|
15
|
+
import chalk from "chalk";
|
|
14
16
|
import { convertObj } from "swagger2openapi";
|
|
15
17
|
|
|
16
18
|
import { OpenAPISpec } from "./types";
|
|
17
19
|
|
|
20
|
+
async function resolveJsonRefs(specUrlOrObject: object | string) {
|
|
21
|
+
try {
|
|
22
|
+
let schema = await $RefParser.dereference(specUrlOrObject, {
|
|
23
|
+
continueOnError: true,
|
|
24
|
+
resolve: {
|
|
25
|
+
http: {
|
|
26
|
+
timeout: 15000, // 15 sec timeout
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
dereference: {
|
|
30
|
+
circular: "ignore",
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return schema;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error(chalk.yellow(err.errors[0]?.message ?? err));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
18
40
|
export async function loadAndBundleSpec(
|
|
19
|
-
specUrlOrObject: object | string
|
|
41
|
+
specUrlOrObject: object | string,
|
|
42
|
+
parseJsonRefs: boolean | undefined
|
|
20
43
|
): Promise<OpenAPISpec> {
|
|
21
44
|
const config = new Config({} as ResolvedConfig);
|
|
22
45
|
const bundleOpts = {
|
|
@@ -39,6 +62,14 @@ export async function loadAndBundleSpec(
|
|
|
39
62
|
const {
|
|
40
63
|
bundle: { parsed },
|
|
41
64
|
} = await bundle(bundleOpts);
|
|
65
|
+
if (parseJsonRefs) {
|
|
66
|
+
const resolved = resolveJsonRefs(parsed);
|
|
67
|
+
return typeof resolved === Object
|
|
68
|
+
? resolved.swagger !== undefined
|
|
69
|
+
? convertSwagger2OpenAPI(resolved)
|
|
70
|
+
: resolved
|
|
71
|
+
: parsed;
|
|
72
|
+
}
|
|
42
73
|
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
|
|
43
74
|
}
|
|
44
75
|
|
package/src/options.ts
CHANGED
|
@@ -7,14 +7,47 @@
|
|
|
7
7
|
|
|
8
8
|
import { Joi } from "@docusaurus/utils-validation";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const sidebarOptions = Joi.object({
|
|
11
|
+
groupPathsBy: Joi.string().valid("tag"),
|
|
12
|
+
categoryLinkSource: Joi.string().valid("tag", "info"),
|
|
13
|
+
customProps: Joi.object(),
|
|
14
|
+
sidebarCollapsible: Joi.boolean(),
|
|
15
|
+
sidebarCollapsed: Joi.boolean(),
|
|
16
|
+
});
|
|
16
17
|
|
|
17
18
|
export const OptionsSchema = Joi.object({
|
|
18
|
-
id: Joi.string().
|
|
19
|
-
|
|
19
|
+
id: Joi.string().required(),
|
|
20
|
+
docsPluginId: Joi.string().required(),
|
|
21
|
+
config: Joi.object()
|
|
22
|
+
.pattern(
|
|
23
|
+
/^/,
|
|
24
|
+
Joi.object({
|
|
25
|
+
specPath: Joi.string().required(),
|
|
26
|
+
outputDir: Joi.string().required(),
|
|
27
|
+
template: Joi.string(),
|
|
28
|
+
sidebarOptions: sidebarOptions,
|
|
29
|
+
version: Joi.string().when("versions", {
|
|
30
|
+
is: Joi.exist(),
|
|
31
|
+
then: Joi.required(),
|
|
32
|
+
}),
|
|
33
|
+
label: Joi.string().when("versions", {
|
|
34
|
+
is: Joi.exist(),
|
|
35
|
+
then: Joi.required(),
|
|
36
|
+
}),
|
|
37
|
+
baseUrl: Joi.string().when("versions", {
|
|
38
|
+
is: Joi.exist(),
|
|
39
|
+
then: Joi.required(),
|
|
40
|
+
}),
|
|
41
|
+
versions: Joi.object().pattern(
|
|
42
|
+
/^/,
|
|
43
|
+
Joi.object({
|
|
44
|
+
specPath: Joi.string().required(),
|
|
45
|
+
outputDir: Joi.string().required(),
|
|
46
|
+
label: Joi.string().required(),
|
|
47
|
+
baseUrl: Joi.string().required(),
|
|
48
|
+
})
|
|
49
|
+
),
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
.required(),
|
|
20
53
|
});
|
package/src/sidebars/index.ts
CHANGED
|
@@ -35,9 +35,10 @@ function groupByTags(
|
|
|
35
35
|
items: ApiPageMetadata[],
|
|
36
36
|
sidebarOptions: SidebarOptions,
|
|
37
37
|
options: APIOptions,
|
|
38
|
-
tags: TagObject[]
|
|
38
|
+
tags: TagObject[],
|
|
39
|
+
docPath: string
|
|
39
40
|
): ProcessedSidebar {
|
|
40
|
-
const { outputDir } = options;
|
|
41
|
+
const { outputDir, label } = options;
|
|
41
42
|
const {
|
|
42
43
|
sidebarCollapsed,
|
|
43
44
|
sidebarCollapsible,
|
|
@@ -63,10 +64,9 @@ function groupByTags(
|
|
|
63
64
|
.filter((item): item is string => !!item)
|
|
64
65
|
);
|
|
65
66
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.slice(outputDir.indexOf("/", 1))
|
|
69
|
-
.replace(/^\/+/g, "");
|
|
67
|
+
const basePath = docPath
|
|
68
|
+
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
|
|
69
|
+
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
70
70
|
|
|
71
71
|
function createDocItem(item: ApiPageMetadata): SidebarItemDoc {
|
|
72
72
|
const sidebar_label = item.frontMatter.sidebar_label;
|
|
@@ -74,7 +74,8 @@ function groupByTags(
|
|
|
74
74
|
const id = item.id;
|
|
75
75
|
return {
|
|
76
76
|
type: "doc" as const,
|
|
77
|
-
id:
|
|
77
|
+
id:
|
|
78
|
+
basePath === "" || undefined ? `${item.id}` : `${basePath}/${item.id}`,
|
|
78
79
|
label: (sidebar_label as string) ?? title ?? id,
|
|
79
80
|
customProps: customProps,
|
|
80
81
|
className: clsx(
|
|
@@ -134,7 +135,9 @@ function groupByTags(
|
|
|
134
135
|
linkConfig = {
|
|
135
136
|
type: "generated-index" as "generated-index",
|
|
136
137
|
title: tag,
|
|
137
|
-
slug:
|
|
138
|
+
slug: label
|
|
139
|
+
? "/category/" + kebabCase(label) + "/" + kebabCase(tag)
|
|
140
|
+
: "/category/" + kebabCase(tag),
|
|
138
141
|
} as SidebarItemCategoryLinkConfig;
|
|
139
142
|
}
|
|
140
143
|
|
|
@@ -183,7 +186,8 @@ export default function generateSidebarSlice(
|
|
|
183
186
|
sidebarOptions: SidebarOptions,
|
|
184
187
|
options: APIOptions,
|
|
185
188
|
api: ApiMetadata[],
|
|
186
|
-
tags: TagObject[]
|
|
189
|
+
tags: TagObject[],
|
|
190
|
+
docPath: string
|
|
187
191
|
) {
|
|
188
192
|
let sidebarSlice: ProcessedSidebar = [];
|
|
189
193
|
if (sidebarOptions.groupPathsBy === "tag") {
|
|
@@ -191,7 +195,8 @@ export default function generateSidebarSlice(
|
|
|
191
195
|
api as ApiPageMetadata[],
|
|
192
196
|
sidebarOptions,
|
|
193
197
|
options,
|
|
194
|
-
tags
|
|
198
|
+
tags,
|
|
199
|
+
docPath
|
|
195
200
|
);
|
|
196
201
|
}
|
|
197
202
|
return sidebarSlice;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import { render } from "mustache";
|
|
9
|
+
|
|
10
|
+
export function versionSelector(versions: object[]) {
|
|
11
|
+
const template = `<div class="dropdown dropdown--hoverable dropdown--right">
|
|
12
|
+
<button class="button button--block button--sm button--secondary"><span>Select API Version</span></button>
|
|
13
|
+
<ul class="dropdown__menu">
|
|
14
|
+
{{#.}}<li><a class="dropdown__link" href="{{{baseUrl}}}">{{{label}}}</a></li>{{/.}}
|
|
15
|
+
</ul>
|
|
16
|
+
</div>
|
|
17
|
+
`;
|
|
18
|
+
const view = render(template, versions);
|
|
19
|
+
return view;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function versionCrumb(version: string) {
|
|
23
|
+
const template = `<ul style="display: flex;" class="breadcrumbs breadcrumbs--sm">
|
|
24
|
+
<li style="margin-left: auto; margin-right: 0;" class="breadcrumbs__item breadcrumbs__item--active">
|
|
25
|
+
<a class="breadcrumbs__link"><span>{{{.}}}</span></a></li></ul>
|
|
26
|
+
`;
|
|
27
|
+
const view = render(template, version);
|
|
28
|
+
return view;
|
|
29
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type {
|
|
|
22
22
|
} from "@docusaurus/plugin-content-docs-types";
|
|
23
23
|
export interface PluginOptions {
|
|
24
24
|
id?: string;
|
|
25
|
+
docsPluginId: string;
|
|
25
26
|
config: {
|
|
26
27
|
[key: string]: APIOptions;
|
|
27
28
|
};
|
|
@@ -32,6 +33,27 @@ export interface APIOptions {
|
|
|
32
33
|
outputDir: string;
|
|
33
34
|
template?: string;
|
|
34
35
|
sidebarOptions?: SidebarOptions;
|
|
36
|
+
version?: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
baseUrl?: string;
|
|
39
|
+
versions?: {
|
|
40
|
+
[key: string]: APIVersionOptions;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SidebarOptions {
|
|
45
|
+
groupPathsBy?: string;
|
|
46
|
+
categoryLinkSource?: string;
|
|
47
|
+
customProps?: { [key: string]: unknown };
|
|
48
|
+
sidebarCollapsible?: boolean;
|
|
49
|
+
sidebarCollapsed?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface APIVersionOptions {
|
|
53
|
+
specPath: string;
|
|
54
|
+
outputDir: string;
|
|
55
|
+
label: string;
|
|
56
|
+
baseUrl: string;
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
export interface LoadedContent {
|
|
@@ -99,11 +121,3 @@ export interface ApiNavLink {
|
|
|
99
121
|
title: string;
|
|
100
122
|
permalink: string;
|
|
101
123
|
}
|
|
102
|
-
|
|
103
|
-
export interface SidebarOptions {
|
|
104
|
-
groupPathsBy?: string;
|
|
105
|
-
categoryLinkSource?: string;
|
|
106
|
-
customProps?: { [key: string]: unknown };
|
|
107
|
-
sidebarCollapsible?: boolean;
|
|
108
|
-
sidebarCollapsed?: boolean;
|
|
109
|
-
}
|