docusaurus-plugin-openapi-docs 0.0.0-395 → 0.0.0-396
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.js +2 -38
- package/lib/markdown/createSchemaDetails.d.ts +5 -1
- package/lib/markdown/createSchemaDetails.js +98 -40
- package/lib/markdown/schema.js +29 -12
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +26 -25
- package/lib/openapi/types.d.ts +1 -0
- package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
- package/lib/openapi/utils/{loadAndBundleSpec.js → loadAndResolveSpec.js} +61 -28
- package/package.json +2 -2
- package/src/markdown/createAnyOneOf.ts +3 -40
- package/src/markdown/createSchemaDetails.ts +123 -47
- package/src/markdown/schema.ts +32 -11
- package/src/openapi/openapi.ts +38 -37
- package/src/openapi/types.ts +1 -0
- package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
- package/src/openapi/utils/loadAndBundleSpec.ts +0 -93
|
@@ -9,14 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.createAnyOneOf = void 0;
|
|
10
10
|
const createSchemaDetails_1 = require("./createSchemaDetails");
|
|
11
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
12
|
function createAnyOneOf(anyOneOf, type) {
|
|
21
13
|
if (anyOneOf === undefined) {
|
|
22
14
|
return undefined;
|
|
@@ -32,47 +24,19 @@ function createAnyOneOf(anyOneOf, type) {
|
|
|
32
24
|
}),
|
|
33
25
|
(0, utils_1.create)("SchemaTabs", {
|
|
34
26
|
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
27
|
const label = schema.title ? schema.title : `MOD${index + 1}`;
|
|
40
28
|
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
29
|
return (0, utils_1.create)("TabItem", {
|
|
46
30
|
label: label,
|
|
47
31
|
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
|
-
],
|
|
32
|
+
children: [(0, createSchemaDetails_1.createRows)({ schema: schema })],
|
|
58
33
|
});
|
|
59
34
|
}
|
|
60
35
|
if (schema.allOf !== undefined) {
|
|
61
|
-
schemaDetails["application/json"].schema.allOf = schema.allOf;
|
|
62
|
-
schemaDetails["application/json"].schema.example = schema.example;
|
|
63
36
|
return (0, utils_1.create)("TabItem", {
|
|
64
37
|
label: label,
|
|
65
38
|
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
|
-
],
|
|
39
|
+
children: [(0, createSchemaDetails_1.createRows)({ schema: schema })],
|
|
76
40
|
});
|
|
77
41
|
}
|
|
78
42
|
return undefined;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { MediaTypeObject } from "../openapi/types";
|
|
1
|
+
import { MediaTypeObject, SchemaObject } from "../openapi/types";
|
|
2
|
+
interface RowsProps {
|
|
3
|
+
schema: SchemaObject;
|
|
4
|
+
}
|
|
5
|
+
export declare function createRows({ schema }: RowsProps): string | undefined;
|
|
2
6
|
interface Props {
|
|
3
7
|
style?: any;
|
|
4
8
|
title: string;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createSchemaDetails = void 0;
|
|
9
|
+
exports.createSchemaDetails = exports.createRows = void 0;
|
|
10
10
|
const createAnyOneOf_1 = require("./createAnyOneOf");
|
|
11
11
|
const createDescription_1 = require("./createDescription");
|
|
12
12
|
const createDetails_1 = require("./createDetails");
|
|
@@ -16,7 +16,6 @@ const utils_1 = require("./utils");
|
|
|
16
16
|
const mergeAllOf = require("json-schema-merge-allof");
|
|
17
17
|
function resolveAllOf(allOf) {
|
|
18
18
|
// Use external library to resolve and merge nested allOf schemas
|
|
19
|
-
let properties = {};
|
|
20
19
|
const mergedSchemas = mergeAllOf(allOf, {
|
|
21
20
|
resolvers: {
|
|
22
21
|
readOnly: function () {
|
|
@@ -27,9 +26,6 @@ function resolveAllOf(allOf) {
|
|
|
27
26
|
},
|
|
28
27
|
},
|
|
29
28
|
});
|
|
30
|
-
if (mergedSchemas.properties) {
|
|
31
|
-
properties = mergedSchemas.properties;
|
|
32
|
-
}
|
|
33
29
|
const required = allOf.reduce((acc, cur) => {
|
|
34
30
|
if (Array.isArray(cur.required)) {
|
|
35
31
|
const next = [...acc, ...cur.required];
|
|
@@ -37,10 +33,55 @@ function resolveAllOf(allOf) {
|
|
|
37
33
|
}
|
|
38
34
|
return acc;
|
|
39
35
|
}, []);
|
|
40
|
-
return {
|
|
36
|
+
return { mergedSchemas, required };
|
|
41
37
|
}
|
|
42
38
|
function createRow({ name, schema, required }) {
|
|
43
|
-
const schemaName = (0, schema_1.getSchemaName)(schema
|
|
39
|
+
const schemaName = (0, schema_1.getSchemaName)(schema);
|
|
40
|
+
// array
|
|
41
|
+
if (schema.type === "array" && schema.items) {
|
|
42
|
+
return (0, utils_1.create)("SchemaItem", {
|
|
43
|
+
collapsible: true,
|
|
44
|
+
className: "schemaItem",
|
|
45
|
+
children: [
|
|
46
|
+
(0, createDetails_1.createDetails)({
|
|
47
|
+
children: [
|
|
48
|
+
(0, createDetailsSummary_1.createDetailsSummary)({
|
|
49
|
+
children: [
|
|
50
|
+
(0, utils_1.create)("strong", { children: name }),
|
|
51
|
+
(0, utils_1.create)("span", {
|
|
52
|
+
style: { opacity: "0.6" },
|
|
53
|
+
children: ` ${schemaName}`,
|
|
54
|
+
}),
|
|
55
|
+
(0, utils_1.guard)(required, () => [
|
|
56
|
+
(0, utils_1.create)("strong", {
|
|
57
|
+
style: {
|
|
58
|
+
fontSize: "var(--ifm-code-font-size)",
|
|
59
|
+
color: "var(--openapi-required)",
|
|
60
|
+
},
|
|
61
|
+
children: " required",
|
|
62
|
+
}),
|
|
63
|
+
]),
|
|
64
|
+
],
|
|
65
|
+
}),
|
|
66
|
+
(0, utils_1.create)("div", {
|
|
67
|
+
style: { marginLeft: "1rem" },
|
|
68
|
+
children: [
|
|
69
|
+
(0, utils_1.guard)((0, schema_1.getQualifierMessage)(schema), (message) => (0, utils_1.create)("div", {
|
|
70
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
71
|
+
children: (0, createDescription_1.createDescription)(message),
|
|
72
|
+
})),
|
|
73
|
+
(0, utils_1.guard)(schema.description, (description) => (0, utils_1.create)("div", {
|
|
74
|
+
style: { marginTop: ".5rem", marginBottom: ".5rem" },
|
|
75
|
+
children: (0, createDescription_1.createDescription)(description),
|
|
76
|
+
})),
|
|
77
|
+
createRows({ schema: schema.items }),
|
|
78
|
+
],
|
|
79
|
+
}),
|
|
80
|
+
],
|
|
81
|
+
}),
|
|
82
|
+
],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
44
85
|
if (schemaName && (schemaName === "object" || schemaName === "object[]")) {
|
|
45
86
|
return (0, utils_1.create)("SchemaItem", {
|
|
46
87
|
collapsible: true,
|
|
@@ -85,16 +126,25 @@ function createRow({ name, schema, required }) {
|
|
|
85
126
|
],
|
|
86
127
|
});
|
|
87
128
|
}
|
|
129
|
+
// primitive
|
|
88
130
|
return (0, utils_1.create)("SchemaItem", {
|
|
89
131
|
collapsible: false,
|
|
90
132
|
name,
|
|
91
133
|
required,
|
|
92
134
|
schemaDescription: schema.description,
|
|
93
|
-
schemaName:
|
|
135
|
+
schemaName: schemaName,
|
|
94
136
|
qualifierMessage: (0, schema_1.getQualifierMessage)(schema),
|
|
95
137
|
});
|
|
96
138
|
}
|
|
97
139
|
function createRows({ schema }) {
|
|
140
|
+
// oneOf
|
|
141
|
+
if (schema.oneOf !== undefined) {
|
|
142
|
+
return (0, createAnyOneOf_1.createAnyOneOf)(schema.oneOf, "oneOf");
|
|
143
|
+
}
|
|
144
|
+
// anyOf
|
|
145
|
+
if (schema.anyOf !== undefined) {
|
|
146
|
+
return (0, createAnyOneOf_1.createAnyOneOf)(schema.anyOf, "anyOf");
|
|
147
|
+
}
|
|
98
148
|
// object
|
|
99
149
|
if (schema.properties !== undefined) {
|
|
100
150
|
return (0, utils_1.create)("ul", {
|
|
@@ -107,38 +157,43 @@ function createRows({ schema }) {
|
|
|
107
157
|
})),
|
|
108
158
|
});
|
|
109
159
|
}
|
|
110
|
-
//
|
|
160
|
+
// allOf
|
|
111
161
|
if (schema.allOf !== undefined) {
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
162
|
+
const { mergedSchemas, required, } = resolveAllOf(schema.allOf);
|
|
163
|
+
// Adds support one more level deep
|
|
164
|
+
if (mergedSchemas.oneOf !== undefined) {
|
|
165
|
+
return (0, createAnyOneOf_1.createAnyOneOf)(mergedSchemas.oneOf, "oneOf");
|
|
166
|
+
}
|
|
167
|
+
if (mergedSchemas.anyOf !== undefined) {
|
|
168
|
+
return (0, createAnyOneOf_1.createAnyOneOf)(mergedSchemas.anyOf, "anyOf");
|
|
169
|
+
}
|
|
170
|
+
// array
|
|
171
|
+
if (mergedSchemas.items !== undefined) {
|
|
172
|
+
return createRows({ schema: schema.items });
|
|
173
|
+
}
|
|
174
|
+
if (mergedSchemas.properties !== undefined) {
|
|
175
|
+
return (0, utils_1.create)("div", {
|
|
176
|
+
children: [
|
|
177
|
+
(0, utils_1.create)("span", {
|
|
178
|
+
className: "badge badge--info",
|
|
179
|
+
style: { marginBottom: "1rem" },
|
|
180
|
+
children: "allOf",
|
|
181
|
+
}),
|
|
182
|
+
Object.entries(mergedSchemas.properties).map(([key, val]) => createRow({
|
|
183
|
+
name: key,
|
|
184
|
+
schema: val,
|
|
185
|
+
required: Array.isArray(required)
|
|
186
|
+
? required.includes(key)
|
|
187
|
+
: false,
|
|
188
|
+
})),
|
|
189
|
+
],
|
|
190
|
+
});
|
|
191
|
+
}
|
|
138
192
|
}
|
|
139
193
|
// primitive
|
|
140
194
|
return undefined;
|
|
141
195
|
}
|
|
196
|
+
exports.createRows = createRows;
|
|
142
197
|
function createRowsRoot({ schema }) {
|
|
143
198
|
// object
|
|
144
199
|
if (schema.properties !== undefined) {
|
|
@@ -150,9 +205,9 @@ function createRowsRoot({ schema }) {
|
|
|
150
205
|
: false,
|
|
151
206
|
}));
|
|
152
207
|
}
|
|
153
|
-
//
|
|
208
|
+
// allOf
|
|
154
209
|
if (schema.allOf !== undefined) {
|
|
155
|
-
const {
|
|
210
|
+
const { mergedSchemas, required, } = resolveAllOf(schema.allOf);
|
|
156
211
|
return (0, utils_1.create)("div", {
|
|
157
212
|
children: [
|
|
158
213
|
(0, utils_1.create)("span", {
|
|
@@ -160,18 +215,21 @@ function createRowsRoot({ schema }) {
|
|
|
160
215
|
style: { marginBottom: "1rem" },
|
|
161
216
|
children: "allOf",
|
|
162
217
|
}),
|
|
163
|
-
Object.entries(properties).map(([key, val]) => createRow({
|
|
218
|
+
Object.entries(mergedSchemas.properties).map(([key, val]) => createRow({
|
|
164
219
|
name: key,
|
|
165
220
|
schema: val,
|
|
166
|
-
required: Array.isArray(required)
|
|
221
|
+
required: Array.isArray(required)
|
|
222
|
+
? required.includes(key)
|
|
223
|
+
: false,
|
|
167
224
|
})),
|
|
168
225
|
],
|
|
169
226
|
});
|
|
170
227
|
}
|
|
171
|
-
//
|
|
228
|
+
// oneOf
|
|
172
229
|
if (schema.oneOf !== undefined) {
|
|
173
230
|
return (0, createAnyOneOf_1.createAnyOneOf)(schema.oneOf, "oneOf");
|
|
174
231
|
}
|
|
232
|
+
// anyOf
|
|
175
233
|
if (schema.anyOf !== undefined) {
|
|
176
234
|
return (0, createAnyOneOf_1.createAnyOneOf)(schema.anyOf, "anyOf");
|
|
177
235
|
}
|
package/lib/markdown/schema.js
CHANGED
|
@@ -8,22 +8,34 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.getQualifierMessage = exports.getSchemaName = void 0;
|
|
10
10
|
function prettyName(schema, circular) {
|
|
11
|
-
var _a, _b, _c;
|
|
12
|
-
if (schema.$ref) {
|
|
13
|
-
return schema.$ref.replace("#/components/schemas/", "") + circular
|
|
14
|
-
? " (circular)"
|
|
15
|
-
: "";
|
|
16
|
-
}
|
|
11
|
+
var _a, _b, _c, _d, _e;
|
|
17
12
|
if (schema.format) {
|
|
18
13
|
return schema.format;
|
|
19
14
|
}
|
|
20
15
|
if (schema.allOf) {
|
|
16
|
+
if (typeof schema.allOf[0] === "string") {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
if (schema.allOf[0].includes("circular")) {
|
|
19
|
+
return schema.allOf[0];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return "object";
|
|
23
|
+
}
|
|
24
|
+
if (schema.oneOf) {
|
|
25
|
+
return "object";
|
|
26
|
+
}
|
|
27
|
+
if (schema.anyOf) {
|
|
21
28
|
return "object";
|
|
22
29
|
}
|
|
23
30
|
if (schema.type === "object") {
|
|
24
31
|
return (_b = (_a = schema.xml) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : schema.type;
|
|
32
|
+
// return schema.type;
|
|
25
33
|
}
|
|
26
|
-
|
|
34
|
+
if (schema.type === "array") {
|
|
35
|
+
return (_d = (_c = schema.xml) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : schema.type;
|
|
36
|
+
// return schema.type;
|
|
37
|
+
}
|
|
38
|
+
return (_e = schema.title) !== null && _e !== void 0 ? _e : schema.type;
|
|
27
39
|
}
|
|
28
40
|
function getSchemaName(schema, circular) {
|
|
29
41
|
var _a;
|
|
@@ -35,8 +47,6 @@ function getSchemaName(schema, circular) {
|
|
|
35
47
|
exports.getSchemaName = getSchemaName;
|
|
36
48
|
function getQualifierMessage(schema) {
|
|
37
49
|
// TODO:
|
|
38
|
-
// - maxItems
|
|
39
|
-
// - minItems
|
|
40
50
|
// - uniqueItems
|
|
41
51
|
// - maxProperties
|
|
42
52
|
// - minProperties
|
|
@@ -44,9 +54,10 @@ function getQualifierMessage(schema) {
|
|
|
44
54
|
if (!schema) {
|
|
45
55
|
return undefined;
|
|
46
56
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
// TODO: This doesn't seem right
|
|
58
|
+
// if (schema.items) {
|
|
59
|
+
// return getQualifierMessage(schema.items);
|
|
60
|
+
// }
|
|
50
61
|
let message = "**Possible values:** ";
|
|
51
62
|
let qualifierGroups = [];
|
|
52
63
|
if (schema.minLength || schema.maxLength) {
|
|
@@ -92,6 +103,12 @@ function getQualifierMessage(schema) {
|
|
|
92
103
|
if (schema.enum) {
|
|
93
104
|
qualifierGroups.push(`[${schema.enum.map((e) => `\`${e}\``).join(", ")}]`);
|
|
94
105
|
}
|
|
106
|
+
if (schema.minItems) {
|
|
107
|
+
qualifierGroups.push(`items >= ${schema.minItems}`);
|
|
108
|
+
}
|
|
109
|
+
if (schema.maxItems) {
|
|
110
|
+
qualifierGroups.push(`items <= ${schema.maxItems}`);
|
|
111
|
+
}
|
|
95
112
|
if (qualifierGroups.length === 0) {
|
|
96
113
|
return undefined;
|
|
97
114
|
}
|
package/lib/openapi/openapi.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ApiMetadata, APIOptions, SidebarOptions } from "../types";
|
|
2
|
-
import {
|
|
2
|
+
import { OpenApiObject, TagObject } from "./types";
|
|
3
3
|
interface OpenApiFiles {
|
|
4
4
|
source: string;
|
|
5
5
|
sourceDirName: string;
|
|
6
|
-
data:
|
|
6
|
+
data: OpenApiObject;
|
|
7
7
|
}
|
|
8
8
|
export declare function readOpenapiFiles(openapiPath: string, options: APIOptions): Promise<OpenApiFiles[]>;
|
|
9
9
|
export declare function processOpenapiFiles(files: OpenApiFiles[], sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
10
|
-
export declare function processOpenapiFile(
|
|
10
|
+
export declare function processOpenapiFile(openapiData: OpenApiObject, sidebarOptions: SidebarOptions): Promise<[ApiMetadata[], TagObject[]]>;
|
|
11
11
|
export declare function getTagDisplayName(tagName: string, tags: TagObject[]): string;
|
|
12
12
|
export {};
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -16,18 +16,10 @@ 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 json_refs_1 = __importDefault(require("json-refs"));
|
|
20
19
|
const lodash_1 = require("lodash");
|
|
21
20
|
const index_1 = require("../index");
|
|
22
21
|
const createExample_1 = require("./createExample");
|
|
23
|
-
const
|
|
24
|
-
/**
|
|
25
|
-
* Finds any reference objects in the OpenAPI definition and resolves them to a finalized value.
|
|
26
|
-
*/
|
|
27
|
-
async function resolveRefs(openapiData) {
|
|
28
|
-
const { resolved } = await json_refs_1.default.resolveRefs(openapiData);
|
|
29
|
-
return resolved;
|
|
30
|
-
}
|
|
22
|
+
const loadAndResolveSpec_1 = require("./utils/loadAndResolveSpec");
|
|
31
23
|
/**
|
|
32
24
|
* Convenience function for converting raw JSON to a Postman Collection object.
|
|
33
25
|
*/
|
|
@@ -48,7 +40,7 @@ function jsonToCollection(data) {
|
|
|
48
40
|
*/
|
|
49
41
|
async function createPostmanCollection(openapiData) {
|
|
50
42
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
51
|
-
const data =
|
|
43
|
+
const data = openapiData;
|
|
52
44
|
// Including `servers` breaks postman, so delete all of them.
|
|
53
45
|
delete data.servers;
|
|
54
46
|
for (let pathItemObject of Object.values(data.paths)) {
|
|
@@ -189,9 +181,6 @@ function bindCollectionToApiItems(items, postmanCollection) {
|
|
|
189
181
|
});
|
|
190
182
|
}
|
|
191
183
|
async function readOpenapiFiles(openapiPath, options) {
|
|
192
|
-
// TODO: determine if this should be an API option
|
|
193
|
-
// Forces the json-schema-ref-parser
|
|
194
|
-
const parseJsonRefs = true;
|
|
195
184
|
if (!(0, index_1.isURL)(openapiPath)) {
|
|
196
185
|
const stat = await fs_extra_1.default.lstat(openapiPath);
|
|
197
186
|
if (stat.isDirectory()) {
|
|
@@ -206,7 +195,7 @@ async function readOpenapiFiles(openapiPath, options) {
|
|
|
206
195
|
return Promise.all(sources.map(async (source) => {
|
|
207
196
|
// TODO: make a function for this
|
|
208
197
|
const fullPath = path_1.default.join(openapiPath, source);
|
|
209
|
-
const data = (await (0,
|
|
198
|
+
const data = (await (0, loadAndResolveSpec_1.loadAndResolveSpec)(fullPath));
|
|
210
199
|
return {
|
|
211
200
|
source: fullPath,
|
|
212
201
|
sourceDirName: path_1.default.dirname(source),
|
|
@@ -215,7 +204,7 @@ async function readOpenapiFiles(openapiPath, options) {
|
|
|
215
204
|
}));
|
|
216
205
|
}
|
|
217
206
|
}
|
|
218
|
-
const data = (await (0,
|
|
207
|
+
const data = (await (0, loadAndResolveSpec_1.loadAndResolveSpec)(openapiPath));
|
|
219
208
|
return [
|
|
220
209
|
{
|
|
221
210
|
source: openapiPath,
|
|
@@ -227,27 +216,39 @@ async function readOpenapiFiles(openapiPath, options) {
|
|
|
227
216
|
exports.readOpenapiFiles = readOpenapiFiles;
|
|
228
217
|
async function processOpenapiFiles(files, sidebarOptions) {
|
|
229
218
|
const promises = files.map(async (file) => {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
219
|
+
if (file.data !== undefined) {
|
|
220
|
+
const processedFile = await processOpenapiFile(file.data, sidebarOptions);
|
|
221
|
+
const itemsObjectsArray = processedFile[0].map((item) => ({
|
|
222
|
+
...item,
|
|
223
|
+
}));
|
|
224
|
+
const tags = processedFile[1];
|
|
225
|
+
return [itemsObjectsArray, tags];
|
|
226
|
+
}
|
|
227
|
+
console.warn(chalk_1.default.yellow(`WARNING: the following OpenAPI spec returned undefined: ${file.source}`));
|
|
228
|
+
return [];
|
|
236
229
|
});
|
|
237
230
|
const metadata = await Promise.all(promises);
|
|
238
231
|
const items = metadata
|
|
239
232
|
.map(function (x) {
|
|
240
233
|
return x[0];
|
|
241
234
|
})
|
|
242
|
-
.flat()
|
|
243
|
-
|
|
235
|
+
.flat()
|
|
236
|
+
.filter(function (x) {
|
|
237
|
+
// Remove undefined items due to transient parsing errors
|
|
238
|
+
return x !== undefined;
|
|
239
|
+
});
|
|
240
|
+
const tags = metadata
|
|
241
|
+
.map(function (x) {
|
|
244
242
|
return x[1];
|
|
243
|
+
})
|
|
244
|
+
.filter(function (x) {
|
|
245
|
+
// Remove undefined tags due to transient parsing errors
|
|
246
|
+
return x !== undefined;
|
|
245
247
|
});
|
|
246
248
|
return [items, tags];
|
|
247
249
|
}
|
|
248
250
|
exports.processOpenapiFiles = processOpenapiFiles;
|
|
249
|
-
async function processOpenapiFile(
|
|
250
|
-
const openapiData = await resolveRefs(openapiDataWithRefs);
|
|
251
|
+
async function processOpenapiFile(openapiData, sidebarOptions) {
|
|
251
252
|
const postmanCollection = await createPostmanCollection(openapiData);
|
|
252
253
|
const items = createItems(openapiData, sidebarOptions);
|
|
253
254
|
bindCollectionToApiItems(items, postmanCollection);
|
package/lib/openapi/types.d.ts
CHANGED
|
@@ -9,25 +9,62 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
9
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
// @ts-nocheck
|
|
12
|
+
exports.loadAndResolveSpec = exports.convertSwagger2OpenAPI = void 0;
|
|
14
13
|
const json_schema_ref_parser_1 = __importDefault(require("@apidevtools/json-schema-ref-parser"));
|
|
15
|
-
const
|
|
16
|
-
const config_1 = require("@redocly/openapi-core/lib/config/config");
|
|
14
|
+
const openapi_core_1 = require("@redocly/openapi-core");
|
|
17
15
|
const chalk_1 = __importDefault(require("chalk"));
|
|
16
|
+
// @ts-ignore
|
|
18
17
|
const swagger2openapi_1 = require("swagger2openapi");
|
|
18
|
+
function serializer(replacer, cycleReplacer) {
|
|
19
|
+
var stack = [], keys = [];
|
|
20
|
+
if (cycleReplacer === undefined)
|
|
21
|
+
cycleReplacer = function (key, value) {
|
|
22
|
+
if (stack[0] === value)
|
|
23
|
+
return "circular()";
|
|
24
|
+
return value.title ? `circular(${value.title})` : "circular()";
|
|
25
|
+
};
|
|
26
|
+
return function (key, value) {
|
|
27
|
+
if (stack.length > 0) {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
var thisPos = stack.indexOf(this);
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
|
|
32
|
+
~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
if (~stack.indexOf(value))
|
|
35
|
+
value = cycleReplacer.call(this, key, value);
|
|
36
|
+
}
|
|
37
|
+
else
|
|
38
|
+
stack.push(value);
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
return replacer === undefined ? value : replacer.call(this, key, value);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function convertSwagger2OpenAPI(spec) {
|
|
44
|
+
console.warn("[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0");
|
|
45
|
+
return new Promise((resolve, reject) => (0, swagger2openapi_1.convertObj)(spec, { patch: true, warnOnly: true, text: "{}", anchors: true }, (err, res) => {
|
|
46
|
+
// TODO: log any warnings
|
|
47
|
+
if (err) {
|
|
48
|
+
return reject(err);
|
|
49
|
+
}
|
|
50
|
+
resolve(res && res.openapi);
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
exports.convertSwagger2OpenAPI = convertSwagger2OpenAPI;
|
|
19
54
|
async function resolveJsonRefs(specUrlOrObject) {
|
|
20
55
|
var _a, _b;
|
|
21
56
|
try {
|
|
22
57
|
let schema = await json_schema_ref_parser_1.default.dereference(specUrlOrObject, {
|
|
23
58
|
continueOnError: true,
|
|
24
59
|
resolve: {
|
|
60
|
+
file: true,
|
|
61
|
+
external: true,
|
|
25
62
|
http: {
|
|
26
63
|
timeout: 15000, // 15 sec timeout
|
|
27
64
|
},
|
|
28
65
|
},
|
|
29
66
|
dereference: {
|
|
30
|
-
circular:
|
|
67
|
+
circular: true,
|
|
31
68
|
},
|
|
32
69
|
});
|
|
33
70
|
return schema;
|
|
@@ -37,8 +74,8 @@ async function resolveJsonRefs(specUrlOrObject) {
|
|
|
37
74
|
return;
|
|
38
75
|
}
|
|
39
76
|
}
|
|
40
|
-
async function
|
|
41
|
-
const config = new
|
|
77
|
+
async function loadAndResolveSpec(specUrlOrObject) {
|
|
78
|
+
const config = new openapi_core_1.Config({});
|
|
42
79
|
const bundleOpts = {
|
|
43
80
|
config,
|
|
44
81
|
base: process.cwd(),
|
|
@@ -54,26 +91,22 @@ async function loadAndBundleSpec(specUrlOrObject, parseJsonRefs) {
|
|
|
54
91
|
}
|
|
55
92
|
// Force dereference ?
|
|
56
93
|
// bundleOpts["dereference"] = true;
|
|
57
|
-
const { bundle: { parsed }, } = await (0,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
94
|
+
const { bundle: { parsed }, } = await (0, openapi_core_1.bundle)(bundleOpts);
|
|
95
|
+
const resolved = await resolveJsonRefs(parsed);
|
|
96
|
+
// Force serialization and replace circular $ref pointers
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
const serialized = JSON.stringify(resolved, serializer());
|
|
99
|
+
let decycled;
|
|
100
|
+
try {
|
|
101
|
+
decycled = JSON.parse(serialized);
|
|
65
102
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return reject(err);
|
|
75
|
-
}
|
|
76
|
-
resolve(res && res.openapi);
|
|
77
|
-
}));
|
|
103
|
+
catch (err) {
|
|
104
|
+
console.error(chalk_1.default.yellow(err));
|
|
105
|
+
}
|
|
106
|
+
return decycled !== undefined && typeof decycled === "object"
|
|
107
|
+
? decycled.swagger !== undefined
|
|
108
|
+
? convertSwagger2OpenAPI(decycled)
|
|
109
|
+
: decycled
|
|
110
|
+
: resolved;
|
|
78
111
|
}
|
|
79
|
-
exports.
|
|
112
|
+
exports.loadAndResolveSpec = loadAndResolveSpec;
|
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-396",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=14"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "958b9c6e0b370afe79572dfea950d2be33f41cc0"
|
|
71
71
|
}
|