docusaurus-plugin-openapi-docs 4.0.1 → 4.2.0
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 +11 -0
- package/lib/index.js +4 -0
- package/lib/markdown/createCallbackMethodEndpoint.d.ts +1 -0
- package/lib/markdown/createCallbackMethodEndpoint.js +21 -0
- package/lib/markdown/createCallbacks.js +2 -2
- package/lib/markdown/createContactInfo.js +1 -1
- package/lib/markdown/createDeprecationNotice.js +5 -6
- package/lib/markdown/createMethodEndpoint.js +8 -1
- package/lib/markdown/createParamsDetails.d.ts +1 -2
- package/lib/markdown/createParamsDetails.js +7 -36
- package/lib/markdown/createRequestBodyDetails.d.ts +1 -1
- package/lib/markdown/createRequestSchema.d.ts +1 -1
- package/lib/markdown/createRequestSchema.js +8 -132
- package/lib/markdown/createResponseSchema.d.ts +1 -1
- package/lib/markdown/createResponseSchema.js +8 -94
- package/lib/markdown/createSchema.d.ts +1 -4
- package/lib/markdown/createSchema.js +35 -50
- package/lib/markdown/createSchema.test.js +48 -0
- package/lib/markdown/createStatusCodes.d.ts +1 -4
- package/lib/markdown/createStatusCodes.js +10 -259
- package/lib/markdown/index.js +11 -22
- package/lib/markdown/utils.d.ts +4 -0
- package/lib/openapi/createRequestExample.js +2 -2
- package/lib/openapi/createResponseExample.js +2 -2
- package/lib/openapi/openapi.js +16 -14
- package/lib/openapi/types.d.ts +4 -0
- package/lib/openapi/utils/services/OpenAPIParser.js +1 -1
- package/lib/options.js +5 -0
- package/lib/sidebars/index.js +32 -26
- package/lib/types.d.ts +9 -0
- package/package.json +7 -7
- package/src/index.ts +4 -0
- package/src/markdown/__snapshots__/createSchema.test.ts.snap +142 -0
- package/src/markdown/createCallbackMethodEndpoint.ts +19 -0
- package/src/markdown/createCallbacks.ts +2 -2
- package/src/markdown/createContactInfo.ts +1 -1
- package/src/markdown/createDeprecationNotice.ts +3 -2
- package/src/markdown/createMethodEndpoint.ts +8 -1
- package/src/markdown/createParamsDetails.ts +7 -42
- package/src/markdown/createRequestSchema.ts +9 -143
- package/src/markdown/createResponseSchema.ts +9 -112
- package/src/markdown/createSchema.test.ts +64 -0
- package/src/markdown/createSchema.ts +30 -50
- package/src/markdown/createStatusCodes.ts +9 -268
- package/src/markdown/index.ts +11 -22
- package/src/markdown/utils.ts +4 -0
- package/src/openapi/createRequestExample.ts +2 -5
- package/src/openapi/createResponseExample.ts +2 -5
- package/src/openapi/openapi.ts +4 -2
- package/src/openapi/types.ts +4 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +1 -1
- package/src/openapi/utils/services/OpenAPIParser.ts +1 -0
- package/src/options.ts +6 -0
- package/src/sidebars/index.ts +47 -40
- package/src/types.ts +11 -0
package/lib/openapi/openapi.js
CHANGED
|
@@ -21,8 +21,9 @@ const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
|
21
21
|
const openapi_to_postmanv2_1 = __importDefault(require("openapi-to-postmanv2"));
|
|
22
22
|
const postman_collection_1 = __importDefault(require("postman-collection"));
|
|
23
23
|
const createRequestExample_1 = require("./createRequestExample");
|
|
24
|
-
const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
|
|
25
24
|
const index_1 = require("../index");
|
|
25
|
+
const createResponseExample_1 = require("./createResponseExample");
|
|
26
|
+
const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
|
|
26
27
|
/**
|
|
27
28
|
* Convenience function for converting raw JSON to a Postman Collection object.
|
|
28
29
|
*/
|
|
@@ -61,7 +62,7 @@ async function createPostmanCollection(openapiData) {
|
|
|
61
62
|
return await jsonToCollection(data);
|
|
62
63
|
}
|
|
63
64
|
function createItems(openapiData, options, sidebarOptions) {
|
|
64
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
|
|
65
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7;
|
|
65
66
|
// TODO: Find a better way to handle this
|
|
66
67
|
let items = [];
|
|
67
68
|
const infoIdSpaces = openapiData.info.title.replace(" ", "-").toLowerCase();
|
|
@@ -212,15 +213,15 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
212
213
|
}
|
|
213
214
|
}
|
|
214
215
|
// Gather x-webhooks endpoints
|
|
215
|
-
for (let [path, pathObject] of Object.entries((_p = openapiData["x-webhooks"]) !== null && _p !== void 0 ? _p : {})) {
|
|
216
|
+
for (let [path, pathObject] of Object.entries((_q = (_p = openapiData["x-webhooks"]) !== null && _p !== void 0 ? _p : openapiData["webhooks"]) !== null && _q !== void 0 ? _q : {})) {
|
|
216
217
|
path = "webhook";
|
|
217
218
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
218
219
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
219
220
|
method = "event";
|
|
220
|
-
const title = (
|
|
221
|
+
const title = (_s = (_r = operationObject.summary) !== null && _r !== void 0 ? _r : operationObject.operationId) !== null && _s !== void 0 ? _s : "Missing summary";
|
|
221
222
|
if (operationObject.description === undefined) {
|
|
222
223
|
operationObject.description =
|
|
223
|
-
(
|
|
224
|
+
(_u = (_t = operationObject.summary) !== null && _t !== void 0 ? _t : operationObject.operationId) !== null && _u !== void 0 ? _u : "";
|
|
224
225
|
}
|
|
225
226
|
const baseId = operationObject.operationId
|
|
226
227
|
? (0, kebabCase_1.default)(operationObject.operationId)
|
|
@@ -232,10 +233,10 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
232
233
|
extensions.push({ key, value });
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
|
-
const servers = (
|
|
236
|
-
const security = (
|
|
236
|
+
const servers = (_w = (_v = operationObject.servers) !== null && _v !== void 0 ? _v : pathObject.servers) !== null && _w !== void 0 ? _w : openapiData.servers;
|
|
237
|
+
const security = (_x = operationObject.security) !== null && _x !== void 0 ? _x : openapiData.security;
|
|
237
238
|
// Add security schemes so we know how to handle security.
|
|
238
|
-
const securitySchemes = (
|
|
239
|
+
const securitySchemes = (_y = openapiData.components) === null || _y === void 0 ? void 0 : _y.securitySchemes;
|
|
239
240
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
240
241
|
if (securitySchemes) {
|
|
241
242
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -245,7 +246,7 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
245
246
|
}
|
|
246
247
|
}
|
|
247
248
|
let jsonRequestBodyExample;
|
|
248
|
-
const content = (
|
|
249
|
+
const content = (_z = operationObject.requestBody) === null || _z === void 0 ? void 0 : _z.content;
|
|
249
250
|
let body;
|
|
250
251
|
for (let key in content) {
|
|
251
252
|
if (key.toLowerCase() === "application/json" ||
|
|
@@ -258,7 +259,7 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
258
259
|
jsonRequestBodyExample = (0, createRequestExample_1.sampleRequestFromSchema)(body.schema);
|
|
259
260
|
}
|
|
260
261
|
// Handle vendor JSON media types
|
|
261
|
-
const bodyContent = (
|
|
262
|
+
const bodyContent = (_0 = operationObject.requestBody) === null || _0 === void 0 ? void 0 : _0.content;
|
|
262
263
|
if (bodyContent) {
|
|
263
264
|
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
264
265
|
if (firstBodyContentKey.endsWith("+json")) {
|
|
@@ -325,13 +326,13 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
325
326
|
}
|
|
326
327
|
}
|
|
327
328
|
if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true ||
|
|
328
|
-
Object.entries((
|
|
329
|
+
Object.entries((_2 = (_1 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _1 === void 0 ? void 0 : _1.schemas) !== null && _2 !== void 0 ? _2 : {})
|
|
329
330
|
.flatMap(([_, s]) => s["x-tags"])
|
|
330
331
|
.filter((item) => !!item).length > 0) {
|
|
331
332
|
// Gather schemas
|
|
332
|
-
for (let [schema, schemaObject] of Object.entries((
|
|
333
|
+
for (let [schema, schemaObject] of Object.entries((_4 = (_3 = openapiData === null || openapiData === void 0 ? void 0 : openapiData.components) === null || _3 === void 0 ? void 0 : _3.schemas) !== null && _4 !== void 0 ? _4 : {})) {
|
|
333
334
|
if ((options === null || options === void 0 ? void 0 : options.showSchemas) === true || schemaObject["x-tags"]) {
|
|
334
|
-
const baseIdSpaces = (
|
|
335
|
+
const baseIdSpaces = (_6 = (_5 = schemaObject === null || schemaObject === void 0 ? void 0 : schemaObject.title) === null || _5 === void 0 ? void 0 : _5.replace(" ", "-").toLowerCase()) !== null && _6 !== void 0 ? _6 : "";
|
|
335
336
|
const baseId = (0, kebabCase_1.default)(baseIdSpaces);
|
|
336
337
|
const schemaDescription = schemaObject.description;
|
|
337
338
|
let splitDescription;
|
|
@@ -355,6 +356,7 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
355
356
|
.replace(/((?:^|[^\\])(?:\\{2})*)"/g, "$1'")
|
|
356
357
|
.replace(/\s+$/, "")
|
|
357
358
|
: "",
|
|
359
|
+
sample: JSON.stringify((0, createResponseExample_1.sampleResponseFromSchema)(schemaObject)),
|
|
358
360
|
},
|
|
359
361
|
schema: schemaObject,
|
|
360
362
|
};
|
|
@@ -364,7 +366,7 @@ function createItems(openapiData, options, sidebarOptions) {
|
|
|
364
366
|
}
|
|
365
367
|
if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
|
|
366
368
|
// Get global tags
|
|
367
|
-
const tags = (
|
|
369
|
+
const tags = (_7 = openapiData.tags) !== null && _7 !== void 0 ? _7 : [];
|
|
368
370
|
// Get operation tags
|
|
369
371
|
const apiItems = items.filter((item) => {
|
|
370
372
|
return item.type === "api";
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface OpenApiObject {
|
|
|
12
12
|
tags?: TagObject[];
|
|
13
13
|
externalDocs?: ExternalDocumentationObject;
|
|
14
14
|
swagger?: string;
|
|
15
|
+
webhooks?: PathsObject;
|
|
15
16
|
"x-webhooks"?: PathsObject;
|
|
16
17
|
"x-tagGroups"?: TagGroupObject[];
|
|
17
18
|
}
|
|
@@ -163,6 +164,7 @@ export interface ParameterObject {
|
|
|
163
164
|
examples?: Map<ExampleObject>;
|
|
164
165
|
content?: Map<MediaTypeObject>;
|
|
165
166
|
param?: Object;
|
|
167
|
+
"x-enumDescriptions"?: Record<string, string>;
|
|
166
168
|
}
|
|
167
169
|
export interface ParameterObjectWithRef {
|
|
168
170
|
name: string;
|
|
@@ -194,6 +196,7 @@ export interface MediaTypeObject {
|
|
|
194
196
|
example?: any;
|
|
195
197
|
examples?: Map<ExampleObject>;
|
|
196
198
|
encoding?: Map<EncodingObject>;
|
|
199
|
+
type?: any;
|
|
197
200
|
}
|
|
198
201
|
export interface MediaTypeObjectWithRef {
|
|
199
202
|
schema?: SchemaObjectWithRef | ReferenceObject;
|
|
@@ -279,6 +282,7 @@ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf"
|
|
|
279
282
|
example?: any;
|
|
280
283
|
deprecated?: boolean;
|
|
281
284
|
"x-tags"?: string[];
|
|
285
|
+
"x-enumDescriptions"?: Record<string, string>;
|
|
282
286
|
};
|
|
283
287
|
export type SchemaObjectWithRef = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
|
|
284
288
|
type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
|
|
@@ -215,7 +215,7 @@ class OpenAPIParser {
|
|
|
215
215
|
})
|
|
216
216
|
.filter((child) => child !== undefined);
|
|
217
217
|
for (const { $ref: subSchemaRef, schema: subSchema } of allOfSchemas) {
|
|
218
|
-
const { type, enum: enumProperty, properties, items, required, oneOf, anyOf, title, ...otherConstraints } = subSchema;
|
|
218
|
+
const { type, enum: enumProperty, "x-enumDescription": enumDescription, properties, items, required, oneOf, anyOf, title, ...otherConstraints } = subSchema;
|
|
219
219
|
if (receiver.type !== type &&
|
|
220
220
|
receiver.type !== undefined &&
|
|
221
221
|
type !== undefined) {
|
package/lib/options.js
CHANGED
|
@@ -8,17 +8,22 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.OptionsSchema = void 0;
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
|
+
const sidebarGenerators = utils_validation_1.Joi.object({
|
|
12
|
+
createDocItem: utils_validation_1.Joi.function(),
|
|
13
|
+
});
|
|
11
14
|
const sidebarOptions = utils_validation_1.Joi.object({
|
|
12
15
|
groupPathsBy: utils_validation_1.Joi.string().valid("tag", "tagGroup"),
|
|
13
16
|
categoryLinkSource: utils_validation_1.Joi.string().valid("tag", "info", "auto"),
|
|
14
17
|
customProps: utils_validation_1.Joi.object(),
|
|
15
18
|
sidebarCollapsible: utils_validation_1.Joi.boolean(),
|
|
16
19
|
sidebarCollapsed: utils_validation_1.Joi.boolean(),
|
|
20
|
+
sidebarGenerators: sidebarGenerators,
|
|
17
21
|
});
|
|
18
22
|
const markdownGenerators = utils_validation_1.Joi.object({
|
|
19
23
|
createApiPageMD: utils_validation_1.Joi.function(),
|
|
20
24
|
createInfoPageMD: utils_validation_1.Joi.function(),
|
|
21
25
|
createTagPageMD: utils_validation_1.Joi.function(),
|
|
26
|
+
createSchemaPageMD: utils_validation_1.Joi.function(),
|
|
22
27
|
});
|
|
23
28
|
exports.OptionsSchema = utils_validation_1.Joi.object({
|
|
24
29
|
id: utils_validation_1.Joi.string().required(),
|
package/lib/sidebars/index.js
CHANGED
|
@@ -23,11 +23,33 @@ function isInfoItem(item) {
|
|
|
23
23
|
function isSchemaItem(item) {
|
|
24
24
|
return item.type === "schema";
|
|
25
25
|
}
|
|
26
|
+
const createDocItem = (item, { sidebarOptions: { customProps }, basePath }) => {
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const sidebar_label = item.frontMatter.sidebar_label;
|
|
29
|
+
const title = item.title;
|
|
30
|
+
const id = item.type === "schema" ? `schemas/${item.id}` : item.id;
|
|
31
|
+
const className = item.type === "api"
|
|
32
|
+
? (0, clsx_1.default)({
|
|
33
|
+
"menu__list-item--deprecated": item.api.deprecated,
|
|
34
|
+
"api-method": !!item.api.method,
|
|
35
|
+
}, item.api.method)
|
|
36
|
+
: (0, clsx_1.default)({
|
|
37
|
+
"menu__list-item--deprecated": item.schema.deprecated,
|
|
38
|
+
}, "schema");
|
|
39
|
+
return {
|
|
40
|
+
type: "doc",
|
|
41
|
+
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
42
|
+
label: (_b = (_a = sidebar_label) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : id,
|
|
43
|
+
customProps: customProps,
|
|
44
|
+
className: className ? className : undefined,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
26
47
|
function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
48
|
+
var _a, _b;
|
|
27
49
|
let { outputDir, label, showSchemas } = options;
|
|
28
50
|
// Remove trailing slash before proceeding
|
|
29
51
|
outputDir = outputDir.replace(/\/$/, "");
|
|
30
|
-
const { sidebarCollapsed, sidebarCollapsible,
|
|
52
|
+
const { sidebarCollapsed, sidebarCollapsible, categoryLinkSource } = sidebarOptions;
|
|
31
53
|
const apiItems = items.filter(isApiItem);
|
|
32
54
|
const infoItems = items.filter(isInfoItem);
|
|
33
55
|
const schemaItems = items.filter(isSchemaItem);
|
|
@@ -61,27 +83,11 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
61
83
|
const basePath = docPath
|
|
62
84
|
? outputDir.split(docPath)[1].replace(/^\/+/g, "")
|
|
63
85
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const className = item.type === "api"
|
|
70
|
-
? (0, clsx_1.default)({
|
|
71
|
-
"menu__list-item--deprecated": item.api.deprecated,
|
|
72
|
-
"api-method": !!item.api.method,
|
|
73
|
-
}, item.api.method)
|
|
74
|
-
: (0, clsx_1.default)({
|
|
75
|
-
"menu__list-item--deprecated": item.schema.deprecated,
|
|
76
|
-
}, "schema");
|
|
77
|
-
return {
|
|
78
|
-
type: "doc",
|
|
79
|
-
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
80
|
-
label: (_b = (_a = sidebar_label) !== null && _a !== void 0 ? _a : title) !== null && _b !== void 0 ? _b : id,
|
|
81
|
-
customProps: customProps,
|
|
82
|
-
className: className ? className : undefined,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
86
|
+
const createDocItemFnContext = {
|
|
87
|
+
sidebarOptions,
|
|
88
|
+
basePath,
|
|
89
|
+
};
|
|
90
|
+
const createDocItemFn = (_b = (_a = sidebarOptions.sidebarGenerators) === null || _a === void 0 ? void 0 : _a.createDocItem) !== null && _b !== void 0 ? _b : createDocItem;
|
|
85
91
|
let rootIntroDoc = undefined;
|
|
86
92
|
if (infoItems.length === 1) {
|
|
87
93
|
const infoItem = infoItems[0];
|
|
@@ -139,14 +145,14 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
139
145
|
link: linkConfig,
|
|
140
146
|
collapsible: sidebarCollapsible,
|
|
141
147
|
collapsed: sidebarCollapsed,
|
|
142
|
-
items: [...taggedSchemaItems, ...taggedApiItems].map(
|
|
148
|
+
items: [...taggedSchemaItems, ...taggedApiItems].map((item) => createDocItemFn(item, createDocItemFnContext)),
|
|
143
149
|
};
|
|
144
150
|
})
|
|
145
151
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
146
152
|
// Handle items with no tag
|
|
147
153
|
const untaggedItems = apiItems
|
|
148
154
|
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
149
|
-
.map(
|
|
155
|
+
.map((item) => createDocItemFn(item, createDocItemFnContext));
|
|
150
156
|
let untagged = [];
|
|
151
157
|
if (untaggedItems.length > 0) {
|
|
152
158
|
untagged = [
|
|
@@ -157,7 +163,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
157
163
|
collapsed: sidebarCollapsed,
|
|
158
164
|
items: apiItems
|
|
159
165
|
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
160
|
-
.map(
|
|
166
|
+
.map((item) => createDocItemFn(item, createDocItemFnContext)),
|
|
161
167
|
},
|
|
162
168
|
];
|
|
163
169
|
}
|
|
@@ -171,7 +177,7 @@ function groupByTags(items, sidebarOptions, options, tags, docPath) {
|
|
|
171
177
|
collapsed: sidebarCollapsed,
|
|
172
178
|
items: schemaItems
|
|
173
179
|
.filter(({ schema }) => !schema["x-tags"])
|
|
174
|
-
.map(
|
|
180
|
+
.map((item) => createDocItemFn(item, createDocItemFnContext)),
|
|
175
181
|
},
|
|
176
182
|
];
|
|
177
183
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SidebarItemDoc } from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
1
2
|
import type Request from "postman-collection";
|
|
2
3
|
import { InfoObject, OperationObject, SchemaObject, SecuritySchemeObject, TagObject } from "./openapi/types";
|
|
3
4
|
export type { PropSidebarItemCategory, SidebarItemLink, PropSidebar, PropSidebarItem, } from "@docusaurus/plugin-content-docs-types";
|
|
@@ -34,6 +35,13 @@ export interface MarkdownGenerator {
|
|
|
34
35
|
createTagPageMD?: (pageData: TagPageMetadata) => string;
|
|
35
36
|
createSchemaPageMD?: (pageData: SchemaPageMetadata) => string;
|
|
36
37
|
}
|
|
38
|
+
export type ApiDocItemGenerator = (item: ApiPageMetadata | SchemaPageMetadata, context: {
|
|
39
|
+
sidebarOptions: SidebarOptions;
|
|
40
|
+
basePath: string;
|
|
41
|
+
}) => SidebarItemDoc;
|
|
42
|
+
export interface SidebarGenerators {
|
|
43
|
+
createDocItem?: ApiDocItemGenerator;
|
|
44
|
+
}
|
|
37
45
|
export interface SidebarOptions {
|
|
38
46
|
groupPathsBy?: string;
|
|
39
47
|
categoryLinkSource?: "info" | "tag" | "auto";
|
|
@@ -42,6 +50,7 @@ export interface SidebarOptions {
|
|
|
42
50
|
};
|
|
43
51
|
sidebarCollapsible?: boolean;
|
|
44
52
|
sidebarCollapsed?: boolean;
|
|
53
|
+
sidebarGenerators?: SidebarGenerators;
|
|
45
54
|
}
|
|
46
55
|
export interface APIVersionOptions {
|
|
47
56
|
specPath: 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": "4.0
|
|
4
|
+
"version": "4.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"watch": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@docusaurus/types": "^3.0
|
|
31
|
+
"@docusaurus/types": "^3.5.0",
|
|
32
32
|
"@types/fs-extra": "^9.0.13",
|
|
33
33
|
"@types/json-pointer": "^1.0.31",
|
|
34
34
|
"@types/json-schema": "^7.0.9",
|
|
@@ -38,15 +38,15 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@apidevtools/json-schema-ref-parser": "^11.5.4",
|
|
41
|
-
"@docusaurus/plugin-content-docs": "^3.0
|
|
42
|
-
"@docusaurus/utils": "^3.0
|
|
43
|
-
"@docusaurus/utils-validation": "^3.0
|
|
41
|
+
"@docusaurus/plugin-content-docs": "^3.5.0",
|
|
42
|
+
"@docusaurus/utils": "^3.5.0",
|
|
43
|
+
"@docusaurus/utils-validation": "^3.5.0",
|
|
44
44
|
"@redocly/openapi-core": "^1.10.5",
|
|
45
|
+
"allof-merge": "^0.6.6",
|
|
45
46
|
"chalk": "^4.1.2",
|
|
46
47
|
"clsx": "^1.1.1",
|
|
47
48
|
"fs-extra": "^9.0.1",
|
|
48
49
|
"json-pointer": "^0.6.2",
|
|
49
|
-
"json-schema-merge-allof": "^0.8.1",
|
|
50
50
|
"json5": "^2.2.3",
|
|
51
51
|
"lodash": "^4.17.20",
|
|
52
52
|
"mustache": "^4.2.0",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=14"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "e7295a8aa6f3fab5ccc4f8f9ad0e6c33d785aa16"
|
|
66
66
|
}
|
package/src/index.ts
CHANGED
|
@@ -278,7 +278,11 @@ title: "{{{title}}}"
|
|
|
278
278
|
description: "{{{frontMatter.description}}}"
|
|
279
279
|
sidebar_label: "{{{title}}}"
|
|
280
280
|
hide_title: true
|
|
281
|
+
{{#schema}}
|
|
282
|
+
hide_table_of_contents: true
|
|
283
|
+
{{/schema}}
|
|
281
284
|
schema: true
|
|
285
|
+
sample: {{{frontMatter.sample}}}
|
|
282
286
|
custom_edit_url: null
|
|
283
287
|
---
|
|
284
288
|
|
|
@@ -364,6 +364,111 @@ Array [
|
|
|
364
364
|
qualifierMessage={undefined}
|
|
365
365
|
schema={{ type: \\"string\\" }}
|
|
366
366
|
></SchemaItem>;
|
|
367
|
+
",
|
|
368
|
+
"<SchemaItem
|
|
369
|
+
collapsible={false}
|
|
370
|
+
name={\\"parentProp1\\"}
|
|
371
|
+
required={false}
|
|
372
|
+
schemaName={\\"string\\"}
|
|
373
|
+
qualifierMessage={undefined}
|
|
374
|
+
schema={{ type: \\"string\\" }}
|
|
375
|
+
></SchemaItem>;
|
|
376
|
+
",
|
|
377
|
+
"<SchemaItem
|
|
378
|
+
collapsible={false}
|
|
379
|
+
name={\\"parentProp2\\"}
|
|
380
|
+
required={false}
|
|
381
|
+
schemaName={\\"string\\"}
|
|
382
|
+
qualifierMessage={undefined}
|
|
383
|
+
schema={{ type: \\"string\\" }}
|
|
384
|
+
></SchemaItem>;
|
|
385
|
+
",
|
|
386
|
+
]
|
|
387
|
+
`;
|
|
388
|
+
|
|
389
|
+
exports[`createNodes anyOf should render oneOf within anyOf 1`] = `
|
|
390
|
+
Array [
|
|
391
|
+
"<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
|
|
392
|
+
<details style={{}} className={\\"openapi-markdown__details\\"}>
|
|
393
|
+
<summary style={{}}>
|
|
394
|
+
<span className={\\"openapi-schema__container\\"}>
|
|
395
|
+
<strong className={\\"openapi-schema__property\\"}>oneOfProperty</strong>
|
|
396
|
+
<span className={\\"openapi-schema__name\\"}>object</span>
|
|
397
|
+
</span>
|
|
398
|
+
</summary>
|
|
399
|
+
<div style={{ marginLeft: \\"1rem\\" }}>
|
|
400
|
+
<div>
|
|
401
|
+
<span className={\\"badge badge--info\\"} style={{ marginBottom: \\"1rem\\" }}>
|
|
402
|
+
anyOf
|
|
403
|
+
</span>
|
|
404
|
+
<SchemaTabs>
|
|
405
|
+
<TabItem label={\\"An int or a bool\\"} value={\\"0-item-properties\\"}>
|
|
406
|
+
<div>
|
|
407
|
+
<span
|
|
408
|
+
className={\\"badge badge--info\\"}
|
|
409
|
+
style={{ marginBottom: \\"1rem\\" }}
|
|
410
|
+
>
|
|
411
|
+
oneOf
|
|
412
|
+
</span>
|
|
413
|
+
<SchemaTabs>
|
|
414
|
+
<TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
|
|
415
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
416
|
+
integer
|
|
417
|
+
</div>
|
|
418
|
+
</TabItem>
|
|
419
|
+
<TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
|
|
420
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
421
|
+
boolean
|
|
422
|
+
</div>
|
|
423
|
+
</TabItem>
|
|
424
|
+
</SchemaTabs>
|
|
425
|
+
</div>
|
|
426
|
+
</TabItem>
|
|
427
|
+
<TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
|
|
428
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
429
|
+
string
|
|
430
|
+
</div>
|
|
431
|
+
</TabItem>
|
|
432
|
+
</SchemaTabs>
|
|
433
|
+
</div>
|
|
434
|
+
</div>
|
|
435
|
+
</details>
|
|
436
|
+
</SchemaItem>;
|
|
437
|
+
",
|
|
438
|
+
]
|
|
439
|
+
`;
|
|
440
|
+
|
|
441
|
+
exports[`createNodes anyOf should render primitives within anyOf 1`] = `
|
|
442
|
+
Array [
|
|
443
|
+
"<SchemaItem collapsible={true} className={\\"schemaItem\\"}>
|
|
444
|
+
<details style={{}} className={\\"openapi-markdown__details\\"}>
|
|
445
|
+
<summary style={{}}>
|
|
446
|
+
<span className={\\"openapi-schema__container\\"}>
|
|
447
|
+
<strong className={\\"openapi-schema__property\\"}>oneOfProperty</strong>
|
|
448
|
+
<span className={\\"openapi-schema__name\\"}>object</span>
|
|
449
|
+
</span>
|
|
450
|
+
</summary>
|
|
451
|
+
<div style={{ marginLeft: \\"1rem\\" }}>
|
|
452
|
+
<div>
|
|
453
|
+
<span className={\\"badge badge--info\\"} style={{ marginBottom: \\"1rem\\" }}>
|
|
454
|
+
anyOf
|
|
455
|
+
</span>
|
|
456
|
+
<SchemaTabs>
|
|
457
|
+
<TabItem label={\\"MOD1\\"} value={\\"0-item-properties\\"}>
|
|
458
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
459
|
+
integer
|
|
460
|
+
</div>
|
|
461
|
+
</TabItem>
|
|
462
|
+
<TabItem label={\\"MOD2\\"} value={\\"1-item-properties\\"}>
|
|
463
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
464
|
+
boolean
|
|
465
|
+
</div>
|
|
466
|
+
</TabItem>
|
|
467
|
+
</SchemaTabs>
|
|
468
|
+
</div>
|
|
469
|
+
</div>
|
|
470
|
+
</details>
|
|
471
|
+
</SchemaItem>;
|
|
367
472
|
",
|
|
368
473
|
]
|
|
369
474
|
`;
|
|
@@ -624,6 +729,15 @@ Array [
|
|
|
624
729
|
qualifierMessage={undefined}
|
|
625
730
|
schema={{ type: \\"string\\" }}
|
|
626
731
|
></SchemaItem>;
|
|
732
|
+
",
|
|
733
|
+
"<SchemaItem
|
|
734
|
+
collapsible={false}
|
|
735
|
+
name={\\"type\\"}
|
|
736
|
+
required={false}
|
|
737
|
+
schemaName={\\"string\\"}
|
|
738
|
+
qualifierMessage={undefined}
|
|
739
|
+
schema={{ type: \\"string\\" }}
|
|
740
|
+
></SchemaItem>;
|
|
627
741
|
",
|
|
628
742
|
]
|
|
629
743
|
`;
|
|
@@ -710,6 +824,34 @@ Array [
|
|
|
710
824
|
qualifierMessage={undefined}
|
|
711
825
|
schema={{ type: \\"string\\" }}
|
|
712
826
|
></SchemaItem>;
|
|
827
|
+
",
|
|
828
|
+
"<div className={\\"openapi-discriminator__item openapi-schema__list-item\\"}>
|
|
829
|
+
<div>
|
|
830
|
+
<span className={\\"openapi-schema__container\\"}>
|
|
831
|
+
<strong
|
|
832
|
+
className={\\"openapi-discriminator__name openapi-schema__property\\"}
|
|
833
|
+
>
|
|
834
|
+
type
|
|
835
|
+
</strong>
|
|
836
|
+
<span className={\\"openapi-schema__name\\"}>string</span>
|
|
837
|
+
</span>
|
|
838
|
+
<div style={{ paddingLeft: \\"1rem\\" }}>
|
|
839
|
+
**Possible values:** [\`typeA\`, \`typeB\`]
|
|
840
|
+
</div>
|
|
841
|
+
<DiscriminatorTabs className={\\"openapi-tabs__discriminator\\"}>
|
|
842
|
+
<TabItem label={\\"typeA\\"} value={\\"0-item-discriminator\\"}>
|
|
843
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
844
|
+
#/definitions/TypeA
|
|
845
|
+
</div>
|
|
846
|
+
</TabItem>
|
|
847
|
+
<TabItem label={\\"typeB\\"} value={\\"1-item-discriminator\\"}>
|
|
848
|
+
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
|
|
849
|
+
#/definitions/TypeB
|
|
850
|
+
</div>
|
|
851
|
+
</TabItem>
|
|
852
|
+
</DiscriminatorTabs>
|
|
853
|
+
</div>
|
|
854
|
+
</div>;
|
|
713
855
|
",
|
|
714
856
|
]
|
|
715
857
|
`;
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { create } from "./utils";
|
|
9
|
+
|
|
10
|
+
export function createCallbackMethodEndpoint(method: String, path: String) {
|
|
11
|
+
return [
|
|
12
|
+
create("MethodEndpoint", {
|
|
13
|
+
method: method,
|
|
14
|
+
path: path,
|
|
15
|
+
context: "callback",
|
|
16
|
+
}),
|
|
17
|
+
"\n\n",
|
|
18
|
+
];
|
|
19
|
+
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
import { createCallbackMethodEndpoint } from "./createCallbackMethodEndpoint";
|
|
8
9
|
import { createDescription } from "./createDescription";
|
|
9
|
-
import { createMethodEndpoint } from "./createMethodEndpoint";
|
|
10
10
|
import { createRequestBodyDetails } from "./createRequestBodyDetails";
|
|
11
11
|
import { createStatusCodes } from "./createStatusCodes";
|
|
12
12
|
import { create } from "./utils";
|
|
@@ -78,7 +78,7 @@ export function createCallbacks({ callbacks }: Props) {
|
|
|
78
78
|
label: `${method.toUpperCase()} ${name}`,
|
|
79
79
|
value: `${method}-${name}`,
|
|
80
80
|
children: [
|
|
81
|
-
|
|
81
|
+
createCallbackMethodEndpoint(method, path),
|
|
82
82
|
// TODO: add `deprecation notice` when markdown support is added
|
|
83
83
|
createDescription(description),
|
|
84
84
|
createRequestBodyDetails({
|
|
@@ -23,8 +23,9 @@ export function createDeprecationNotice({
|
|
|
23
23
|
return guard(deprecated, () =>
|
|
24
24
|
createAdmonition({
|
|
25
25
|
children:
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
description && description.length > 0
|
|
27
|
+
? clean(description)
|
|
28
|
+
: "This endpoint has been deprecated and may be replaced or removed in future versions of the API.",
|
|
28
29
|
})
|
|
29
30
|
);
|
|
30
31
|
}
|
|
@@ -8,5 +8,12 @@
|
|
|
8
8
|
import { create } from "./utils";
|
|
9
9
|
|
|
10
10
|
export function createMethodEndpoint(method: String, path: String) {
|
|
11
|
-
return [
|
|
11
|
+
return [
|
|
12
|
+
create("MethodEndpoint", {
|
|
13
|
+
method: method,
|
|
14
|
+
path: path,
|
|
15
|
+
context: "endpoint",
|
|
16
|
+
}),
|
|
17
|
+
"\n\n",
|
|
18
|
+
];
|
|
12
19
|
}
|
|
@@ -5,53 +5,18 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import { createDetails } from "./createDetails";
|
|
9
|
-
import { createDetailsSummary } from "./createDetailsSummary";
|
|
10
8
|
import { create } from "./utils";
|
|
11
9
|
import { ApiItem } from "../types";
|
|
12
10
|
|
|
13
11
|
interface Props {
|
|
14
12
|
parameters: ApiItem["parameters"];
|
|
15
|
-
type: "path" | "query" | "header" | "cookie";
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
export function createParamsDetails({ parameters
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return createDetails({
|
|
28
|
-
className: "openapi-markdown__details",
|
|
29
|
-
"data-collapsed": false,
|
|
30
|
-
open: true,
|
|
31
|
-
style: { marginBottom: "1rem" },
|
|
32
|
-
children: [
|
|
33
|
-
createDetailsSummary({
|
|
34
|
-
children: [
|
|
35
|
-
create("h3", {
|
|
36
|
-
className: "openapi-markdown__details-summary-header-params",
|
|
37
|
-
children: `${
|
|
38
|
-
type.charAt(0).toUpperCase() + type.slice(1)
|
|
39
|
-
} Parameters`,
|
|
40
|
-
}),
|
|
41
|
-
],
|
|
42
|
-
}),
|
|
43
|
-
create("div", {
|
|
44
|
-
children: [
|
|
45
|
-
create("ul", {
|
|
46
|
-
children: params.map((param) =>
|
|
47
|
-
create("ParamsItem", {
|
|
48
|
-
className: "paramsItem",
|
|
49
|
-
param: param,
|
|
50
|
-
})
|
|
51
|
-
),
|
|
52
|
-
}),
|
|
53
|
-
],
|
|
54
|
-
}),
|
|
55
|
-
],
|
|
56
|
-
});
|
|
15
|
+
export function createParamsDetails({ parameters }: Props) {
|
|
16
|
+
return [
|
|
17
|
+
create("ParamsDetails", {
|
|
18
|
+
parameters: parameters,
|
|
19
|
+
}),
|
|
20
|
+
"\n\n",
|
|
21
|
+
];
|
|
57
22
|
}
|