docusaurus-plugin-openapi-docs 0.0.0-345
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 +194 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +194 -0
- package/lib/markdown/createDeprecationNotice.d.ts +6 -0
- package/lib/markdown/createDeprecationNotice.js +19 -0
- package/lib/markdown/createDescription.d.ts +1 -0
- package/lib/markdown/createDescription.js +16 -0
- package/lib/markdown/createDetails.d.ts +2 -0
- package/lib/markdown/createDetails.js +18 -0
- package/lib/markdown/createDetailsSummary.d.ts +2 -0
- package/lib/markdown/createDetailsSummary.js +18 -0
- package/lib/markdown/createFullWidthTable.d.ts +2 -0
- package/lib/markdown/createFullWidthTable.js +18 -0
- package/lib/markdown/createParamsDetails.d.ts +7 -0
- package/lib/markdown/createParamsDetails.js +44 -0
- package/lib/markdown/createParamsTable.d.ts +7 -0
- package/lib/markdown/createParamsTable.js +80 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +6 -0
- package/lib/markdown/createRequestBodyDetails.js +14 -0
- package/lib/markdown/createRequestBodyTable.d.ts +6 -0
- package/lib/markdown/createRequestBodyTable.js +14 -0
- package/lib/markdown/createSchemaDetails.d.ts +14 -0
- package/lib/markdown/createSchemaDetails.js +241 -0
- package/lib/markdown/createSchemaTable.d.ts +14 -0
- package/lib/markdown/createSchemaTable.js +217 -0
- package/lib/markdown/createStatusCodes.d.ts +6 -0
- package/lib/markdown/createStatusCodes.js +47 -0
- package/lib/markdown/createVersionBadge.d.ts +1 -0
- package/lib/markdown/createVersionBadge.js +20 -0
- package/lib/markdown/index.d.ts +3 -0
- package/lib/markdown/index.js +43 -0
- package/lib/markdown/schema.d.ts +3 -0
- package/lib/markdown/schema.js +100 -0
- package/lib/markdown/schema.test.d.ts +1 -0
- package/lib/markdown/schema.test.js +171 -0
- package/lib/markdown/utils.d.ts +7 -0
- package/lib/markdown/utils.js +33 -0
- package/lib/openapi/createExample.d.ts +2 -0
- package/lib/openapi/createExample.js +113 -0
- package/lib/openapi/index.d.ts +1 -0
- package/lib/openapi/index.js +12 -0
- package/lib/openapi/openapi.d.ts +11 -0
- package/lib/openapi/openapi.js +231 -0
- package/lib/openapi/openapi.test.d.ts +1 -0
- package/lib/openapi/openapi.test.js +33 -0
- package/lib/openapi/types.d.ts +332 -0
- package/lib/openapi/types.js +8 -0
- package/lib/options.d.ts +4 -0
- package/lib/options.js +18 -0
- package/lib/sidebars/index.d.ts +3 -0
- package/lib/sidebars/index.js +89 -0
- package/lib/types.d.ts +68 -0
- package/lib/types.js +8 -0
- package/package.json +64 -0
- package/src/index.ts +244 -0
- package/src/markdown/createDeprecationNotice.ts +30 -0
- package/src/markdown/createDescription.ts +13 -0
- package/src/markdown/createDetails.ts +16 -0
- package/src/markdown/createDetailsSummary.ts +16 -0
- package/src/markdown/createFullWidthTable.ts +16 -0
- package/src/markdown/createParamsDetails.ts +53 -0
- package/src/markdown/createParamsTable.ts +102 -0
- package/src/markdown/createRequestBodyDetails.ts +17 -0
- package/src/markdown/createRequestBodyTable.ts +17 -0
- package/src/markdown/createSchemaDetails.ts +302 -0
- package/src/markdown/createSchemaTable.ts +275 -0
- package/src/markdown/createStatusCodes.ts +52 -0
- package/src/markdown/createVersionBadge.ts +18 -0
- package/src/markdown/index.ts +55 -0
- package/src/markdown/schema.test.ts +196 -0
- package/src/markdown/schema.ts +115 -0
- package/src/markdown/utils.ts +39 -0
- package/src/openapi/__fixtures__/examples/openapi.yaml +13 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +4 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +13 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +13 -0
- package/src/openapi/createExample.ts +143 -0
- package/src/openapi/index.ts +8 -0
- package/src/openapi/openapi.test.ts +37 -0
- package/src/openapi/openapi.ts +292 -0
- package/src/openapi/types.ts +431 -0
- package/src/openapi-to-postmanv2.d.ts +10 -0
- package/src/options.ts +20 -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 +121 -0
- package/src/types.ts +96 -0
- package/tsconfig.json +7 -0
- package/yarn-error.log +15179 -0
|
@@ -0,0 +1,121 @@
|
|
|
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 {
|
|
9
|
+
ProcessedSidebar,
|
|
10
|
+
SidebarItemDoc,
|
|
11
|
+
} from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
12
|
+
import clsx from "clsx";
|
|
13
|
+
import uniq from "lodash/uniq";
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
SidebarOptions,
|
|
17
|
+
APIOptions,
|
|
18
|
+
ApiPageMetadata,
|
|
19
|
+
ApiMetadata,
|
|
20
|
+
} from "../types";
|
|
21
|
+
|
|
22
|
+
function isApiItem(item: ApiMetadata): item is ApiMetadata {
|
|
23
|
+
return item.type === "api";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function groupByTags(
|
|
27
|
+
items: ApiPageMetadata[],
|
|
28
|
+
sidebarOptions: SidebarOptions,
|
|
29
|
+
options: APIOptions
|
|
30
|
+
): ProcessedSidebar {
|
|
31
|
+
// TODO: Figure out how to handle these
|
|
32
|
+
// const intros = items.filter(isInfoItem).map((item) => {
|
|
33
|
+
// return {
|
|
34
|
+
// type: "link" as const,
|
|
35
|
+
// label: item.title,
|
|
36
|
+
// href: item.permalink,
|
|
37
|
+
// docId: item.id,
|
|
38
|
+
// };
|
|
39
|
+
// });
|
|
40
|
+
|
|
41
|
+
const { outputDir } = options;
|
|
42
|
+
const { sidebarCollapsed, sidebarCollapsible, customProps } = sidebarOptions;
|
|
43
|
+
|
|
44
|
+
const apiItems = items.filter(isApiItem);
|
|
45
|
+
|
|
46
|
+
// TODO: make sure we only take the first tag
|
|
47
|
+
const tags = uniq(
|
|
48
|
+
apiItems
|
|
49
|
+
.flatMap((item) => item.api.tags)
|
|
50
|
+
.filter((item): item is string => !!item)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
// TODO: optimize this or make it a function
|
|
54
|
+
const basePath = outputDir
|
|
55
|
+
.slice(outputDir.indexOf("/", 1))
|
|
56
|
+
.replace(/^\/+/g, "");
|
|
57
|
+
|
|
58
|
+
function createDocItem(item: ApiPageMetadata): SidebarItemDoc {
|
|
59
|
+
const sidebar_label = item.frontMatter.sidebar_label;
|
|
60
|
+
const title = item.title;
|
|
61
|
+
const id = item.id;
|
|
62
|
+
return {
|
|
63
|
+
type: "doc" as const,
|
|
64
|
+
id: `${basePath}/${item.id}`,
|
|
65
|
+
label: (sidebar_label as string) ?? title ?? id,
|
|
66
|
+
customProps: customProps,
|
|
67
|
+
className: clsx(
|
|
68
|
+
{
|
|
69
|
+
"menu__list-item--deprecated": item.api.deprecated,
|
|
70
|
+
"api-method": !!item.api.method,
|
|
71
|
+
},
|
|
72
|
+
item.api.method
|
|
73
|
+
),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const tagged = tags
|
|
78
|
+
.map((tag) => {
|
|
79
|
+
return {
|
|
80
|
+
type: "category" as const,
|
|
81
|
+
label: tag,
|
|
82
|
+
collapsible: sidebarCollapsible,
|
|
83
|
+
collapsed: sidebarCollapsed,
|
|
84
|
+
items: apiItems
|
|
85
|
+
.filter((item) => !!item.api.tags?.includes(tag))
|
|
86
|
+
.map(createDocItem),
|
|
87
|
+
};
|
|
88
|
+
})
|
|
89
|
+
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
90
|
+
|
|
91
|
+
// const untagged = [
|
|
92
|
+
// // TODO: determine if needed and how
|
|
93
|
+
// {
|
|
94
|
+
// type: "category" as const,
|
|
95
|
+
// label: "UNTAGGED",
|
|
96
|
+
// // collapsible: options.sidebarCollapsible, TODO: add option
|
|
97
|
+
// // collapsed: options.sidebarCollapsed, TODO: add option
|
|
98
|
+
// items: apiItems
|
|
99
|
+
// //@ts-ignore
|
|
100
|
+
// .filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
101
|
+
// .map(createDocItem),
|
|
102
|
+
// },
|
|
103
|
+
// ];
|
|
104
|
+
return [...tagged];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export default function generateSidebarSlice(
|
|
108
|
+
sidebarOptions: SidebarOptions,
|
|
109
|
+
options: APIOptions,
|
|
110
|
+
api: ApiMetadata[]
|
|
111
|
+
) {
|
|
112
|
+
let sidebarSlice: ProcessedSidebar = [];
|
|
113
|
+
if (sidebarOptions.groupPathsBy === "tags") {
|
|
114
|
+
sidebarSlice = groupByTags(
|
|
115
|
+
api as ApiPageMetadata[],
|
|
116
|
+
sidebarOptions,
|
|
117
|
+
options
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
return sidebarSlice;
|
|
121
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
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 Request from "@paloaltonetworks/postman-collection";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
InfoObject,
|
|
12
|
+
OperationObject,
|
|
13
|
+
SecuritySchemeObject,
|
|
14
|
+
} from "./openapi/types";
|
|
15
|
+
|
|
16
|
+
export type {
|
|
17
|
+
PropSidebarItemCategory,
|
|
18
|
+
SidebarItemLink,
|
|
19
|
+
PropSidebar,
|
|
20
|
+
PropSidebarItem,
|
|
21
|
+
} from "@docusaurus/plugin-content-docs-types";
|
|
22
|
+
export interface PluginOptions {
|
|
23
|
+
id?: string;
|
|
24
|
+
config: {
|
|
25
|
+
[key: string]: APIOptions;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface APIOptions {
|
|
30
|
+
specPath: string;
|
|
31
|
+
outputDir: string;
|
|
32
|
+
template?: string;
|
|
33
|
+
sidebarOptions?: SidebarOptions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface LoadedContent {
|
|
37
|
+
loadedApi: ApiMetadata[];
|
|
38
|
+
// loadedDocs: DocPageMetadata[]; TODO: cleanup
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type ApiMetadata = ApiPageMetadata | InfoPageMetadata;
|
|
42
|
+
|
|
43
|
+
export interface ApiMetadataBase {
|
|
44
|
+
sidebar?: string;
|
|
45
|
+
previous?: ApiNavLink;
|
|
46
|
+
next?: ApiNavLink;
|
|
47
|
+
//
|
|
48
|
+
id: string; // TODO legacy versioned id => try to remove
|
|
49
|
+
unversionedId: string; // TODO new unversioned id => try to rename to "id"
|
|
50
|
+
title: string;
|
|
51
|
+
description: string;
|
|
52
|
+
source: string; // @site aliased source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"
|
|
53
|
+
sourceDirName: string; // relative to the versioned docs folder (can be ".") => "folder/subFolder/subSubFolder"
|
|
54
|
+
slug: string;
|
|
55
|
+
permalink: string;
|
|
56
|
+
sidebarPosition?: number;
|
|
57
|
+
frontMatter: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface ApiPageMetadata extends ApiMetadataBase {
|
|
61
|
+
json?: string;
|
|
62
|
+
type: "api";
|
|
63
|
+
api: ApiItem;
|
|
64
|
+
markdown?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface ApiItem extends OperationObject {
|
|
68
|
+
method: string; // get, post, put, etc...
|
|
69
|
+
path: string; // The endpoint path => "/api/getPets"
|
|
70
|
+
jsonRequestBodyExample: string;
|
|
71
|
+
securitySchemes?: {
|
|
72
|
+
[key: string]: SecuritySchemeObject;
|
|
73
|
+
};
|
|
74
|
+
postman?: Request;
|
|
75
|
+
info: InfoObject;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface InfoPageMetadata extends ApiMetadataBase {
|
|
79
|
+
type: "info";
|
|
80
|
+
info: ApiInfo;
|
|
81
|
+
markdown?: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export type ApiInfo = InfoObject;
|
|
85
|
+
|
|
86
|
+
export interface ApiNavLink {
|
|
87
|
+
title: string;
|
|
88
|
+
permalink: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface SidebarOptions {
|
|
92
|
+
groupPathsBy?: string;
|
|
93
|
+
customProps?: { [key: string]: unknown };
|
|
94
|
+
sidebarCollapsible?: boolean;
|
|
95
|
+
sidebarCollapsed?: boolean;
|
|
96
|
+
}
|