docusaurus-plugin-openapi-docs 0.0.0-386 → 0.0.0-390
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/lib/markdown/createAnyOneOf.d.ts +1 -0
- package/lib/markdown/createAnyOneOf.js +84 -0
- package/lib/markdown/createSchemaDetails.js +34 -15
- package/lib/markdown/index.js +1 -0
- package/lib/markdown/utils.d.ts +1 -1
- package/lib/markdown/utils.js +4 -1
- package/lib/openapi/utils/loadAndBundleSpec.js +5 -0
- package/package.json +2 -2
- package/src/markdown/createAnyOneOf.ts +88 -0
- package/src/markdown/createSchemaDetails.ts +43 -20
- package/src/markdown/index.ts +1 -0
- package/src/markdown/utils.ts +5 -2
- package/src/openapi/utils/loadAndBundleSpec.ts +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createAnyOneOf(anyOneOf: any[], type: string): string | undefined;
|
|
@@ -0,0 +1,84 @@
|
|
|
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.createAnyOneOf = void 0;
|
|
10
|
+
const createSchemaDetails_1 = require("./createSchemaDetails");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
// {
|
|
13
|
+
// 'application/json': {
|
|
14
|
+
// schema: { properties: [Object], required: [Array], type: 'object' }
|
|
15
|
+
// }
|
|
16
|
+
// }
|
|
17
|
+
// {
|
|
18
|
+
// 'application/json': { schema: { allOf: [Array], example: [Object] } }
|
|
19
|
+
// }
|
|
20
|
+
function createAnyOneOf(anyOneOf, type) {
|
|
21
|
+
if (anyOneOf === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (anyOneOf.length === 0) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
return (0, utils_1.create)("div", {
|
|
28
|
+
children: [
|
|
29
|
+
(0, utils_1.create)("span", {
|
|
30
|
+
className: "badge badge--info",
|
|
31
|
+
children: type,
|
|
32
|
+
}),
|
|
33
|
+
(0, utils_1.create)("SchemaTabs", {
|
|
34
|
+
children: anyOneOf.map((schema, index) => {
|
|
35
|
+
// Prep schema details
|
|
36
|
+
let schemaDetails = {};
|
|
37
|
+
schemaDetails["application/json"] = {}; // Placeholder content type
|
|
38
|
+
schemaDetails["application/json"].schema = {};
|
|
39
|
+
const label = schema.title ? schema.title : `MOD${index + 1}`;
|
|
40
|
+
if (schema.properties !== undefined) {
|
|
41
|
+
schemaDetails["application/json"].schema.properties =
|
|
42
|
+
schema.properties;
|
|
43
|
+
schemaDetails["application/json"].schema.required = schema.required;
|
|
44
|
+
schemaDetails["application/json"].schema.type = "object";
|
|
45
|
+
return (0, utils_1.create)("TabItem", {
|
|
46
|
+
label: label,
|
|
47
|
+
value: `${index}-properties`,
|
|
48
|
+
children: [
|
|
49
|
+
(0, utils_1.create)("div", {
|
|
50
|
+
children: (0, createSchemaDetails_1.createSchemaDetails)({
|
|
51
|
+
title: "Schema",
|
|
52
|
+
body: {
|
|
53
|
+
content: schemaDetails,
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
if (schema.allOf !== undefined) {
|
|
61
|
+
schemaDetails["application/json"].schema.allOf = schema.allOf;
|
|
62
|
+
schemaDetails["application/json"].schema.example = schema.example;
|
|
63
|
+
return (0, utils_1.create)("TabItem", {
|
|
64
|
+
label: label,
|
|
65
|
+
value: `${index}-allOf`,
|
|
66
|
+
children: [
|
|
67
|
+
(0, utils_1.create)("div", {
|
|
68
|
+
children: (0, createSchemaDetails_1.createSchemaDetails)({
|
|
69
|
+
title: "Schema",
|
|
70
|
+
body: {
|
|
71
|
+
content: schemaDetails,
|
|
72
|
+
},
|
|
73
|
+
}),
|
|
74
|
+
}),
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}),
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
exports.createAnyOneOf = createAnyOneOf;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createSchemaDetails = void 0;
|
|
10
|
+
const createAnyOneOf_1 = require("./createAnyOneOf");
|
|
10
11
|
const createDescription_1 = require("./createDescription");
|
|
11
12
|
const createDetails_1 = require("./createDetails");
|
|
12
13
|
const createDetailsSummary_1 = require("./createDetailsSummary");
|
|
@@ -116,19 +117,21 @@ function createRows({ schema }) {
|
|
|
116
117
|
style: { marginBottom: "1rem" },
|
|
117
118
|
children: "allOf",
|
|
118
119
|
}),
|
|
119
|
-
(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
required: Array.isArray(required)
|
|
125
|
-
? required.includes(key)
|
|
126
|
-
: false,
|
|
127
|
-
})),
|
|
128
|
-
}),
|
|
120
|
+
Object.entries(properties).map(([key, val]) => createRow({
|
|
121
|
+
name: key,
|
|
122
|
+
schema: val,
|
|
123
|
+
required: Array.isArray(required) ? required.includes(key) : false,
|
|
124
|
+
})),
|
|
129
125
|
],
|
|
130
126
|
});
|
|
131
127
|
}
|
|
128
|
+
// Adds support one more level deep
|
|
129
|
+
if (schema.oneOf !== undefined) {
|
|
130
|
+
return (0, createAnyOneOf_1.createAnyOneOf)(schema.oneOf, "oneOf");
|
|
131
|
+
}
|
|
132
|
+
if (schema.anyOf !== undefined) {
|
|
133
|
+
return (0, createAnyOneOf_1.createAnyOneOf)(schema.anyOf, "anyOf");
|
|
134
|
+
}
|
|
132
135
|
// array
|
|
133
136
|
if (schema.items !== undefined) {
|
|
134
137
|
return createRows({ schema: schema.items });
|
|
@@ -150,11 +153,27 @@ function createRowsRoot({ schema }) {
|
|
|
150
153
|
// TODO: This can be a bit complicated types can be missmatched and there can be nested allOfs which need to be resolved before merging properties
|
|
151
154
|
if (schema.allOf !== undefined) {
|
|
152
155
|
const { properties, required } = resolveAllOf(schema.allOf);
|
|
153
|
-
return
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
return (0, utils_1.create)("div", {
|
|
157
|
+
children: [
|
|
158
|
+
(0, utils_1.create)("span", {
|
|
159
|
+
className: "badge badge--info",
|
|
160
|
+
style: { marginBottom: "1rem" },
|
|
161
|
+
children: "allOf",
|
|
162
|
+
}),
|
|
163
|
+
Object.entries(properties).map(([key, val]) => createRow({
|
|
164
|
+
name: key,
|
|
165
|
+
schema: val,
|
|
166
|
+
required: Array.isArray(required) ? required.includes(key) : false,
|
|
167
|
+
})),
|
|
168
|
+
],
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// TODO: This is top-level only - add support for nested oneOf/anyOf
|
|
172
|
+
if (schema.oneOf !== undefined) {
|
|
173
|
+
return (0, createAnyOneOf_1.createAnyOneOf)(schema.oneOf, "oneOf");
|
|
174
|
+
}
|
|
175
|
+
if (schema.anyOf !== undefined) {
|
|
176
|
+
return (0, createAnyOneOf_1.createAnyOneOf)(schema.anyOf, "anyOf");
|
|
158
177
|
}
|
|
159
178
|
// array
|
|
160
179
|
if (schema.items !== undefined) {
|
package/lib/markdown/index.js
CHANGED
|
@@ -24,6 +24,7 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
24
24
|
`import ParamsItem from "@theme/ParamsItem";\n`,
|
|
25
25
|
`import SchemaItem from "@theme/SchemaItem"\n`,
|
|
26
26
|
`import ApiTabs from "@theme/ApiTabs";\n`,
|
|
27
|
+
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
27
28
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
28
29
|
`## ${(0, lodash_1.escape)(title)}\n\n`,
|
|
29
30
|
(0, createDeprecationNotice_1.createDeprecationNotice)({ deprecated, description: deprecatedDescription }),
|
package/lib/markdown/utils.d.ts
CHANGED
package/lib/markdown/utils.js
CHANGED
|
@@ -26,7 +26,10 @@ function guard(value, cb) {
|
|
|
26
26
|
exports.guard = guard;
|
|
27
27
|
function render(children) {
|
|
28
28
|
if (Array.isArray(children)) {
|
|
29
|
-
|
|
29
|
+
const filteredChildren = children.filter((c) => c !== undefined);
|
|
30
|
+
return filteredChildren
|
|
31
|
+
.map((i) => (Array.isArray(i) ? i.join("") : i))
|
|
32
|
+
.join("");
|
|
30
33
|
}
|
|
31
34
|
return children !== null && children !== void 0 ? children : "";
|
|
32
35
|
}
|
|
@@ -21,6 +21,11 @@ async function resolveJsonRefs(specUrlOrObject) {
|
|
|
21
21
|
try {
|
|
22
22
|
let schema = await json_schema_ref_parser_1.default.dereference(specUrlOrObject, {
|
|
23
23
|
continueOnError: true,
|
|
24
|
+
resolve: {
|
|
25
|
+
http: {
|
|
26
|
+
timeout: 15000, // 15 sec timeout
|
|
27
|
+
},
|
|
28
|
+
},
|
|
24
29
|
dereference: {
|
|
25
30
|
circular: "ignore",
|
|
26
31
|
},
|
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-
|
|
4
|
+
"version": "0.0.0-390",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">=14"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "0773c12511d7ba04e31ad3420ba9ec084c517690"
|
|
67
67
|
}
|
|
@@ -0,0 +1,88 @@
|
|
|
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 { createSchemaDetails } from "./createSchemaDetails";
|
|
9
|
+
import { create } from "./utils";
|
|
10
|
+
|
|
11
|
+
// {
|
|
12
|
+
// 'application/json': {
|
|
13
|
+
// schema: { properties: [Object], required: [Array], type: 'object' }
|
|
14
|
+
// }
|
|
15
|
+
// }
|
|
16
|
+
// {
|
|
17
|
+
// 'application/json': { schema: { allOf: [Array], example: [Object] } }
|
|
18
|
+
// }
|
|
19
|
+
|
|
20
|
+
export function createAnyOneOf(anyOneOf: any[], type: string) {
|
|
21
|
+
if (anyOneOf === undefined) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (anyOneOf.length === 0) {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return create("div", {
|
|
30
|
+
children: [
|
|
31
|
+
create("span", {
|
|
32
|
+
className: "badge badge--info",
|
|
33
|
+
children: type,
|
|
34
|
+
}),
|
|
35
|
+
create("SchemaTabs", {
|
|
36
|
+
children: anyOneOf.map((schema, index) => {
|
|
37
|
+
// Prep schema details
|
|
38
|
+
let schemaDetails: any = {};
|
|
39
|
+
schemaDetails["application/json"] = {}; // Placeholder content type
|
|
40
|
+
schemaDetails["application/json"].schema = {};
|
|
41
|
+
const label = schema.title ? schema.title : `MOD${index + 1}`;
|
|
42
|
+
|
|
43
|
+
if (schema.properties !== undefined) {
|
|
44
|
+
schemaDetails["application/json"].schema.properties =
|
|
45
|
+
schema.properties;
|
|
46
|
+
schemaDetails["application/json"].schema.required = schema.required;
|
|
47
|
+
schemaDetails["application/json"].schema.type = "object";
|
|
48
|
+
return create("TabItem", {
|
|
49
|
+
label: label,
|
|
50
|
+
value: `${index}-properties`,
|
|
51
|
+
children: [
|
|
52
|
+
create("div", {
|
|
53
|
+
children: createSchemaDetails({
|
|
54
|
+
title: "Schema",
|
|
55
|
+
body: {
|
|
56
|
+
content: schemaDetails,
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
}),
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (schema.allOf !== undefined) {
|
|
65
|
+
schemaDetails["application/json"].schema.allOf = schema.allOf;
|
|
66
|
+
schemaDetails["application/json"].schema.example = schema.example;
|
|
67
|
+
return create("TabItem", {
|
|
68
|
+
label: label,
|
|
69
|
+
value: `${index}-allOf`,
|
|
70
|
+
children: [
|
|
71
|
+
create("div", {
|
|
72
|
+
children: createSchemaDetails({
|
|
73
|
+
title: "Schema",
|
|
74
|
+
body: {
|
|
75
|
+
content: schemaDetails,
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return undefined;
|
|
84
|
+
}),
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
8
|
import { MediaTypeObject, SchemaObject } from "../openapi/types";
|
|
9
|
+
import { createAnyOneOf } from "./createAnyOneOf";
|
|
9
10
|
import { createDescription } from "./createDescription";
|
|
10
11
|
import { createDetails } from "./createDetails";
|
|
11
12
|
import { createDetailsSummary } from "./createDetailsSummary";
|
|
@@ -140,22 +141,26 @@ function createRows({ schema }: RowsProps): string | undefined {
|
|
|
140
141
|
style: { marginBottom: "1rem" },
|
|
141
142
|
children: "allOf",
|
|
142
143
|
}),
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
? required.includes(key)
|
|
151
|
-
: false,
|
|
152
|
-
})
|
|
153
|
-
),
|
|
154
|
-
}),
|
|
144
|
+
Object.entries(properties).map(([key, val]) =>
|
|
145
|
+
createRow({
|
|
146
|
+
name: key,
|
|
147
|
+
schema: val,
|
|
148
|
+
required: Array.isArray(required) ? required.includes(key) : false,
|
|
149
|
+
})
|
|
150
|
+
),
|
|
155
151
|
],
|
|
156
152
|
});
|
|
157
153
|
}
|
|
158
154
|
|
|
155
|
+
// Adds support one more level deep
|
|
156
|
+
if (schema.oneOf !== undefined) {
|
|
157
|
+
return createAnyOneOf(schema.oneOf, "oneOf");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (schema.anyOf !== undefined) {
|
|
161
|
+
return createAnyOneOf(schema.anyOf, "anyOf");
|
|
162
|
+
}
|
|
163
|
+
|
|
159
164
|
// array
|
|
160
165
|
if (schema.items !== undefined) {
|
|
161
166
|
return createRows({ schema: schema.items });
|
|
@@ -169,7 +174,7 @@ interface RowsRootProps {
|
|
|
169
174
|
schema: SchemaObject;
|
|
170
175
|
}
|
|
171
176
|
|
|
172
|
-
function createRowsRoot({ schema }: RowsRootProps) {
|
|
177
|
+
function createRowsRoot({ schema }: RowsRootProps): any {
|
|
173
178
|
// object
|
|
174
179
|
if (schema.properties !== undefined) {
|
|
175
180
|
return Object.entries(schema.properties).map(([key, val]) =>
|
|
@@ -186,13 +191,31 @@ function createRowsRoot({ schema }: RowsRootProps) {
|
|
|
186
191
|
// TODO: This can be a bit complicated types can be missmatched and there can be nested allOfs which need to be resolved before merging properties
|
|
187
192
|
if (schema.allOf !== undefined) {
|
|
188
193
|
const { properties, required } = resolveAllOf(schema.allOf);
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
return create("div", {
|
|
195
|
+
children: [
|
|
196
|
+
create("span", {
|
|
197
|
+
className: "badge badge--info",
|
|
198
|
+
style: { marginBottom: "1rem" },
|
|
199
|
+
children: "allOf",
|
|
200
|
+
}),
|
|
201
|
+
Object.entries(properties).map(([key, val]) =>
|
|
202
|
+
createRow({
|
|
203
|
+
name: key,
|
|
204
|
+
schema: val,
|
|
205
|
+
required: Array.isArray(required) ? required.includes(key) : false,
|
|
206
|
+
})
|
|
207
|
+
),
|
|
208
|
+
],
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// TODO: This is top-level only - add support for nested oneOf/anyOf
|
|
213
|
+
if (schema.oneOf !== undefined) {
|
|
214
|
+
return createAnyOneOf(schema.oneOf, "oneOf");
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (schema.anyOf !== undefined) {
|
|
218
|
+
return createAnyOneOf(schema.anyOf, "anyOf");
|
|
196
219
|
}
|
|
197
220
|
|
|
198
221
|
// array
|
package/src/markdown/index.ts
CHANGED
|
@@ -40,6 +40,7 @@ export function createApiPageMD({
|
|
|
40
40
|
`import ParamsItem from "@theme/ParamsItem";\n`,
|
|
41
41
|
`import SchemaItem from "@theme/SchemaItem"\n`,
|
|
42
42
|
`import ApiTabs from "@theme/ApiTabs";\n`,
|
|
43
|
+
`import SchemaTabs from "@theme/SchemaTabs";\n`,
|
|
43
44
|
`import TabItem from "@theme/TabItem";\n\n`,
|
|
44
45
|
`## ${escape(title)}\n\n`,
|
|
45
46
|
createDeprecationNotice({ deprecated, description: deprecatedDescription }),
|
package/src/markdown/utils.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
export type Children = string | undefined | (string | undefined)[];
|
|
8
|
+
export type Children = string | undefined | (string | string[] | undefined)[];
|
|
9
9
|
|
|
10
10
|
export type Props = Record<string, any> & { children?: Children };
|
|
11
11
|
|
|
@@ -33,7 +33,10 @@ export function guard<T>(
|
|
|
33
33
|
|
|
34
34
|
export function render(children: Children): string {
|
|
35
35
|
if (Array.isArray(children)) {
|
|
36
|
-
|
|
36
|
+
const filteredChildren = children.filter((c) => c !== undefined);
|
|
37
|
+
return filteredChildren
|
|
38
|
+
.map((i: any) => (Array.isArray(i) ? i.join("") : i))
|
|
39
|
+
.join("");
|
|
37
40
|
}
|
|
38
41
|
return children ?? "";
|
|
39
42
|
}
|
|
@@ -21,6 +21,11 @@ async function resolveJsonRefs(specUrlOrObject: object | string) {
|
|
|
21
21
|
try {
|
|
22
22
|
let schema = await $RefParser.dereference(specUrlOrObject, {
|
|
23
23
|
continueOnError: true,
|
|
24
|
+
resolve: {
|
|
25
|
+
http: {
|
|
26
|
+
timeout: 15000, // 15 sec timeout
|
|
27
|
+
},
|
|
28
|
+
},
|
|
24
29
|
dereference: {
|
|
25
30
|
circular: "ignore",
|
|
26
31
|
},
|