docusaurus-plugin-openapi-docs 0.0.0-1000
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/LICENSE +21 -0
- package/README.md +361 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.js +709 -0
- package/lib/markdown/createArrayBracket.d.ts +2 -0
- package/lib/markdown/createArrayBracket.js +36 -0
- package/lib/markdown/createAuthentication.d.ts +2 -0
- package/lib/markdown/createAuthentication.js +171 -0
- package/lib/markdown/createAuthorization.d.ts +1 -0
- package/lib/markdown/createAuthorization.js +15 -0
- package/lib/markdown/createCallbackMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createCallbackMethodEndpoint.js +20 -0
- package/lib/markdown/createCallbacks.d.ts +6 -0
- package/lib/markdown/createCallbacks.js +77 -0
- package/lib/markdown/createContactInfo.d.ts +2 -0
- package/lib/markdown/createContactInfo.js +39 -0
- package/lib/markdown/createDeprecationNotice.d.ts +6 -0
- package/lib/markdown/createDeprecationNotice.js +20 -0
- package/lib/markdown/createDescription.d.ts +1 -0
- package/lib/markdown/createDescription.js +13 -0
- package/lib/markdown/createDetails.d.ts +2 -0
- package/lib/markdown/createDetails.js +17 -0
- package/lib/markdown/createDetailsSummary.d.ts +2 -0
- package/lib/markdown/createDetailsSummary.js +17 -0
- package/lib/markdown/createDownload.d.ts +1 -0
- package/lib/markdown/createDownload.js +16 -0
- package/lib/markdown/createHeading.d.ts +1 -0
- package/lib/markdown/createHeading.js +20 -0
- package/lib/markdown/createLicense.d.ts +2 -0
- package/lib/markdown/createLicense.js +32 -0
- package/lib/markdown/createLogo.d.ts +2 -0
- package/lib/markdown/createLogo.js +18 -0
- package/lib/markdown/createMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createMethodEndpoint.js +20 -0
- package/lib/markdown/createParamsDetails.d.ts +6 -0
- package/lib/markdown/createParamsDetails.js +18 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +13 -0
- package/lib/markdown/createRequestBodyDetails.js +13 -0
- package/lib/markdown/createRequestHeader.d.ts +1 -0
- package/lib/markdown/createRequestHeader.js +21 -0
- package/lib/markdown/createRequestSchema.d.ts +14 -0
- package/lib/markdown/createRequestSchema.js +20 -0
- package/lib/markdown/createResponseSchema.d.ts +14 -0
- package/lib/markdown/createResponseSchema.js +20 -0
- package/lib/markdown/createSchema.d.ts +9 -0
- package/lib/markdown/createSchema.js +668 -0
- package/lib/markdown/createSchema.test.d.ts +1 -0
- package/lib/markdown/createSchema.test.js +913 -0
- package/lib/markdown/createStatusCodes.d.ts +9 -0
- package/lib/markdown/createStatusCodes.js +63 -0
- package/lib/markdown/createTermsOfService.d.ts +1 -0
- package/lib/markdown/createTermsOfService.js +31 -0
- package/lib/markdown/createVendorExtensions.d.ts +1 -0
- package/lib/markdown/createVendorExtensions.js +24 -0
- package/lib/markdown/createVersionBadge.d.ts +1 -0
- package/lib/markdown/createVersionBadge.js +19 -0
- package/lib/markdown/index.d.ts +5 -0
- package/lib/markdown/index.js +92 -0
- package/lib/markdown/schema.d.ts +3 -0
- package/lib/markdown/schema.js +154 -0
- package/lib/markdown/schema.test.d.ts +1 -0
- package/lib/markdown/schema.test.js +181 -0
- package/lib/markdown/utils.d.ts +20 -0
- package/lib/markdown/utils.js +68 -0
- package/lib/openapi/createRequestExample.d.ts +2 -0
- package/lib/openapi/createRequestExample.js +191 -0
- package/lib/openapi/createResponseExample.d.ts +2 -0
- package/lib/openapi/createResponseExample.js +192 -0
- package/lib/openapi/index.d.ts +1 -0
- package/lib/openapi/index.js +12 -0
- package/lib/openapi/openapi.d.ts +12 -0
- package/lib/openapi/openapi.js +544 -0
- package/lib/openapi/openapi.test.d.ts +1 -0
- package/lib/openapi/openapi.test.js +33 -0
- package/lib/openapi/types.d.ts +354 -0
- package/lib/openapi/types.js +8 -0
- package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
- package/lib/openapi/utils/loadAndResolveSpec.js +153 -0
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
- package/lib/openapi/utils/services/OpenAPIParser.js +343 -0
- package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
- package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
- package/lib/openapi/utils/types/index.d.ts +2 -0
- package/lib/openapi/utils/types/index.js +23 -0
- package/lib/openapi/utils/types/open-api.d.ts +305 -0
- package/lib/openapi/utils/types/open-api.js +8 -0
- package/lib/openapi/utils/types.d.ts +306 -0
- package/lib/openapi/utils/types.js +8 -0
- package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
- package/lib/openapi/utils/utils/JsonPointer.js +95 -0
- package/lib/openapi/utils/utils/helpers.d.ts +43 -0
- package/lib/openapi/utils/utils/helpers.js +230 -0
- package/lib/openapi/utils/utils/index.d.ts +3 -0
- package/lib/openapi/utils/utils/index.js +25 -0
- package/lib/openapi/utils/utils/openapi.d.ts +40 -0
- package/lib/openapi/utils/utils/openapi.js +605 -0
- package/lib/options.d.ts +2 -0
- package/lib/options.js +69 -0
- package/lib/sidebars/index.d.ts +4 -0
- package/lib/sidebars/index.js +226 -0
- package/lib/sidebars/utils.d.ts +2 -0
- package/lib/sidebars/utils.js +30 -0
- package/lib/types.d.ts +135 -0
- package/lib/types.js +8 -0
- package/package.json +69 -0
- package/src/index.ts +945 -0
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +1605 -0
- package/src/markdown/createArrayBracket.ts +35 -0
- package/src/markdown/createAuthentication.ts +201 -0
- package/src/markdown/createAuthorization.ts +13 -0
- package/src/markdown/createCallbackMethodEndpoint.ts +19 -0
- package/src/markdown/createCallbacks.ts +101 -0
- package/src/markdown/createContactInfo.ts +41 -0
- package/src/markdown/createDeprecationNotice.ts +31 -0
- package/src/markdown/createDescription.ts +12 -0
- package/src/markdown/createDetails.ts +16 -0
- package/src/markdown/createDetailsSummary.ts +16 -0
- package/src/markdown/createDownload.ts +15 -0
- package/src/markdown/createHeading.ts +23 -0
- package/src/markdown/createLicense.ts +34 -0
- package/src/markdown/createLogo.ts +21 -0
- package/src/markdown/createMethodEndpoint.ts +19 -0
- package/src/markdown/createParamsDetails.ts +22 -0
- package/src/markdown/createRequestBodyDetails.ts +24 -0
- package/src/markdown/createRequestHeader.ts +24 -0
- package/src/markdown/createRequestSchema.ts +32 -0
- package/src/markdown/createResponseSchema.ts +32 -0
- package/src/markdown/createSchema.test.ts +1075 -0
- package/src/markdown/createSchema.ts +862 -0
- package/src/markdown/createStatusCodes.ts +63 -0
- package/src/markdown/createTermsOfService.ts +30 -0
- package/src/markdown/createVendorExtensions.ts +22 -0
- package/src/markdown/createVersionBadge.ts +22 -0
- package/src/markdown/index.ts +144 -0
- package/src/markdown/schema.test.ts +208 -0
- package/src/markdown/schema.ts +185 -0
- package/src/markdown/utils.ts +89 -0
- package/src/openapi/__fixtures__/examples/openapi.yaml +49 -0
- package/src/openapi/createRequestExample.ts +235 -0
- package/src/openapi/createResponseExample.ts +238 -0
- package/src/openapi/index.ts +8 -0
- package/src/openapi/openapi.test.ts +40 -0
- package/src/openapi/openapi.ts +697 -0
- package/src/openapi/types.ts +455 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +171 -0
- package/src/openapi/utils/services/OpenAPIParser.ts +434 -0
- package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
- package/src/openapi/utils/types/index.ts +10 -0
- package/src/openapi/utils/types/open-api.ts +303 -0
- package/src/openapi/utils/types.ts +303 -0
- package/src/openapi/utils/utils/JsonPointer.ts +99 -0
- package/src/openapi/utils/utils/helpers.ts +239 -0
- package/src/openapi/utils/utils/index.ts +11 -0
- package/src/openapi/utils/utils/openapi.ts +771 -0
- package/src/openapi-to-postmanv2.d.ts +10 -0
- package/src/options.ts +77 -0
- package/src/plugin-content-docs-types.d.ts +42 -0
- package/src/plugin-openapi.d.ts +87 -0
- package/src/postman-collection.d.ts +10 -0
- package/src/sidebars/index.ts +322 -0
- package/src/sidebars/utils.ts +29 -0
- package/src/types.ts +176 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
declare module "openapi-to-postmanv2" {
|
|
9
|
+
export default any;
|
|
10
|
+
}
|
package/src/options.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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 { Joi } from "@docusaurus/utils-validation";
|
|
9
|
+
|
|
10
|
+
const sidebarGenerators = Joi.object({
|
|
11
|
+
createDocItem: Joi.function(),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const sidebarOptions = Joi.object({
|
|
15
|
+
groupPathsBy: Joi.string().valid("tag", "tagGroup"),
|
|
16
|
+
categoryLinkSource: Joi.string().valid("tag", "info", "auto"),
|
|
17
|
+
customProps: Joi.object(),
|
|
18
|
+
sidebarCollapsible: Joi.boolean(),
|
|
19
|
+
sidebarCollapsed: Joi.boolean(),
|
|
20
|
+
sidebarGenerators: sidebarGenerators,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const markdownGenerators = Joi.object({
|
|
24
|
+
createApiPageMD: Joi.function(),
|
|
25
|
+
createInfoPageMD: Joi.function(),
|
|
26
|
+
createTagPageMD: Joi.function(),
|
|
27
|
+
createSchemaPageMD: Joi.function(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const OptionsSchema = Joi.object({
|
|
31
|
+
id: Joi.string().required(),
|
|
32
|
+
docsPlugin: Joi.string(),
|
|
33
|
+
docsPluginId: Joi.string().required(),
|
|
34
|
+
config: Joi.object()
|
|
35
|
+
.pattern(
|
|
36
|
+
/^/,
|
|
37
|
+
Joi.object({
|
|
38
|
+
specPath: Joi.string().required(),
|
|
39
|
+
proxy: Joi.string(),
|
|
40
|
+
outputDir: Joi.string().required(),
|
|
41
|
+
template: Joi.string(),
|
|
42
|
+
infoTemplate: Joi.string(),
|
|
43
|
+
tagTemplate: Joi.string(),
|
|
44
|
+
schemaTemplate: Joi.string(),
|
|
45
|
+
downloadUrl: Joi.string(),
|
|
46
|
+
hideSendButton: Joi.boolean(),
|
|
47
|
+
showExtensions: Joi.boolean(),
|
|
48
|
+
sidebarOptions: sidebarOptions,
|
|
49
|
+
markdownGenerators: markdownGenerators,
|
|
50
|
+
showSchemas: Joi.boolean(),
|
|
51
|
+
disableCompression: Joi.boolean(),
|
|
52
|
+
version: Joi.string().when("versions", {
|
|
53
|
+
is: Joi.exist(),
|
|
54
|
+
then: Joi.required(),
|
|
55
|
+
}),
|
|
56
|
+
label: Joi.string().when("versions", {
|
|
57
|
+
is: Joi.exist(),
|
|
58
|
+
then: Joi.required(),
|
|
59
|
+
}),
|
|
60
|
+
baseUrl: Joi.string().when("versions", {
|
|
61
|
+
is: Joi.exist(),
|
|
62
|
+
then: Joi.required(),
|
|
63
|
+
}),
|
|
64
|
+
versions: Joi.object().pattern(
|
|
65
|
+
/^/,
|
|
66
|
+
Joi.object({
|
|
67
|
+
specPath: Joi.string().required(),
|
|
68
|
+
outputDir: Joi.string().required(),
|
|
69
|
+
label: Joi.string().required(),
|
|
70
|
+
baseUrl: Joi.string().required(),
|
|
71
|
+
downloadUrl: Joi.string(),
|
|
72
|
+
})
|
|
73
|
+
),
|
|
74
|
+
})
|
|
75
|
+
)
|
|
76
|
+
.required(),
|
|
77
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
declare module "@docusaurus/plugin-content-docs-types" {
|
|
9
|
+
// Makes all properties visible when hovering over the type
|
|
10
|
+
type Expand<T extends Record<string, unknown>> = { [P in keyof T]: T[P] };
|
|
11
|
+
|
|
12
|
+
export type SidebarItemBase = {
|
|
13
|
+
className?: string;
|
|
14
|
+
customProps?: Record<string, unknown>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type SidebarItemLink = SidebarItemBase & {
|
|
18
|
+
type: "link";
|
|
19
|
+
href: string;
|
|
20
|
+
label: string;
|
|
21
|
+
docId: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
type SidebarItemCategoryBase = SidebarItemBase & {
|
|
25
|
+
type: "category";
|
|
26
|
+
label: string;
|
|
27
|
+
collapsed: boolean;
|
|
28
|
+
collapsible: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type PropSidebarItemCategory = Expand<
|
|
32
|
+
SidebarItemCategoryBase & {
|
|
33
|
+
items: PropSidebarItem[];
|
|
34
|
+
}
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
export type PropSidebarItem = SidebarItemLink | PropSidebarItemCategory;
|
|
38
|
+
export type PropSidebar = PropSidebarItem[];
|
|
39
|
+
export type PropSidebars = {
|
|
40
|
+
[sidebarId: string]: PropSidebar;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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 type { FrontMatter as DocsFrontMatter } from "@docusaurus/types";
|
|
9
|
+
import type { Props as DocsProps } from "@docusaurus/types";
|
|
10
|
+
|
|
11
|
+
// TODO: figure out how to import this
|
|
12
|
+
declare module "docusaurus-plugin-openapi-docs" {
|
|
13
|
+
import type { PropSidebars } from "@docusaurus/plugin-content-docs-types";
|
|
14
|
+
|
|
15
|
+
export type Options = Partial<import("./types").APIOptions>;
|
|
16
|
+
|
|
17
|
+
export type PropApiMetadata = {
|
|
18
|
+
// TODO: adjust this to our needs
|
|
19
|
+
pluginId: string;
|
|
20
|
+
version: string;
|
|
21
|
+
label: string;
|
|
22
|
+
banner: VersionBanner | null;
|
|
23
|
+
badge: boolean;
|
|
24
|
+
className: string;
|
|
25
|
+
isLast: boolean;
|
|
26
|
+
apiSidebars: PropSidebars;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
declare module "@theme/ApiPage" {
|
|
31
|
+
import type { ApiRoute } from "@theme/ApiItem";
|
|
32
|
+
import type { PropApiMetadata } from "docusaurus-plugin-openapi";
|
|
33
|
+
|
|
34
|
+
export interface Props {
|
|
35
|
+
readonly location: { readonly pathname: string };
|
|
36
|
+
readonly apiMetadata: PropApiMetadata;
|
|
37
|
+
readonly route: {
|
|
38
|
+
readonly path: string;
|
|
39
|
+
readonly component: () => JSX.Element;
|
|
40
|
+
readonly routes: ApiRoute[];
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ApiPage: (props: Props) => JSX.Element;
|
|
45
|
+
export default ApiPage;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
declare module "@theme/ApiItem" {
|
|
49
|
+
import type { Request } from "postman-collection";
|
|
50
|
+
|
|
51
|
+
import type { ApiItem } from "./types";
|
|
52
|
+
|
|
53
|
+
export type ApiRoute = {
|
|
54
|
+
readonly component: () => JSX.Element;
|
|
55
|
+
readonly exact: boolean;
|
|
56
|
+
readonly path: string;
|
|
57
|
+
readonly sidebar?: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export interface FrontMatter extends DocsFrontMatter {
|
|
61
|
+
readonly api?: object;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type Metadata = {
|
|
65
|
+
readonly description?: string;
|
|
66
|
+
readonly title?: string;
|
|
67
|
+
readonly permalink?: string;
|
|
68
|
+
readonly previous?: { readonly permalink: string; readonly title: string };
|
|
69
|
+
readonly next?: { readonly permalink: string; readonly title: string };
|
|
70
|
+
readonly api?: ApiItem & { postman: Request }; // TODO
|
|
71
|
+
readonly type?: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export interface Props extends DocsProps {
|
|
75
|
+
readonly route: ApiRoute;
|
|
76
|
+
readonly content: {
|
|
77
|
+
readonly frontMatter: FrontMatter;
|
|
78
|
+
readonly metadata: Metadata;
|
|
79
|
+
readonly contentTitle: string | undefined;
|
|
80
|
+
readonly toc: array | undefined;
|
|
81
|
+
(): JSX.Element;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const ApiItem: (props: Props) => JSX.Element;
|
|
86
|
+
export default ApiItem;
|
|
87
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
declare module "postman-collection" {
|
|
9
|
+
export default any;
|
|
10
|
+
}
|
|
@@ -0,0 +1,322 @@
|
|
|
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 path from "path";
|
|
9
|
+
|
|
10
|
+
import { ProcessedSidebarItem } from "@docusaurus/plugin-content-docs/lib/sidebars/types";
|
|
11
|
+
import {
|
|
12
|
+
ProcessedSidebar,
|
|
13
|
+
SidebarItemCategory,
|
|
14
|
+
SidebarItemCategoryLinkConfig,
|
|
15
|
+
} from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
16
|
+
import { posixPath } from "@docusaurus/utils";
|
|
17
|
+
import clsx from "clsx";
|
|
18
|
+
import { kebabCase } from "lodash";
|
|
19
|
+
import uniq from "lodash/uniq";
|
|
20
|
+
|
|
21
|
+
import { TagGroupObject, TagObject } from "../openapi/types";
|
|
22
|
+
import type {
|
|
23
|
+
SidebarOptions,
|
|
24
|
+
APIOptions,
|
|
25
|
+
ApiPageMetadata,
|
|
26
|
+
ApiMetadata,
|
|
27
|
+
InfoPageMetadata,
|
|
28
|
+
SchemaPageMetadata,
|
|
29
|
+
ApiDocItemGenerator,
|
|
30
|
+
} from "../types";
|
|
31
|
+
|
|
32
|
+
function isApiItem(item: ApiMetadata): item is ApiMetadata {
|
|
33
|
+
return item.type === "api";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isInfoItem(item: ApiMetadata): item is ApiMetadata {
|
|
37
|
+
return item.type === "info";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isSchemaItem(item: ApiMetadata): item is ApiMetadata {
|
|
41
|
+
return item.type === "schema";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const createDocItem: ApiDocItemGenerator = (
|
|
45
|
+
item,
|
|
46
|
+
{ sidebarOptions: { customProps }, basePath }
|
|
47
|
+
) => {
|
|
48
|
+
const sidebar_label = item.frontMatter.sidebar_label;
|
|
49
|
+
const title = item.title;
|
|
50
|
+
const id = item.type === "schema" ? `schemas/${item.id}` : item.id;
|
|
51
|
+
const className =
|
|
52
|
+
item.type === "api"
|
|
53
|
+
? clsx(
|
|
54
|
+
{
|
|
55
|
+
"menu__list-item--deprecated": item.api.deprecated,
|
|
56
|
+
"api-method": !!item.api.method,
|
|
57
|
+
},
|
|
58
|
+
item.api.method
|
|
59
|
+
)
|
|
60
|
+
: clsx(
|
|
61
|
+
{
|
|
62
|
+
"menu__list-item--deprecated": item.schema.deprecated,
|
|
63
|
+
},
|
|
64
|
+
"schema"
|
|
65
|
+
);
|
|
66
|
+
return {
|
|
67
|
+
type: "doc" as const,
|
|
68
|
+
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
69
|
+
label: (sidebar_label as string) ?? title ?? id,
|
|
70
|
+
customProps: customProps,
|
|
71
|
+
className: className ? className : undefined,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function groupByTags(
|
|
76
|
+
items: ApiMetadata[],
|
|
77
|
+
sidebarOptions: SidebarOptions,
|
|
78
|
+
options: APIOptions,
|
|
79
|
+
tags: TagObject[][],
|
|
80
|
+
docPath: string
|
|
81
|
+
): ProcessedSidebar {
|
|
82
|
+
let { outputDir, label, showSchemas } = options;
|
|
83
|
+
|
|
84
|
+
// Remove trailing slash before proceeding
|
|
85
|
+
outputDir = outputDir.replace(/\/$/, "");
|
|
86
|
+
|
|
87
|
+
const { sidebarCollapsed, sidebarCollapsible, categoryLinkSource } =
|
|
88
|
+
sidebarOptions;
|
|
89
|
+
|
|
90
|
+
const apiItems = items.filter(isApiItem) as ApiPageMetadata[];
|
|
91
|
+
const infoItems = items.filter(isInfoItem) as InfoPageMetadata[];
|
|
92
|
+
const schemaItems = items.filter(isSchemaItem) as SchemaPageMetadata[];
|
|
93
|
+
const intros = infoItems.map((item: any) => {
|
|
94
|
+
return {
|
|
95
|
+
id: item.id,
|
|
96
|
+
title: item.title,
|
|
97
|
+
description: item.description,
|
|
98
|
+
tags: item.info.tags,
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// TODO: make sure we only take the first tag
|
|
103
|
+
const operationTags = uniq(
|
|
104
|
+
apiItems
|
|
105
|
+
.flatMap((item) => item.api.tags)
|
|
106
|
+
.filter((item): item is string => !!item)
|
|
107
|
+
);
|
|
108
|
+
const schemaTags = uniq(
|
|
109
|
+
schemaItems
|
|
110
|
+
.flatMap((item) => item.schema["x-tags"])
|
|
111
|
+
.filter((item): item is string => !!item)
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// Combine globally defined tags with operation and schema tags
|
|
115
|
+
// Only include global tag if referenced in operation/schema tags
|
|
116
|
+
let apiTags: string[] = [];
|
|
117
|
+
tags.flat().forEach((tag) => {
|
|
118
|
+
// Should we also check x-displayName?
|
|
119
|
+
if (operationTags.includes(tag.name!) || schemaTags.includes(tag.name!)) {
|
|
120
|
+
apiTags.push(tag.name!);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (sidebarOptions.groupPathsBy !== "tagGroup") {
|
|
125
|
+
apiTags = uniq(apiTags.concat(operationTags, schemaTags));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const basePath = docPath
|
|
129
|
+
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
|
|
130
|
+
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
131
|
+
|
|
132
|
+
const createDocItemFnContext = {
|
|
133
|
+
sidebarOptions,
|
|
134
|
+
basePath,
|
|
135
|
+
};
|
|
136
|
+
const createDocItemFn =
|
|
137
|
+
sidebarOptions.sidebarGenerators?.createDocItem ?? createDocItem;
|
|
138
|
+
|
|
139
|
+
let rootIntroDoc = undefined;
|
|
140
|
+
if (infoItems.length === 1) {
|
|
141
|
+
const infoItem = infoItems[0];
|
|
142
|
+
const id = infoItem.id;
|
|
143
|
+
rootIntroDoc = {
|
|
144
|
+
type: "doc" as const,
|
|
145
|
+
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const tagged = apiTags
|
|
150
|
+
.map((tag) => {
|
|
151
|
+
// Map info object to tag
|
|
152
|
+
const taggedInfoObject = intros.find((i) =>
|
|
153
|
+
i.tags ? i.tags.find((t: any) => t.name === tag) : undefined
|
|
154
|
+
);
|
|
155
|
+
const tagObject = tags.flat().find(
|
|
156
|
+
(t) =>
|
|
157
|
+
tag === t.name && {
|
|
158
|
+
name: tag,
|
|
159
|
+
description: `${tag} Index`,
|
|
160
|
+
}
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
// TODO: perhaps move this into a getLinkConfig() function
|
|
164
|
+
// Default to no link config (spindowns only)
|
|
165
|
+
let linkConfig = undefined;
|
|
166
|
+
if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
|
|
167
|
+
linkConfig = {
|
|
168
|
+
type: "doc",
|
|
169
|
+
id:
|
|
170
|
+
basePath === "" || undefined
|
|
171
|
+
? `${taggedInfoObject.id}`
|
|
172
|
+
: `${basePath}/${taggedInfoObject.id}`,
|
|
173
|
+
} as SidebarItemCategoryLinkConfig;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// TODO: perhaps move this into a getLinkConfig() function
|
|
177
|
+
if (tagObject !== undefined && categoryLinkSource === "tag") {
|
|
178
|
+
const tagId = kebabCase(tagObject.name);
|
|
179
|
+
linkConfig = {
|
|
180
|
+
type: "doc",
|
|
181
|
+
id:
|
|
182
|
+
basePath === "" || undefined ? `${tagId}` : `${basePath}/${tagId}`,
|
|
183
|
+
} as SidebarItemCategoryLinkConfig;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (categoryLinkSource === "auto") {
|
|
187
|
+
linkConfig = {
|
|
188
|
+
type: "generated-index" as "generated-index",
|
|
189
|
+
title: tag,
|
|
190
|
+
slug: label
|
|
191
|
+
? posixPath(
|
|
192
|
+
path.join(
|
|
193
|
+
"/category",
|
|
194
|
+
basePath,
|
|
195
|
+
kebabCase(label),
|
|
196
|
+
kebabCase(tag)
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
: posixPath(path.join("/category", basePath, kebabCase(tag))),
|
|
200
|
+
} as SidebarItemCategoryLinkConfig;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const taggedApiItems = apiItems.filter(
|
|
204
|
+
(item) => !!item.api.tags?.includes(tag)
|
|
205
|
+
);
|
|
206
|
+
const taggedSchemaItems = schemaItems.filter(
|
|
207
|
+
(item) => !!item.schema["x-tags"]?.includes(tag)
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
return {
|
|
211
|
+
type: "category" as const,
|
|
212
|
+
label: tagObject?.["x-displayName"] ?? tag,
|
|
213
|
+
link: linkConfig,
|
|
214
|
+
collapsible: sidebarCollapsible,
|
|
215
|
+
collapsed: sidebarCollapsed,
|
|
216
|
+
items: [...taggedSchemaItems, ...taggedApiItems].map((item) =>
|
|
217
|
+
createDocItemFn(item, createDocItemFnContext)
|
|
218
|
+
),
|
|
219
|
+
};
|
|
220
|
+
})
|
|
221
|
+
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
222
|
+
|
|
223
|
+
// Handle items with no tag
|
|
224
|
+
const untaggedItems = apiItems
|
|
225
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
226
|
+
.map((item) => createDocItemFn(item, createDocItemFnContext));
|
|
227
|
+
let untagged: SidebarItemCategory[] = [];
|
|
228
|
+
if (untaggedItems.length > 0) {
|
|
229
|
+
untagged = [
|
|
230
|
+
{
|
|
231
|
+
type: "category" as const,
|
|
232
|
+
label: "UNTAGGED",
|
|
233
|
+
collapsible: sidebarCollapsible!,
|
|
234
|
+
collapsed: sidebarCollapsed!,
|
|
235
|
+
items: apiItems
|
|
236
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
237
|
+
.map((item) => createDocItemFn(item, createDocItemFnContext)),
|
|
238
|
+
},
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
let schemas: SidebarItemCategory[] = [];
|
|
243
|
+
if (showSchemas && schemaItems.length > 0) {
|
|
244
|
+
schemas = [
|
|
245
|
+
{
|
|
246
|
+
type: "category" as const,
|
|
247
|
+
label: "Schemas",
|
|
248
|
+
collapsible: sidebarCollapsible!,
|
|
249
|
+
collapsed: sidebarCollapsed!,
|
|
250
|
+
items: schemaItems
|
|
251
|
+
.filter(({ schema }) => !schema["x-tags"])
|
|
252
|
+
.map((item) => createDocItemFn(item, createDocItemFnContext)),
|
|
253
|
+
},
|
|
254
|
+
];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Shift root intro doc to top of sidebar
|
|
258
|
+
// TODO: Add input validation for categoryLinkSource options
|
|
259
|
+
if (rootIntroDoc && categoryLinkSource !== "info") {
|
|
260
|
+
tagged.unshift(rootIntroDoc as any);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return [...tagged, ...untagged, ...schemas];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export default function generateSidebarSlice(
|
|
267
|
+
sidebarOptions: SidebarOptions,
|
|
268
|
+
options: APIOptions,
|
|
269
|
+
api: ApiMetadata[],
|
|
270
|
+
tags: TagObject[][],
|
|
271
|
+
docPath: string,
|
|
272
|
+
tagGroups?: TagGroupObject[]
|
|
273
|
+
) {
|
|
274
|
+
let sidebarSlice: ProcessedSidebar = [];
|
|
275
|
+
|
|
276
|
+
if (sidebarOptions.groupPathsBy === "tagGroup") {
|
|
277
|
+
let schemasGroup: ProcessedSidebar = [];
|
|
278
|
+
tagGroups?.forEach((tagGroup) => {
|
|
279
|
+
//filter tags only included in group
|
|
280
|
+
const filteredTags: TagObject[] = [];
|
|
281
|
+
tags[0].forEach((tag) => {
|
|
282
|
+
if (tagGroup.tags.includes(tag.name as string)) {
|
|
283
|
+
filteredTags.push(tag);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const groupCategory = {
|
|
288
|
+
type: "category" as const,
|
|
289
|
+
label: tagGroup.name,
|
|
290
|
+
collapsible: true,
|
|
291
|
+
collapsed: true,
|
|
292
|
+
items: groupByTags(
|
|
293
|
+
api,
|
|
294
|
+
sidebarOptions,
|
|
295
|
+
options,
|
|
296
|
+
[filteredTags],
|
|
297
|
+
docPath
|
|
298
|
+
),
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
if (options.showSchemas) {
|
|
302
|
+
// For the first tagGroup, save the generated "Schemas" category for later.
|
|
303
|
+
if (schemasGroup.length === 0) {
|
|
304
|
+
schemasGroup = groupCategory.items?.filter(
|
|
305
|
+
(item) => item.type === "category" && item.label === "Schemas"
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
// Remove the "Schemas" category from every `groupCategory`.
|
|
309
|
+
groupCategory.items = groupCategory.items.filter((item) =>
|
|
310
|
+
"label" in item ? item.label !== "Schemas" : true
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
sidebarSlice.push(groupCategory as ProcessedSidebarItem);
|
|
314
|
+
});
|
|
315
|
+
// Add `schemasGroup` to the end of the sidebar.
|
|
316
|
+
sidebarSlice.push(...schemasGroup);
|
|
317
|
+
} else if (sidebarOptions.groupPathsBy === "tag") {
|
|
318
|
+
sidebarSlice = groupByTags(api, sidebarOptions, options, tags, docPath);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return sidebarSlice;
|
|
322
|
+
}
|
|
@@ -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
|
+
}
|