docusaurus-plugin-openapi-docs 0.0.0-beta.691 → 0.0.0-beta.719
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 +2 -0
- package/lib/index.js +75 -19
- package/lib/markdown/createAuthentication.js +4 -3
- package/lib/markdown/createCallbacks.d.ts +6 -0
- package/lib/markdown/createCallbacks.js +78 -0
- package/lib/markdown/createDeprecationNotice.js +6 -3
- package/lib/markdown/createDescription.js +1 -9
- package/lib/markdown/createHeading.js +4 -5
- package/lib/markdown/createRequestBodyDetails.d.ts +1 -1
- package/lib/markdown/createRequestHeader.d.ts +1 -1
- package/lib/markdown/createRequestHeader.js +10 -1
- package/lib/markdown/createSchema.d.ts +1 -1
- package/lib/markdown/createSchema.js +23 -9
- package/lib/markdown/createSchema.test.js +2 -2
- package/lib/markdown/createStatusCodes.d.ts +3 -1
- package/lib/markdown/createStatusCodes.js +8 -6
- package/lib/markdown/createVersionBadge.js +1 -1
- package/lib/markdown/index.d.ts +3 -2
- package/lib/markdown/index.js +31 -6
- package/lib/markdown/schema.js +3 -0
- package/lib/markdown/utils.d.ts +9 -3
- package/lib/markdown/utils.js +29 -4
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +60 -7
- package/lib/openapi/openapi.test.js +2 -0
- package/lib/openapi/types.d.ts +18 -13
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +1 -1
- package/lib/openapi/utils/services/OpenAPIParser.js +2 -1
- package/lib/openapi/utils/services/RedocNormalizedOptions.js +49 -49
- package/lib/openapi/utils/types/index.d.ts +1 -1
- package/lib/openapi/utils/types/open-api.d.ts +4 -4
- package/lib/openapi/utils/types.d.ts +5 -5
- package/lib/openapi/utils/utils/openapi.js +1 -1
- package/lib/options.js +2 -1
- package/lib/sidebars/index.d.ts +2 -2
- package/lib/sidebars/index.js +49 -9
- package/lib/types.d.ts +16 -3
- package/package.json +11 -9
- package/src/index.ts +134 -21
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +4 -28
- package/src/markdown/createAuthentication.ts +11 -6
- package/src/markdown/createCallbacks.ts +101 -0
- package/src/markdown/createContactInfo.ts +1 -1
- package/src/markdown/createDeprecationNotice.ts +2 -2
- package/src/markdown/createDescription.ts +2 -10
- package/src/markdown/createHeading.ts +10 -7
- package/src/markdown/createLicense.ts +1 -1
- package/src/markdown/createLogo.ts +1 -1
- package/src/markdown/createParamsDetails.ts +1 -1
- package/src/markdown/createRequestBodyDetails.ts +2 -2
- package/src/markdown/createRequestHeader.ts +15 -1
- package/src/markdown/createRequestSchema.ts +1 -1
- package/src/markdown/createResponseSchema.ts +1 -1
- package/src/markdown/createSchema.test.ts +6 -4
- package/src/markdown/createSchema.ts +32 -19
- package/src/markdown/createStatusCodes.ts +11 -7
- package/src/markdown/createVersionBadge.ts +8 -4
- package/src/markdown/index.ts +45 -14
- package/src/markdown/schema.ts +4 -0
- package/src/markdown/utils.ts +37 -4
- package/src/openapi/__fixtures__/examples/openapi.yaml +29 -0
- package/src/openapi/createRequestExample.ts +1 -1
- package/src/openapi/createResponseExample.ts +1 -1
- package/src/openapi/openapi.test.ts +3 -0
- package/src/openapi/openapi.ts +77 -9
- package/src/openapi/types.ts +6 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
- package/src/openapi/utils/services/OpenAPIParser.ts +3 -3
- package/src/openapi/utils/utils/openapi.ts +8 -8
- package/src/options.ts +2 -1
- package/src/sidebars/index.ts +70 -15
- package/src/types.ts +21 -1
package/lib/sidebars/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
2
|
-
import { TagObject } from "../openapi/types";
|
|
2
|
+
import { TagGroupObject, TagObject } from "../openapi/types";
|
|
3
3
|
import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
|
|
4
|
-
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[][], docPath: string): ProcessedSidebar;
|
|
4
|
+
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[][], docPath: string, tagGroups?: TagGroupObject[]): ProcessedSidebar;
|
package/lib/sidebars/index.js
CHANGED
|
@@ -20,6 +20,9 @@ function isApiItem(item) {
|
|
|
20
20
|
function isInfoItem(item) {
|
|
21
21
|
return item.type === "info";
|
|
22
22
|
}
|
|
23
|
+
function isSchemaItem(item) {
|
|
24
|
+
return item.type === "schema";
|
|
25
|
+
}
|
|
23
26
|
function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
24
27
|
let { outputDir, label } = options;
|
|
25
28
|
// Remove trailing slash before proceeding
|
|
@@ -27,6 +30,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
27
30
|
const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
|
|
28
31
|
const apiItems = items.filter(isApiItem);
|
|
29
32
|
const infoItems = items.filter(isInfoItem);
|
|
33
|
+
const schemaItems = items.filter(isSchemaItem);
|
|
30
34
|
const intros = infoItems.map((item) => {
|
|
31
35
|
return {
|
|
32
36
|
id: item.id,
|
|
@@ -56,16 +60,21 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
56
60
|
var _a, _b;
|
|
57
61
|
const sidebar_label = item.frontMatter.sidebar_label;
|
|
58
62
|
const title = item.title;
|
|
59
|
-
const id = item.id;
|
|
63
|
+
const id = item.type === "schema" ? `schemas/${item.id}` : item.id;
|
|
64
|
+
const className = item.type === "api"
|
|
65
|
+
? (0, clsx_1.default)({
|
|
66
|
+
"menu__list-item--deprecated": item.api.deprecated,
|
|
67
|
+
"api-method": !!item.api.method,
|
|
68
|
+
}, item.api.method)
|
|
69
|
+
: (0, clsx_1.default)({
|
|
70
|
+
"menu__list-item--deprecated": item.schema.deprecated,
|
|
71
|
+
});
|
|
60
72
|
return {
|
|
61
73
|
type: "doc",
|
|
62
|
-
id: basePath === "" || undefined ? `${
|
|
74
|
+
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
63
75
|
label: (_b = (_a = sidebar_label) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : id,
|
|
64
76
|
customProps: customProps,
|
|
65
|
-
className:
|
|
66
|
-
"menu__list-item--deprecated": item.api.deprecated,
|
|
67
|
-
"api-method": !!item.api.method,
|
|
68
|
-
}, item.api.method),
|
|
77
|
+
className: className ? className : undefined,
|
|
69
78
|
};
|
|
70
79
|
}
|
|
71
80
|
let rootIntroDoc = undefined;
|
|
@@ -147,16 +156,47 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
147
156
|
},
|
|
148
157
|
];
|
|
149
158
|
}
|
|
159
|
+
let schemas = [];
|
|
160
|
+
if (schemaItems.length > 0) {
|
|
161
|
+
schemas = [
|
|
162
|
+
{
|
|
163
|
+
type: "category",
|
|
164
|
+
label: "Schemas",
|
|
165
|
+
collapsible: sidebarCollapsible,
|
|
166
|
+
collapsed: sidebarCollapsed,
|
|
167
|
+
items: schemaItems.map(createDocItem),
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
}
|
|
150
171
|
// Shift root intro doc to top of sidebar
|
|
151
172
|
// TODO: Add input validation for categoryLinkSource options
|
|
152
173
|
if (rootIntroDoc && categoryLinkSource !== "info") {
|
|
153
174
|
tagged.unshift(rootIntroDoc);
|
|
154
175
|
}
|
|
155
|
-
return [...tagged, ...untagged];
|
|
176
|
+
return [...tagged, ...untagged, ...schemas];
|
|
156
177
|
}
|
|
157
|
-
function generateSidebarSlice(sidebarOptions, options, api, tags, docPath) {
|
|
178
|
+
function generateSidebarSlice(sidebarOptions, options, api, tags, docPath, tagGroups) {
|
|
158
179
|
let sidebarSlice = [];
|
|
159
|
-
if (sidebarOptions.groupPathsBy === "
|
|
180
|
+
if (sidebarOptions.groupPathsBy === "tagGroup") {
|
|
181
|
+
tagGroups === null || tagGroups === void 0 ? void 0 : tagGroups.forEach((tagGroup) => {
|
|
182
|
+
//filter tags only included in group
|
|
183
|
+
const filteredTags = [];
|
|
184
|
+
tags[0].forEach((tag) => {
|
|
185
|
+
if (tagGroup.tags.includes(tag.name)) {
|
|
186
|
+
filteredTags.push(tag);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
const groupCategory = {
|
|
190
|
+
type: "category",
|
|
191
|
+
label: tagGroup.name,
|
|
192
|
+
collapsible: true,
|
|
193
|
+
collapsed: true,
|
|
194
|
+
items: groupByTags(api, sidebarOptions, options, [filteredTags], docPath),
|
|
195
|
+
};
|
|
196
|
+
sidebarSlice.push(groupCategory);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else if (sidebarOptions.groupPathsBy === "tag") {
|
|
160
200
|
sidebarSlice = groupByTags(api, sidebarOptions, options, tags, docPath);
|
|
161
201
|
}
|
|
162
202
|
return sidebarSlice;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type Request from "@paloaltonetworks/postman-collection";
|
|
2
|
-
import { InfoObject, OperationObject, SecuritySchemeObject, TagObject } from "./openapi/types";
|
|
2
|
+
import { InfoObject, OperationObject, SchemaObject, SecuritySchemeObject, TagObject } from "./openapi/types";
|
|
3
3
|
export type { PropSidebarItemCategory, SidebarItemLink, PropSidebar, PropSidebarItem, } from "@docusaurus/plugin-content-docs-types";
|
|
4
4
|
export interface PluginOptions {
|
|
5
5
|
id?: string;
|
|
@@ -24,11 +24,13 @@ export interface APIOptions {
|
|
|
24
24
|
};
|
|
25
25
|
proxy?: string;
|
|
26
26
|
markdownGenerators?: MarkdownGenerator;
|
|
27
|
+
showSchemas?: boolean;
|
|
27
28
|
}
|
|
28
29
|
export interface MarkdownGenerator {
|
|
29
30
|
createApiPageMD?: (pageData: ApiPageMetadata) => string;
|
|
30
31
|
createInfoPageMD?: (pageData: InfoPageMetadata) => string;
|
|
31
32
|
createTagPageMD?: (pageData: TagPageMetadata) => string;
|
|
33
|
+
createSchemaPageMD?: (pageData: SchemaPageMetadata) => string;
|
|
32
34
|
}
|
|
33
35
|
export interface SidebarOptions {
|
|
34
36
|
groupPathsBy?: string;
|
|
@@ -48,7 +50,7 @@ export interface APIVersionOptions {
|
|
|
48
50
|
export interface LoadedContent {
|
|
49
51
|
loadedApi: ApiMetadata[];
|
|
50
52
|
}
|
|
51
|
-
export
|
|
53
|
+
export type ApiMetadata = ApiPageMetadata | InfoPageMetadata | TagPageMetadata | SchemaPageMetadata;
|
|
52
54
|
export interface ApiMetadataBase {
|
|
53
55
|
sidebar?: string;
|
|
54
56
|
previous?: ApiNavLink;
|
|
@@ -100,7 +102,18 @@ export interface TagPageMetadata extends ApiMetadataBase {
|
|
|
100
102
|
tag: TagObject;
|
|
101
103
|
markdown?: string;
|
|
102
104
|
}
|
|
103
|
-
export
|
|
105
|
+
export interface SchemaPageMetadata extends ApiMetadataBase {
|
|
106
|
+
type: "schema";
|
|
107
|
+
schema: SchemaObject;
|
|
108
|
+
markdown?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface TagGroupPageMetadata extends ApiMetadataBase {
|
|
111
|
+
type: "tagGroup";
|
|
112
|
+
name: string;
|
|
113
|
+
tags: TagObject[];
|
|
114
|
+
markdown?: string;
|
|
115
|
+
}
|
|
116
|
+
export type ApiInfo = InfoObject;
|
|
104
117
|
export interface ApiNavLink {
|
|
105
118
|
title: string;
|
|
106
119
|
permalink: string;
|
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-beta.
|
|
4
|
+
"version": "0.0.0-beta.719",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -28,26 +28,28 @@
|
|
|
28
28
|
"watch": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@docusaurus/types": "^3.0.
|
|
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
|
-
"@apidevtools/json-schema-ref-parser": "^
|
|
40
|
-
"@docusaurus/plugin-content-docs": "^3.0.
|
|
41
|
-
"@docusaurus/utils": "^3.0.
|
|
42
|
-
"@docusaurus/utils-validation": "^3.0.
|
|
40
|
+
"@apidevtools/json-schema-ref-parser": "^11.5.4",
|
|
41
|
+
"@docusaurus/plugin-content-docs": "^3.0.1",
|
|
42
|
+
"@docusaurus/utils": "^3.0.1",
|
|
43
|
+
"@docusaurus/utils-validation": "^3.0.1",
|
|
43
44
|
"@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
|
|
44
45
|
"@paloaltonetworks/postman-collection": "^4.1.0",
|
|
45
|
-
"@redocly/openapi-core": "^1.
|
|
46
|
+
"@redocly/openapi-core": "^1.10.5",
|
|
46
47
|
"chalk": "^4.1.2",
|
|
47
48
|
"clsx": "^1.1.1",
|
|
48
49
|
"fs-extra": "^9.0.1",
|
|
49
50
|
"json-pointer": "^0.6.2",
|
|
50
51
|
"json-schema-merge-allof": "^0.8.1",
|
|
52
|
+
"json5": "^2.2.3",
|
|
51
53
|
"lodash": "^4.17.20",
|
|
52
54
|
"mustache": "^4.2.0",
|
|
53
55
|
"slugify": "^1.6.5",
|
|
@@ -60,5 +62,5 @@
|
|
|
60
62
|
"engines": {
|
|
61
63
|
"node": ">=14"
|
|
62
64
|
},
|
|
63
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "a39c6c416b43621bc5f7f16e739d75fa54c425a8"
|
|
64
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,13 +12,28 @@ 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
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
createApiPageMD,
|
|
20
|
+
createInfoPageMD,
|
|
21
|
+
createSchemaPageMD,
|
|
22
|
+
createTagPageMD,
|
|
23
|
+
} from "./markdown";
|
|
18
24
|
import { readOpenapiFiles, processOpenapiFiles } from "./openapi";
|
|
19
25
|
import { OptionsSchema } from "./options";
|
|
20
26
|
import generateSidebarSlice from "./sidebars";
|
|
21
|
-
import type {
|
|
27
|
+
import type {
|
|
28
|
+
PluginOptions,
|
|
29
|
+
LoadedContent,
|
|
30
|
+
APIOptions,
|
|
31
|
+
ApiMetadata,
|
|
32
|
+
ApiPageMetadata,
|
|
33
|
+
InfoPageMetadata,
|
|
34
|
+
TagPageMetadata,
|
|
35
|
+
SchemaPageMetadata,
|
|
36
|
+
} from "./types";
|
|
22
37
|
|
|
23
38
|
export function isURL(str: string): boolean {
|
|
24
39
|
return /^(https?:)\/\//m.test(str);
|
|
@@ -117,7 +132,7 @@ export default function pluginOpenAPIDocs(
|
|
|
117
132
|
|
|
118
133
|
try {
|
|
119
134
|
const openapiFiles = await readOpenapiFiles(contentPath);
|
|
120
|
-
const [loadedApi, tags] = await processOpenapiFiles(
|
|
135
|
+
const [loadedApi, tags, tagGroups] = await processOpenapiFiles(
|
|
121
136
|
openapiFiles,
|
|
122
137
|
options,
|
|
123
138
|
sidebarOptions!
|
|
@@ -141,24 +156,30 @@ export default function pluginOpenAPIDocs(
|
|
|
141
156
|
options,
|
|
142
157
|
loadedApi,
|
|
143
158
|
tags,
|
|
144
|
-
docPath
|
|
159
|
+
docPath,
|
|
160
|
+
tagGroups
|
|
145
161
|
);
|
|
146
162
|
|
|
147
|
-
|
|
163
|
+
let sidebarSliceTemplate = `import type { SidebarsConfig } from "@docusaurus/plugin-content-docs";\n\n`;
|
|
164
|
+
sidebarSliceTemplate += `const sidebar: SidebarsConfig = {{{slice}}};\n\n`;
|
|
165
|
+
sidebarSliceTemplate += `export default sidebar.apisidebar;\n`;
|
|
148
166
|
|
|
149
167
|
const view = render(sidebarSliceTemplate, {
|
|
150
|
-
slice:
|
|
168
|
+
slice: JSON5.stringify(
|
|
169
|
+
{ apisidebar: sidebarSlice },
|
|
170
|
+
{ space: 2, quote: '"' }
|
|
171
|
+
),
|
|
151
172
|
});
|
|
152
173
|
|
|
153
|
-
if (!fs.existsSync(`${outputDir}/sidebar.
|
|
174
|
+
if (!fs.existsSync(`${outputDir}/sidebar.ts`)) {
|
|
154
175
|
try {
|
|
155
|
-
fs.writeFileSync(`${outputDir}/sidebar.
|
|
176
|
+
fs.writeFileSync(`${outputDir}/sidebar.ts`, view, "utf8");
|
|
156
177
|
console.log(
|
|
157
|
-
chalk.green(`Successfully created "${outputDir}/sidebar.
|
|
178
|
+
chalk.green(`Successfully created "${outputDir}/sidebar.ts"`)
|
|
158
179
|
);
|
|
159
180
|
} catch (err) {
|
|
160
181
|
console.error(
|
|
161
|
-
chalk.red(`Failed to write "${outputDir}/sidebar.
|
|
182
|
+
chalk.red(`Failed to write "${outputDir}/sidebar.ts"`),
|
|
162
183
|
chalk.yellow(err)
|
|
163
184
|
);
|
|
164
185
|
}
|
|
@@ -244,12 +265,43 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
244
265
|
\`\`\`
|
|
245
266
|
`;
|
|
246
267
|
|
|
268
|
+
const schemaMdTemplate = `---
|
|
269
|
+
id: {{{id}}}
|
|
270
|
+
title: "{{{title}}}"
|
|
271
|
+
description: "{{{frontMatter.description}}}"
|
|
272
|
+
sidebar_label: "{{{title}}}"
|
|
273
|
+
hide_title: true
|
|
274
|
+
schema: true
|
|
275
|
+
custom_edit_url: null
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
{{{markdown}}}
|
|
279
|
+
`;
|
|
280
|
+
|
|
247
281
|
const apiPageGenerator =
|
|
248
282
|
markdownGenerators?.createApiPageMD ?? createApiPageMD;
|
|
249
283
|
const infoPageGenerator =
|
|
250
284
|
markdownGenerators?.createInfoPageMD ?? createInfoPageMD;
|
|
251
285
|
const tagPageGenerator =
|
|
252
286
|
markdownGenerators?.createTagPageMD ?? createTagPageMD;
|
|
287
|
+
const schemaPageGenerator =
|
|
288
|
+
markdownGenerators?.createSchemaPageMD ?? createSchemaPageMD;
|
|
289
|
+
|
|
290
|
+
const pageGeneratorByType: {
|
|
291
|
+
[key in ApiMetadata["type"]]: (
|
|
292
|
+
pageData: {
|
|
293
|
+
api: ApiPageMetadata;
|
|
294
|
+
info: InfoPageMetadata;
|
|
295
|
+
tag: TagPageMetadata;
|
|
296
|
+
schema: SchemaPageMetadata;
|
|
297
|
+
}[key]
|
|
298
|
+
) => string;
|
|
299
|
+
} = {
|
|
300
|
+
api: apiPageGenerator,
|
|
301
|
+
info: infoPageGenerator,
|
|
302
|
+
tag: tagPageGenerator,
|
|
303
|
+
schema: schemaPageGenerator,
|
|
304
|
+
};
|
|
253
305
|
|
|
254
306
|
loadedApi.map(async (item) => {
|
|
255
307
|
if (item.type === "info") {
|
|
@@ -257,12 +309,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
257
309
|
item.downloadUrl = downloadUrl;
|
|
258
310
|
}
|
|
259
311
|
}
|
|
260
|
-
const markdown =
|
|
261
|
-
item.type === "api"
|
|
262
|
-
? apiPageGenerator(item)
|
|
263
|
-
: item.type === "info"
|
|
264
|
-
? infoPageGenerator(item)
|
|
265
|
-
: tagPageGenerator(item);
|
|
312
|
+
const markdown = pageGeneratorByType[item.type](item as any);
|
|
266
313
|
item.markdown = markdown;
|
|
267
314
|
if (item.type === "api") {
|
|
268
315
|
// opportunity to compress JSON
|
|
@@ -363,6 +410,49 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
363
410
|
}
|
|
364
411
|
}
|
|
365
412
|
}
|
|
413
|
+
|
|
414
|
+
if (item.type === "schema") {
|
|
415
|
+
if (!fs.existsSync(`${outputDir}/schemas/${item.id}.schema.mdx`)) {
|
|
416
|
+
if (!fs.existsSync(`${outputDir}/schemas`)) {
|
|
417
|
+
try {
|
|
418
|
+
fs.mkdirSync(`${outputDir}/schemas`, { recursive: true });
|
|
419
|
+
console.log(
|
|
420
|
+
chalk.green(`Successfully created "${outputDir}/schemas"`)
|
|
421
|
+
);
|
|
422
|
+
} catch (err) {
|
|
423
|
+
console.error(
|
|
424
|
+
chalk.red(`Failed to create "${outputDir}/schemas"`),
|
|
425
|
+
chalk.yellow(err)
|
|
426
|
+
);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
try {
|
|
430
|
+
// kebabCase(arg) returns 0-length string when arg is undefined
|
|
431
|
+
if (item.id.length === 0) {
|
|
432
|
+
throw Error("Schema must have title defined");
|
|
433
|
+
}
|
|
434
|
+
// eslint-disable-next-line testing-library/render-result-naming-convention
|
|
435
|
+
const schemaView = render(schemaMdTemplate, item);
|
|
436
|
+
fs.writeFileSync(
|
|
437
|
+
`${outputDir}/schemas/${item.id}.schema.mdx`,
|
|
438
|
+
schemaView,
|
|
439
|
+
"utf8"
|
|
440
|
+
);
|
|
441
|
+
console.log(
|
|
442
|
+
chalk.green(
|
|
443
|
+
`Successfully created "${outputDir}/${item.id}.schema.mdx"`
|
|
444
|
+
)
|
|
445
|
+
);
|
|
446
|
+
} catch (err) {
|
|
447
|
+
console.error(
|
|
448
|
+
chalk.red(
|
|
449
|
+
`Failed to write "${outputDir}/${item.id}.schema.mdx"`
|
|
450
|
+
),
|
|
451
|
+
chalk.yellow(err)
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
366
456
|
return;
|
|
367
457
|
});
|
|
368
458
|
|
|
@@ -380,6 +470,10 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
380
470
|
cwd: path.resolve(apiDir),
|
|
381
471
|
deep: 1,
|
|
382
472
|
});
|
|
473
|
+
const schemaMdxFiles = await Globby(["*.schema.mdx"], {
|
|
474
|
+
cwd: path.resolve(apiDir, "schemas"),
|
|
475
|
+
deep: 1,
|
|
476
|
+
});
|
|
383
477
|
const sidebarFile = await Globby(["sidebar.js"], {
|
|
384
478
|
cwd: path.resolve(apiDir),
|
|
385
479
|
deep: 1,
|
|
@@ -397,6 +491,21 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
397
491
|
})
|
|
398
492
|
);
|
|
399
493
|
|
|
494
|
+
schemaMdxFiles.map((mdx) =>
|
|
495
|
+
fs.unlink(`${apiDir}/schemas/${mdx}`, (err) => {
|
|
496
|
+
if (err) {
|
|
497
|
+
console.error(
|
|
498
|
+
chalk.red(`Cleanup failed for "${apiDir}/schemas/${mdx}"`),
|
|
499
|
+
chalk.yellow(err)
|
|
500
|
+
);
|
|
501
|
+
} else {
|
|
502
|
+
console.log(
|
|
503
|
+
chalk.green(`Cleanup succeeded for "${apiDir}/schemas/${mdx}"`)
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
})
|
|
507
|
+
);
|
|
508
|
+
|
|
400
509
|
sidebarFile.map((sidebar) =>
|
|
401
510
|
fs.unlink(`${apiDir}/${sidebar}`, (err) => {
|
|
402
511
|
if (err) {
|
|
@@ -425,7 +534,11 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
425
534
|
|
|
426
535
|
const versionsJson = JSON.stringify(versionsArray, null, 2);
|
|
427
536
|
try {
|
|
428
|
-
fs.writeFileSync(
|
|
537
|
+
fs.writeFileSync(
|
|
538
|
+
`${outputDir}/versions.json`,
|
|
539
|
+
versionsJson + "\n",
|
|
540
|
+
"utf8"
|
|
541
|
+
);
|
|
429
542
|
console.log(
|
|
430
543
|
chalk.green(`Successfully created "${outputDir}/versions.json"`)
|
|
431
544
|
);
|
|
@@ -461,7 +574,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
461
574
|
cli
|
|
462
575
|
.command(`gen-api-docs`)
|
|
463
576
|
.description(
|
|
464
|
-
`Generates OpenAPI docs in MDX file format and sidebar.
|
|
577
|
+
`Generates OpenAPI docs in MDX file format and sidebar.ts (if enabled).`
|
|
465
578
|
)
|
|
466
579
|
.usage("<id>")
|
|
467
580
|
.arguments("<id>")
|
|
@@ -519,7 +632,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
519
632
|
cli
|
|
520
633
|
.command(`gen-api-docs:version`)
|
|
521
634
|
.description(
|
|
522
|
-
`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.
|
|
635
|
+
`Generates versioned OpenAPI docs in MDX file format, versions.js and sidebar.ts (if enabled).`
|
|
523
636
|
)
|
|
524
637
|
.usage("<id:version>")
|
|
525
638
|
.arguments("<id:version>")
|
|
@@ -610,7 +723,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
610
723
|
cli
|
|
611
724
|
.command(`clean-api-docs`)
|
|
612
725
|
.description(
|
|
613
|
-
`Clears the generated OpenAPI docs MDX files and sidebar.
|
|
726
|
+
`Clears the generated OpenAPI docs MDX files and sidebar.ts (if enabled).`
|
|
614
727
|
)
|
|
615
728
|
.usage("<id>")
|
|
616
729
|
.arguments("<id>")
|
|
@@ -661,7 +774,7 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
661
774
|
cli
|
|
662
775
|
.command(`clean-api-docs:version`)
|
|
663
776
|
.description(
|
|
664
|
-
`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.
|
|
777
|
+
`Clears the versioned, generated OpenAPI docs MDX files, versions.json and sidebar.ts (if enabled).`
|
|
665
778
|
)
|
|
666
779
|
.usage("<id:version>")
|
|
667
780
|
.arguments("<id:version>")
|
|
@@ -35,13 +35,7 @@ Array [
|
|
|
35
35
|
Array [
|
|
36
36
|
</div>
|
|
37
37
|
</li>
|
|
38
|
-
<div
|
|
39
|
-
style={{
|
|
40
|
-
marginTop: \\".5rem\\",
|
|
41
|
-
marginBottom: \\".5rem\\",
|
|
42
|
-
marginLeft: \\"1rem\\",
|
|
43
|
-
}}
|
|
44
|
-
>
|
|
38
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
45
39
|
string
|
|
46
40
|
</div>
|
|
47
41
|
<li>
|
|
@@ -57,35 +51,17 @@ Array [
|
|
|
57
51
|
</li>
|
|
58
52
|
</TabItem>
|
|
59
53
|
<TabItem label={\\"MOD3\\"} value={\\"2-item-properties\\"}>
|
|
60
|
-
<div
|
|
61
|
-
style={{
|
|
62
|
-
marginTop: \\".5rem\\",
|
|
63
|
-
marginBottom: \\".5rem\\",
|
|
64
|
-
marginLeft: \\"1rem\\",
|
|
65
|
-
}}
|
|
66
|
-
>
|
|
54
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
67
55
|
boolean
|
|
68
56
|
</div>
|
|
69
57
|
</TabItem>
|
|
70
58
|
<TabItem label={\\"MOD4\\"} value={\\"3-item-properties\\"}>
|
|
71
|
-
<div
|
|
72
|
-
style={{
|
|
73
|
-
marginTop: \\".5rem\\",
|
|
74
|
-
marginBottom: \\".5rem\\",
|
|
75
|
-
marginLeft: \\"1rem\\",
|
|
76
|
-
}}
|
|
77
|
-
>
|
|
59
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
78
60
|
number
|
|
79
61
|
</div>
|
|
80
62
|
</TabItem>
|
|
81
63
|
<TabItem label={\\"MOD5\\"} value={\\"4-item-properties\\"}>
|
|
82
|
-
<div
|
|
83
|
-
style={{
|
|
84
|
-
marginTop: \\".5rem\\",
|
|
85
|
-
marginBottom: \\".5rem\\",
|
|
86
|
-
marginLeft: \\"1rem\\",
|
|
87
|
-
}}
|
|
88
|
-
>
|
|
64
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
89
65
|
string
|
|
90
66
|
</div>
|
|
91
67
|
</TabItem>
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { OAuthFlowObject, SecuritySchemeObject } from "../openapi/types";
|
|
9
8
|
import { createDescription } from "./createDescription";
|
|
10
9
|
import { create, guard } from "./utils";
|
|
10
|
+
import { OAuthFlowObject, SecuritySchemeObject } from "../openapi/types";
|
|
11
11
|
|
|
12
12
|
export function createAuthentication(securitySchemes: SecuritySchemeObject) {
|
|
13
13
|
if (!securitySchemes || !Object.keys(securitySchemes).length) return "";
|
|
@@ -167,11 +167,16 @@ export function createAuthentication(securitySchemes: SecuritySchemeObject) {
|
|
|
167
167
|
|
|
168
168
|
return create("div", {
|
|
169
169
|
children: [
|
|
170
|
-
create(
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
170
|
+
create(
|
|
171
|
+
"Heading",
|
|
172
|
+
{
|
|
173
|
+
children: "Authentication",
|
|
174
|
+
id: "authentication",
|
|
175
|
+
as: "h2",
|
|
176
|
+
className: "openapi-tabs__heading",
|
|
177
|
+
},
|
|
178
|
+
{ inline: true }
|
|
179
|
+
),
|
|
175
180
|
create("SchemaTabs", {
|
|
176
181
|
className: "openapi-tabs__security-schemes",
|
|
177
182
|
children: Object.entries(securitySchemes).map(
|
|
@@ -0,0 +1,101 @@
|
|
|
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 { createDescription } from "./createDescription";
|
|
9
|
+
import { createMethodEndpoint } from "./createMethodEndpoint";
|
|
10
|
+
import { createRequestBodyDetails } from "./createRequestBodyDetails";
|
|
11
|
+
import { createStatusCodes } from "./createStatusCodes";
|
|
12
|
+
import { create } from "./utils";
|
|
13
|
+
import { MediaTypeObject } from "../openapi/types";
|
|
14
|
+
import { ApiItem } from "../types";
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
callbacks: ApiItem["callbacks"];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface RequestBodyProps {
|
|
21
|
+
title: string;
|
|
22
|
+
body: {
|
|
23
|
+
content?: {
|
|
24
|
+
[key: string]: MediaTypeObject;
|
|
25
|
+
};
|
|
26
|
+
description?: string;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function createCallbacks({ callbacks }: Props) {
|
|
32
|
+
if (callbacks === undefined) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const callbacksNames = Object.keys(callbacks);
|
|
37
|
+
if (callbacksNames.length === 0) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return create("div", {
|
|
42
|
+
children: [
|
|
43
|
+
create("div", {
|
|
44
|
+
className: "openapi__divider",
|
|
45
|
+
}),
|
|
46
|
+
create(
|
|
47
|
+
"Heading",
|
|
48
|
+
{
|
|
49
|
+
children: "Callbacks",
|
|
50
|
+
id: "callbacks",
|
|
51
|
+
as: "h2",
|
|
52
|
+
className: "openapi-tabs__heading",
|
|
53
|
+
},
|
|
54
|
+
{ inline: true }
|
|
55
|
+
),
|
|
56
|
+
create("OperationTabs", {
|
|
57
|
+
className: "openapi-tabs__operation",
|
|
58
|
+
children: callbacksNames.flatMap((name) => {
|
|
59
|
+
const path = Object.keys(callbacks[name])[0];
|
|
60
|
+
const methods = new Map([
|
|
61
|
+
["delete", callbacks[name][path].delete],
|
|
62
|
+
["get", callbacks[name][path].get],
|
|
63
|
+
["head", callbacks[name][path].head],
|
|
64
|
+
["options", callbacks[name][path].options],
|
|
65
|
+
["patch", callbacks[name][path].patch],
|
|
66
|
+
["post", callbacks[name][path].post],
|
|
67
|
+
["put", callbacks[name][path].put],
|
|
68
|
+
["trace", callbacks[name][path].trace],
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
return Array.from(methods).flatMap(([method, operationObject]) => {
|
|
72
|
+
if (!operationObject) return [];
|
|
73
|
+
|
|
74
|
+
const { description, requestBody, responses } = operationObject;
|
|
75
|
+
|
|
76
|
+
return [
|
|
77
|
+
create("TabItem", {
|
|
78
|
+
label: `${method.toUpperCase()} ${name}`,
|
|
79
|
+
value: `${method}-${name}`,
|
|
80
|
+
children: [
|
|
81
|
+
createMethodEndpoint(method, path),
|
|
82
|
+
// TODO: add `deprecation notice` when markdown support is added
|
|
83
|
+
createDescription(description),
|
|
84
|
+
createRequestBodyDetails({
|
|
85
|
+
title: "Body",
|
|
86
|
+
body: requestBody,
|
|
87
|
+
} as RequestBodyProps),
|
|
88
|
+
createStatusCodes({
|
|
89
|
+
id: "callbacks-responses",
|
|
90
|
+
label: "Callbacks Responses",
|
|
91
|
+
responses,
|
|
92
|
+
}),
|
|
93
|
+
],
|
|
94
|
+
}),
|
|
95
|
+
];
|
|
96
|
+
});
|
|
97
|
+
}),
|
|
98
|
+
}),
|
|
99
|
+
],
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { ContactObject } from "../openapi/types";
|
|
9
8
|
import { create, guard } from "./utils";
|
|
9
|
+
import { ContactObject } from "../openapi/types";
|
|
10
10
|
|
|
11
11
|
export function createContactInfo(contact: ContactObject) {
|
|
12
12
|
if (!contact || !Object.keys(contact).length) return "";
|