docusaurus-plugin-openapi-docs 1.0.2 → 1.0.3
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 -2
- package/lib/index.d.ts +1 -0
- package/lib/index.js +50 -4
- package/lib/markdown/createAuthentication.d.ts +2 -0
- package/lib/markdown/createAuthentication.js +139 -0
- package/lib/markdown/index.d.ts +3 -2
- package/lib/markdown/index.js +10 -2
- package/lib/openapi/createExample.js +59 -49
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +71 -41
- package/lib/openapi/openapi.test.js +0 -6
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +3 -0
- package/lib/openapi/utils/loadAndBundleSpec.js +44 -0
- package/lib/openapi/utils/types.d.ts +306 -0
- package/lib/openapi/utils/types.js +8 -0
- package/lib/sidebars/index.js +26 -22
- package/lib/types.d.ts +12 -2
- package/package.json +10 -8
- package/src/index.ts +66 -5
- package/src/markdown/createAuthentication.ts +160 -0
- package/src/markdown/index.ts +15 -2
- package/src/openapi/createExample.ts +59 -50
- package/src/openapi/openapi.test.ts +0 -6
- package/src/openapi/openapi.ts +85 -39
- package/src/openapi/utils/loadAndBundleSpec.ts +62 -0
- package/src/openapi/utils/types.ts +303 -0
- package/src/sidebars/index.ts +29 -22
- package/src/types.ts +13 -1
- package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +0 -4
- package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +0 -13
- package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +0 -13
package/lib/openapi/openapi.js
CHANGED
|
@@ -16,10 +16,11 @@ const openapi_to_postmanv2_1 = __importDefault(require("@paloaltonetworks/openap
|
|
|
16
16
|
const postman_collection_1 = __importDefault(require("@paloaltonetworks/postman-collection"));
|
|
17
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
18
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
19
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
20
19
|
const json_refs_1 = __importDefault(require("json-refs"));
|
|
21
20
|
const lodash_1 = require("lodash");
|
|
21
|
+
const index_1 = require("../index");
|
|
22
22
|
const createExample_1 = require("./createExample");
|
|
23
|
+
const loadAndBundleSpec_1 = require("./utils/loadAndBundleSpec");
|
|
23
24
|
/**
|
|
24
25
|
* Finds any reference objects in the OpenAPI definition and resolves them to a finalized value.
|
|
25
26
|
*/
|
|
@@ -63,13 +64,39 @@ async function createPostmanCollection(openapiData) {
|
|
|
63
64
|
}
|
|
64
65
|
return await jsonToCollection(data);
|
|
65
66
|
}
|
|
66
|
-
function createItems(openapiData) {
|
|
67
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
67
|
+
function createItems(openapiData, sidebarOptions) {
|
|
68
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
68
69
|
// TODO: Find a better way to handle this
|
|
69
70
|
let items = [];
|
|
70
|
-
|
|
71
|
+
const infoId = (0, lodash_1.kebabCase)(openapiData.info.title);
|
|
72
|
+
if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
|
|
73
|
+
// Only create an tag pages if categoryLinkSource set to tag.
|
|
74
|
+
const tags = (_a = openapiData.tags) !== null && _a !== void 0 ? _a : [];
|
|
75
|
+
// eslint-disable-next-line array-callback-return
|
|
76
|
+
tags
|
|
77
|
+
.filter((tag) => { var _a; return !((_a = tag.description) === null || _a === void 0 ? void 0 : _a.includes("SchemaDefinition")); })
|
|
78
|
+
// eslint-disable-next-line array-callback-return
|
|
79
|
+
.map((tag) => {
|
|
80
|
+
var _a;
|
|
81
|
+
const description = getTagDisplayName(tag.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []);
|
|
82
|
+
const tagId = (0, lodash_1.kebabCase)(tag.name);
|
|
83
|
+
const tagPage = {
|
|
84
|
+
type: "tag",
|
|
85
|
+
id: tagId,
|
|
86
|
+
unversionedId: tagId,
|
|
87
|
+
title: description !== null && description !== void 0 ? description : "",
|
|
88
|
+
description: description !== null && description !== void 0 ? description : "",
|
|
89
|
+
slug: "/" + tagId,
|
|
90
|
+
frontMatter: {},
|
|
91
|
+
tag: {
|
|
92
|
+
...tag,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
items.push(tagPage);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
71
98
|
if (openapiData.info.description) {
|
|
72
|
-
|
|
99
|
+
// Only create an info page if we have a description.
|
|
73
100
|
const infoPage = {
|
|
74
101
|
type: "info",
|
|
75
102
|
id: infoId,
|
|
@@ -78,10 +105,11 @@ function createItems(openapiData) {
|
|
|
78
105
|
description: openapiData.info.description,
|
|
79
106
|
slug: "/" + infoId,
|
|
80
107
|
frontMatter: {},
|
|
108
|
+
securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
|
|
81
109
|
info: {
|
|
82
110
|
...openapiData.info,
|
|
83
|
-
tags: (
|
|
84
|
-
title: (
|
|
111
|
+
tags: (_c = openapiData.tags) === null || _c === void 0 ? void 0 : _c.map((tagName) => { var _a; return getTagDisplayName(tagName.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
|
|
112
|
+
title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
|
|
85
113
|
},
|
|
86
114
|
};
|
|
87
115
|
items.push(infoPage);
|
|
@@ -89,16 +117,16 @@ function createItems(openapiData) {
|
|
|
89
117
|
for (let [path, pathObject] of Object.entries(openapiData.paths)) {
|
|
90
118
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
91
119
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
92
|
-
const title = (
|
|
120
|
+
const title = (_f = (_e = operationObject.summary) !== null && _e !== void 0 ? _e : operationObject.operationId) !== null && _f !== void 0 ? _f : "Missing summary";
|
|
93
121
|
if (operationObject.description === undefined) {
|
|
94
122
|
operationObject.description =
|
|
95
|
-
(
|
|
123
|
+
(_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
|
|
96
124
|
}
|
|
97
125
|
const baseId = (0, lodash_1.kebabCase)(title);
|
|
98
|
-
const servers = (
|
|
99
|
-
const security = (
|
|
126
|
+
const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
|
|
127
|
+
const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
|
|
100
128
|
// Add security schemes so we know how to handle security.
|
|
101
|
-
const securitySchemes = (
|
|
129
|
+
const securitySchemes = (_m = openapiData.components) === null || _m === void 0 ? void 0 : _m.securitySchemes;
|
|
102
130
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
103
131
|
if (securitySchemes) {
|
|
104
132
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -108,7 +136,7 @@ function createItems(openapiData) {
|
|
|
108
136
|
}
|
|
109
137
|
}
|
|
110
138
|
let jsonRequestBodyExample;
|
|
111
|
-
const body = (
|
|
139
|
+
const body = (_p = (_o = operationObject.requestBody) === null || _o === void 0 ? void 0 : _o.content) === null || _p === void 0 ? void 0 : _p["application/json"];
|
|
112
140
|
if (body === null || body === void 0 ? void 0 : body.schema) {
|
|
113
141
|
jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(body.schema);
|
|
114
142
|
}
|
|
@@ -117,6 +145,7 @@ function createItems(openapiData) {
|
|
|
117
145
|
const apiPage = {
|
|
118
146
|
type: "api",
|
|
119
147
|
id: baseId,
|
|
148
|
+
infoId: infoId !== null && infoId !== void 0 ? infoId : "",
|
|
120
149
|
unversionedId: baseId,
|
|
121
150
|
title: title,
|
|
122
151
|
description: description !== null && description !== void 0 ? description : "",
|
|
@@ -124,7 +153,7 @@ function createItems(openapiData) {
|
|
|
124
153
|
frontMatter: {},
|
|
125
154
|
api: {
|
|
126
155
|
...defaults,
|
|
127
|
-
tags: (
|
|
156
|
+
tags: (_q = operationObject.tags) === null || _q === void 0 ? void 0 : _q.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
|
|
128
157
|
method,
|
|
129
158
|
path,
|
|
130
159
|
servers,
|
|
@@ -149,7 +178,7 @@ function bindCollectionToApiItems(items, postmanCollection) {
|
|
|
149
178
|
.getPath({ unresolved: true }) // unresolved returns "/:variableName" instead of "/<type>"
|
|
150
179
|
.replace(/:([a-z0-9-_]+)/gi, "{$1}"); // replace "/:variableName" with "/{variableName}"
|
|
151
180
|
const apiItem = items.find((item) => {
|
|
152
|
-
if (item.type === "info") {
|
|
181
|
+
if (item.type === "info" || item.type === "tag") {
|
|
153
182
|
return false;
|
|
154
183
|
}
|
|
155
184
|
return item.api.path === path && item.api.method === method;
|
|
@@ -160,29 +189,30 @@ function bindCollectionToApiItems(items, postmanCollection) {
|
|
|
160
189
|
});
|
|
161
190
|
}
|
|
162
191
|
async function readOpenapiFiles(openapiPath, _options) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
192
|
+
if (!(0, index_1.isURL)(openapiPath)) {
|
|
193
|
+
const stat = await fs_extra_1.default.lstat(openapiPath);
|
|
194
|
+
if (stat.isDirectory()) {
|
|
195
|
+
console.warn(chalk_1.default.yellow("WARNING: Loading a directory of OpenAPI definitions is experimental and subject to unannounced breaking changes."));
|
|
196
|
+
// TODO: Add config for inlcude/ignore
|
|
197
|
+
const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
|
|
198
|
+
cwd: openapiPath,
|
|
199
|
+
ignore: utils_1.GlobExcludeDefault,
|
|
200
|
+
deep: 1,
|
|
201
|
+
});
|
|
202
|
+
const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
|
|
203
|
+
return Promise.all(sources.map(async (source) => {
|
|
204
|
+
// TODO: make a function for this
|
|
205
|
+
const fullPath = path_1.default.join(openapiPath, source);
|
|
206
|
+
const data = (await (0, loadAndBundleSpec_1.loadAndBundleSpec)(fullPath));
|
|
207
|
+
return {
|
|
208
|
+
source: fullPath,
|
|
209
|
+
sourceDirName: path_1.default.dirname(source),
|
|
210
|
+
data,
|
|
211
|
+
};
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
183
214
|
}
|
|
184
|
-
const
|
|
185
|
-
const data = js_yaml_1.default.load(openapiString);
|
|
215
|
+
const data = (await (0, loadAndBundleSpec_1.loadAndBundleSpec)(openapiPath));
|
|
186
216
|
return [
|
|
187
217
|
{
|
|
188
218
|
source: openapiPath,
|
|
@@ -192,9 +222,9 @@ async function readOpenapiFiles(openapiPath, _options) {
|
|
|
192
222
|
];
|
|
193
223
|
}
|
|
194
224
|
exports.readOpenapiFiles = readOpenapiFiles;
|
|
195
|
-
async function processOpenapiFiles(files) {
|
|
225
|
+
async function processOpenapiFiles(files, sidebarOptions) {
|
|
196
226
|
const promises = files.map(async (file) => {
|
|
197
|
-
const processedFile = await processOpenapiFile(file.data);
|
|
227
|
+
const processedFile = await processOpenapiFile(file.data, sidebarOptions);
|
|
198
228
|
const itemsObjectsArray = processedFile[0].map((item) => ({
|
|
199
229
|
...item,
|
|
200
230
|
}));
|
|
@@ -213,10 +243,10 @@ async function processOpenapiFiles(files) {
|
|
|
213
243
|
return [items, tags];
|
|
214
244
|
}
|
|
215
245
|
exports.processOpenapiFiles = processOpenapiFiles;
|
|
216
|
-
async function processOpenapiFile(openapiDataWithRefs) {
|
|
246
|
+
async function processOpenapiFile(openapiDataWithRefs, sidebarOptions) {
|
|
217
247
|
const openapiData = await resolveRefs(openapiDataWithRefs);
|
|
218
248
|
const postmanCollection = await createPostmanCollection(openapiData);
|
|
219
|
-
const items = createItems(openapiData);
|
|
249
|
+
const items = createItems(openapiData, sidebarOptions);
|
|
220
250
|
bindCollectionToApiItems(items, postmanCollection);
|
|
221
251
|
let tags = [];
|
|
222
252
|
if (openapiData.tags !== undefined) {
|
|
@@ -22,12 +22,6 @@ describe("openapi", () => {
|
|
|
22
22
|
const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
|
|
23
23
|
expect(yaml).toBeTruthy();
|
|
24
24
|
expect(yaml === null || yaml === void 0 ? void 0 : yaml.sourceDirName).toBe(".");
|
|
25
|
-
const froyo = results.find((x) => x.source.endsWith("froyo.yaml"));
|
|
26
|
-
expect(froyo).toBeTruthy();
|
|
27
|
-
expect(froyo === null || froyo === void 0 ? void 0 : froyo.sourceDirName).toBe("yogurtstore");
|
|
28
|
-
const nested = results.find((x) => x.source.endsWith("nested.yaml"));
|
|
29
|
-
expect(nested).toBeTruthy();
|
|
30
|
-
expect(nested === null || nested === void 0 ? void 0 : nested.sourceDirName).toBe("yogurtstore/nested");
|
|
31
25
|
});
|
|
32
26
|
});
|
|
33
27
|
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.convertSwagger2OpenAPI = exports.loadAndBundleSpec = void 0;
|
|
10
|
+
const bundle_1 = require("@redocly/openapi-core/lib/bundle");
|
|
11
|
+
const config_1 = require("@redocly/openapi-core/lib/config/config");
|
|
12
|
+
const swagger2openapi_1 = require("swagger2openapi");
|
|
13
|
+
async function loadAndBundleSpec(specUrlOrObject) {
|
|
14
|
+
const config = new config_1.Config({});
|
|
15
|
+
const bundleOpts = {
|
|
16
|
+
config,
|
|
17
|
+
base: process.cwd(),
|
|
18
|
+
};
|
|
19
|
+
if (typeof specUrlOrObject === "object" && specUrlOrObject !== null) {
|
|
20
|
+
bundleOpts["doc"] = {
|
|
21
|
+
source: { absoluteRef: "" },
|
|
22
|
+
parsed: specUrlOrObject,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
bundleOpts["ref"] = specUrlOrObject;
|
|
27
|
+
}
|
|
28
|
+
// Force dereference ?
|
|
29
|
+
// bundleOpts["dereference"] = true;
|
|
30
|
+
const { bundle: { parsed }, } = await (0, bundle_1.bundle)(bundleOpts);
|
|
31
|
+
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
|
|
32
|
+
}
|
|
33
|
+
exports.loadAndBundleSpec = loadAndBundleSpec;
|
|
34
|
+
function convertSwagger2OpenAPI(spec) {
|
|
35
|
+
console.warn("[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0");
|
|
36
|
+
return new Promise((resolve, reject) => (0, swagger2openapi_1.convertObj)(spec, { patch: true, warnOnly: true, text: "{}", anchors: true }, (err, res) => {
|
|
37
|
+
// TODO: log any warnings
|
|
38
|
+
if (err) {
|
|
39
|
+
return reject(err);
|
|
40
|
+
}
|
|
41
|
+
resolve(res && res.openapi);
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
exports.convertSwagger2OpenAPI = convertSwagger2OpenAPI;
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
2
|
+
export interface OpenAPISpec {
|
|
3
|
+
openapi: string;
|
|
4
|
+
info: OpenAPIInfo;
|
|
5
|
+
servers?: OpenAPIServer[];
|
|
6
|
+
paths: OpenAPIPaths;
|
|
7
|
+
components?: OpenAPIComponents;
|
|
8
|
+
security?: OpenAPISecurityRequirement[];
|
|
9
|
+
tags?: OpenAPITag[];
|
|
10
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
11
|
+
"x-webhooks"?: OpenAPIPaths;
|
|
12
|
+
webhooks?: OpenAPIPaths;
|
|
13
|
+
}
|
|
14
|
+
export interface OpenAPIInfo {
|
|
15
|
+
title: string;
|
|
16
|
+
version: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
summary?: string;
|
|
19
|
+
termsOfService?: string;
|
|
20
|
+
contact?: OpenAPIContact;
|
|
21
|
+
license?: OpenAPILicense;
|
|
22
|
+
}
|
|
23
|
+
export interface OpenAPIServer {
|
|
24
|
+
url: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
variables?: {
|
|
27
|
+
[name: string]: OpenAPIServerVariable;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface OpenAPIServerVariable {
|
|
31
|
+
enum?: string[];
|
|
32
|
+
default: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface OpenAPIPaths {
|
|
36
|
+
[path: string]: OpenAPIPath;
|
|
37
|
+
}
|
|
38
|
+
export interface OpenAPIRef {
|
|
39
|
+
$ref: string;
|
|
40
|
+
}
|
|
41
|
+
export declare type Referenced<T> = OpenAPIRef | T;
|
|
42
|
+
export interface OpenAPIPath {
|
|
43
|
+
summary?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
get?: OpenAPIOperation;
|
|
46
|
+
put?: OpenAPIOperation;
|
|
47
|
+
post?: OpenAPIOperation;
|
|
48
|
+
delete?: OpenAPIOperation;
|
|
49
|
+
options?: OpenAPIOperation;
|
|
50
|
+
head?: OpenAPIOperation;
|
|
51
|
+
patch?: OpenAPIOperation;
|
|
52
|
+
trace?: OpenAPIOperation;
|
|
53
|
+
servers?: OpenAPIServer[];
|
|
54
|
+
parameters?: Array<Referenced<OpenAPIParameter>>;
|
|
55
|
+
$ref?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface OpenAPIXCodeSample {
|
|
58
|
+
lang: string;
|
|
59
|
+
label?: string;
|
|
60
|
+
source: string;
|
|
61
|
+
}
|
|
62
|
+
export interface OpenAPIOperation {
|
|
63
|
+
tags?: string[];
|
|
64
|
+
summary?: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
67
|
+
operationId?: string;
|
|
68
|
+
parameters?: Array<Referenced<OpenAPIParameter>>;
|
|
69
|
+
requestBody?: Referenced<OpenAPIRequestBody>;
|
|
70
|
+
responses: OpenAPIResponses;
|
|
71
|
+
callbacks?: {
|
|
72
|
+
[name: string]: Referenced<OpenAPICallback>;
|
|
73
|
+
};
|
|
74
|
+
deprecated?: boolean;
|
|
75
|
+
security?: OpenAPISecurityRequirement[];
|
|
76
|
+
servers?: OpenAPIServer[];
|
|
77
|
+
"x-codeSamples"?: OpenAPIXCodeSample[];
|
|
78
|
+
"x-code-samples"?: OpenAPIXCodeSample[];
|
|
79
|
+
}
|
|
80
|
+
export interface OpenAPIParameter {
|
|
81
|
+
name: string;
|
|
82
|
+
in?: OpenAPIParameterLocation;
|
|
83
|
+
description?: string;
|
|
84
|
+
required?: boolean;
|
|
85
|
+
deprecated?: boolean;
|
|
86
|
+
allowEmptyValue?: boolean;
|
|
87
|
+
style?: OpenAPIParameterStyle;
|
|
88
|
+
explode?: boolean;
|
|
89
|
+
allowReserved?: boolean;
|
|
90
|
+
schema?: Referenced<OpenAPISchema>;
|
|
91
|
+
example?: any;
|
|
92
|
+
examples?: {
|
|
93
|
+
[media: string]: Referenced<OpenAPIExample>;
|
|
94
|
+
};
|
|
95
|
+
content?: {
|
|
96
|
+
[media: string]: OpenAPIMediaType;
|
|
97
|
+
};
|
|
98
|
+
encoding?: Record<string, OpenAPIEncoding>;
|
|
99
|
+
const?: any;
|
|
100
|
+
}
|
|
101
|
+
export interface OpenAPIExample {
|
|
102
|
+
value: any;
|
|
103
|
+
summary?: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
externalValue?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface OpenAPISchema {
|
|
108
|
+
$ref?: string;
|
|
109
|
+
type?: string | string[];
|
|
110
|
+
properties?: {
|
|
111
|
+
[name: string]: OpenAPISchema;
|
|
112
|
+
};
|
|
113
|
+
patternProperties?: {
|
|
114
|
+
[name: string]: OpenAPISchema;
|
|
115
|
+
};
|
|
116
|
+
additionalProperties?: boolean | OpenAPISchema;
|
|
117
|
+
unevaluatedProperties?: boolean | OpenAPISchema;
|
|
118
|
+
description?: string;
|
|
119
|
+
default?: any;
|
|
120
|
+
items?: OpenAPISchema | OpenAPISchema[] | boolean;
|
|
121
|
+
required?: string[];
|
|
122
|
+
readOnly?: boolean;
|
|
123
|
+
writeOnly?: boolean;
|
|
124
|
+
deprecated?: boolean;
|
|
125
|
+
format?: string;
|
|
126
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
127
|
+
discriminator?: OpenAPIDiscriminator;
|
|
128
|
+
nullable?: boolean;
|
|
129
|
+
oneOf?: OpenAPISchema[];
|
|
130
|
+
anyOf?: OpenAPISchema[];
|
|
131
|
+
allOf?: OpenAPISchema[];
|
|
132
|
+
not?: OpenAPISchema;
|
|
133
|
+
title?: string;
|
|
134
|
+
multipleOf?: number;
|
|
135
|
+
maximum?: number;
|
|
136
|
+
exclusiveMaximum?: boolean | number;
|
|
137
|
+
minimum?: number;
|
|
138
|
+
exclusiveMinimum?: boolean | number;
|
|
139
|
+
maxLength?: number;
|
|
140
|
+
minLength?: number;
|
|
141
|
+
pattern?: string;
|
|
142
|
+
maxItems?: number;
|
|
143
|
+
minItems?: number;
|
|
144
|
+
uniqueItems?: boolean;
|
|
145
|
+
maxProperties?: number;
|
|
146
|
+
minProperties?: number;
|
|
147
|
+
enum?: any[];
|
|
148
|
+
example?: any;
|
|
149
|
+
if?: OpenAPISchema;
|
|
150
|
+
else?: OpenAPISchema;
|
|
151
|
+
then?: OpenAPISchema;
|
|
152
|
+
examples?: any[];
|
|
153
|
+
const?: string;
|
|
154
|
+
contentEncoding?: string;
|
|
155
|
+
contentMediaType?: string;
|
|
156
|
+
prefixItems?: OpenAPISchema[];
|
|
157
|
+
additionalItems?: OpenAPISchema | boolean;
|
|
158
|
+
}
|
|
159
|
+
export interface OpenAPIDiscriminator {
|
|
160
|
+
propertyName: string;
|
|
161
|
+
mapping?: {
|
|
162
|
+
[name: string]: string;
|
|
163
|
+
};
|
|
164
|
+
"x-explicitMappingOnly"?: boolean;
|
|
165
|
+
}
|
|
166
|
+
export interface OpenAPIMediaType {
|
|
167
|
+
schema?: Referenced<OpenAPISchema>;
|
|
168
|
+
example?: any;
|
|
169
|
+
examples?: {
|
|
170
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
171
|
+
};
|
|
172
|
+
encoding?: {
|
|
173
|
+
[field: string]: OpenAPIEncoding;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export interface OpenAPIEncoding {
|
|
177
|
+
contentType: string;
|
|
178
|
+
headers?: {
|
|
179
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
180
|
+
};
|
|
181
|
+
style: OpenAPIParameterStyle;
|
|
182
|
+
explode: boolean;
|
|
183
|
+
allowReserved: boolean;
|
|
184
|
+
}
|
|
185
|
+
export declare type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
|
|
186
|
+
export declare type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
|
|
187
|
+
export interface OpenAPIRequestBody {
|
|
188
|
+
description?: string;
|
|
189
|
+
required?: boolean;
|
|
190
|
+
content: {
|
|
191
|
+
[mime: string]: OpenAPIMediaType;
|
|
192
|
+
};
|
|
193
|
+
"x-examples"?: {
|
|
194
|
+
[mime: string]: {
|
|
195
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
"x-example"?: {
|
|
199
|
+
[mime: string]: any;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export interface OpenAPIResponses {
|
|
203
|
+
[code: string]: Referenced<OpenAPIResponse>;
|
|
204
|
+
}
|
|
205
|
+
export interface OpenAPIResponse extends Pick<OpenAPIRequestBody, "description" | "x-examples" | "x-example"> {
|
|
206
|
+
headers?: {
|
|
207
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
208
|
+
};
|
|
209
|
+
links?: {
|
|
210
|
+
[name: string]: Referenced<OpenAPILink>;
|
|
211
|
+
};
|
|
212
|
+
content?: {
|
|
213
|
+
[mime: string]: OpenAPIMediaType;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
export interface OpenAPILink {
|
|
217
|
+
$ref?: string;
|
|
218
|
+
}
|
|
219
|
+
export declare type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
|
|
220
|
+
export interface OpenAPICallback {
|
|
221
|
+
[name: string]: OpenAPIPath;
|
|
222
|
+
}
|
|
223
|
+
export interface OpenAPIComponents {
|
|
224
|
+
schemas?: {
|
|
225
|
+
[name: string]: Referenced<OpenAPISchema>;
|
|
226
|
+
};
|
|
227
|
+
responses?: {
|
|
228
|
+
[name: string]: Referenced<OpenAPIResponse>;
|
|
229
|
+
};
|
|
230
|
+
parameters?: {
|
|
231
|
+
[name: string]: Referenced<OpenAPIParameter>;
|
|
232
|
+
};
|
|
233
|
+
examples?: {
|
|
234
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
235
|
+
};
|
|
236
|
+
requestBodies?: {
|
|
237
|
+
[name: string]: Referenced<OpenAPIRequestBody>;
|
|
238
|
+
};
|
|
239
|
+
headers?: {
|
|
240
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
241
|
+
};
|
|
242
|
+
securitySchemes?: {
|
|
243
|
+
[name: string]: Referenced<OpenAPISecurityScheme>;
|
|
244
|
+
};
|
|
245
|
+
links?: {
|
|
246
|
+
[name: string]: Referenced<OpenAPILink>;
|
|
247
|
+
};
|
|
248
|
+
callbacks?: {
|
|
249
|
+
[name: string]: Referenced<OpenAPICallback>;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
export interface OpenAPISecurityRequirement {
|
|
253
|
+
[name: string]: string[];
|
|
254
|
+
}
|
|
255
|
+
export interface OpenAPISecurityScheme {
|
|
256
|
+
type: "apiKey" | "http" | "oauth2" | "openIdConnect";
|
|
257
|
+
description?: string;
|
|
258
|
+
name?: string;
|
|
259
|
+
in?: "query" | "header" | "cookie";
|
|
260
|
+
scheme?: string;
|
|
261
|
+
bearerFormat: string;
|
|
262
|
+
flows: {
|
|
263
|
+
implicit?: {
|
|
264
|
+
refreshUrl?: string;
|
|
265
|
+
scopes: Record<string, string>;
|
|
266
|
+
authorizationUrl: string;
|
|
267
|
+
};
|
|
268
|
+
password?: {
|
|
269
|
+
refreshUrl?: string;
|
|
270
|
+
scopes: Record<string, string>;
|
|
271
|
+
tokenUrl: string;
|
|
272
|
+
};
|
|
273
|
+
clientCredentials?: {
|
|
274
|
+
refreshUrl?: string;
|
|
275
|
+
scopes: Record<string, string>;
|
|
276
|
+
tokenUrl: string;
|
|
277
|
+
};
|
|
278
|
+
authorizationCode?: {
|
|
279
|
+
refreshUrl?: string;
|
|
280
|
+
scopes: Record<string, string>;
|
|
281
|
+
tokenUrl: string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
openIdConnectUrl?: string;
|
|
285
|
+
}
|
|
286
|
+
export interface OpenAPITag {
|
|
287
|
+
name: string;
|
|
288
|
+
description?: string;
|
|
289
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
290
|
+
"x-displayName"?: string;
|
|
291
|
+
}
|
|
292
|
+
export interface OpenAPIExternalDocumentation {
|
|
293
|
+
description?: string;
|
|
294
|
+
url: string;
|
|
295
|
+
}
|
|
296
|
+
export interface OpenAPIContact {
|
|
297
|
+
name?: string;
|
|
298
|
+
url?: string;
|
|
299
|
+
email?: string;
|
|
300
|
+
}
|
|
301
|
+
export interface OpenAPILicense {
|
|
302
|
+
name: string;
|
|
303
|
+
url?: string;
|
|
304
|
+
identifier?: string;
|
|
305
|
+
}
|
|
306
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/lib/sidebars/index.js
CHANGED
|
@@ -67,7 +67,7 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
67
67
|
const tagged = apiTags
|
|
68
68
|
.map((tag) => {
|
|
69
69
|
// Map info object to tag
|
|
70
|
-
const
|
|
70
|
+
const taggedInfoObject = intros.find((i) => i.tags ? i.tags.includes(tag) : undefined);
|
|
71
71
|
const tagObject = tags.flat().find((t) => {
|
|
72
72
|
var _a;
|
|
73
73
|
return (_a = (tag === t.name || tag === t["x-displayName"])) !== null && _a !== void 0 ? _a : {
|
|
@@ -77,20 +77,18 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
77
77
|
});
|
|
78
78
|
// TODO: perhaps move this into a getLinkConfig() function
|
|
79
79
|
let linkConfig = undefined;
|
|
80
|
-
if (
|
|
80
|
+
if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
|
|
81
81
|
linkConfig = {
|
|
82
82
|
type: "doc",
|
|
83
|
-
id: `${basePath}/${
|
|
83
|
+
id: `${basePath}/${taggedInfoObject.id}`,
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
// TODO: perhaps move this into a getLinkConfig() function
|
|
87
87
|
if (tagObject !== undefined && categoryLinkSource === "tag") {
|
|
88
|
-
const
|
|
88
|
+
const tagId = (0, lodash_1.kebabCase)(tagObject.name);
|
|
89
89
|
linkConfig = {
|
|
90
|
-
type: "
|
|
91
|
-
|
|
92
|
-
description: linkDescription,
|
|
93
|
-
slug: "/category/" + (0, lodash_1.kebabCase)(tag),
|
|
90
|
+
type: "doc",
|
|
91
|
+
id: `${basePath}/${tagId}`,
|
|
94
92
|
};
|
|
95
93
|
}
|
|
96
94
|
// Default behavior
|
|
@@ -113,28 +111,34 @@ function groupByTags(items, sidebarOptions, options, tags) {
|
|
|
113
111
|
};
|
|
114
112
|
})
|
|
115
113
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
116
|
-
//
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
114
|
+
// Handle items with no tag
|
|
115
|
+
const untaggedItems = apiItems
|
|
116
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
117
|
+
.map(createDocItem);
|
|
118
|
+
let untagged = [];
|
|
119
|
+
if (untaggedItems.length > 0) {
|
|
120
|
+
untagged = [
|
|
121
|
+
{
|
|
122
|
+
type: "category",
|
|
123
|
+
label: "UNTAGGED",
|
|
124
|
+
collapsible: sidebarCollapsible,
|
|
125
|
+
collapsed: sidebarCollapsed,
|
|
126
|
+
items: apiItems
|
|
127
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
128
|
+
.map(createDocItem),
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
}
|
|
128
132
|
// Shift root intro doc to top of sidebar
|
|
129
133
|
// TODO: Add input validation for categoryLinkSource options
|
|
130
134
|
if (rootIntroDoc && categoryLinkSource !== "info") {
|
|
131
135
|
tagged.unshift(rootIntroDoc);
|
|
132
136
|
}
|
|
133
|
-
return [...tagged];
|
|
137
|
+
return [...tagged, ...untagged];
|
|
134
138
|
}
|
|
135
139
|
function generateSidebarSlice(sidebarOptions, options, api, tags) {
|
|
136
140
|
let sidebarSlice = [];
|
|
137
|
-
if (sidebarOptions.groupPathsBy === "
|
|
141
|
+
if (sidebarOptions.groupPathsBy === "tag") {
|
|
138
142
|
sidebarSlice = groupByTags(api, sidebarOptions, options, tags);
|
|
139
143
|
}
|
|
140
144
|
return sidebarSlice;
|