docusaurus-plugin-openapi-docs 0.0.0-394 → 0.0.0-397
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/createSchemaDetails.js +322 -148
- package/lib/markdown/schema.js +25 -9
- package/lib/openapi/openapi.d.ts +3 -3
- package/lib/openapi/openapi.js +26 -25
- package/lib/openapi/types.d.ts +2 -1
- package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
- package/lib/openapi/utils/{loadAndBundleSpec.js → loadAndResolveSpec.js} +61 -28
- package/package.json +8 -8
- package/src/markdown/createSchemaDetails.ts +398 -175
- package/src/markdown/schema.ts +28 -8
- package/src/openapi/openapi.ts +38 -37
- package/src/openapi/types.ts +2 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
- package/lib/markdown/createAnyOneOf.d.ts +0 -1
- package/lib/markdown/createAnyOneOf.js +0 -84
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
- package/src/markdown/createAnyOneOf.ts +0 -88
- package/src/openapi/utils/loadAndBundleSpec.ts +0 -93
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
|
@@ -11,6 +11,7 @@ export interface OpenApiObject {
|
|
|
11
11
|
security?: SecurityRequirementObject[];
|
|
12
12
|
tags?: TagObject[];
|
|
13
13
|
externalDocs?: ExternalDocumentationObject;
|
|
14
|
+
swagger?: string;
|
|
14
15
|
}
|
|
15
16
|
export interface OpenApiObjectWithRef {
|
|
16
17
|
openapi: string;
|
|
@@ -255,7 +256,7 @@ export declare type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" |
|
|
|
255
256
|
not?: SchemaObject;
|
|
256
257
|
items?: SchemaObject;
|
|
257
258
|
properties?: Map<SchemaObject>;
|
|
258
|
-
additionalProperties?:
|
|
259
|
+
additionalProperties?: Map<SchemaObject>;
|
|
259
260
|
nullable?: boolean;
|
|
260
261
|
discriminator?: DiscriminatorObject;
|
|
261
262
|
readOnly?: boolean;
|
|
@@ -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-397",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"watch": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
32
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
31
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.22",
|
|
32
|
+
"@docusaurus/types": "2.0.0-beta.22",
|
|
33
33
|
"@types/fs-extra": "^9.0.13",
|
|
34
34
|
"@types/js-yaml": "^4.0.5",
|
|
35
35
|
"@types/json-pointer": "^1.0.31",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@apidevtools/json-schema-ref-parser": "^9.0.9",
|
|
43
|
-
"@docusaurus/mdx-loader": "2.0.0-beta.
|
|
44
|
-
"@docusaurus/plugin-content-docs": "2.0.0-beta.
|
|
45
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
46
|
-
"@docusaurus/utils-validation": "2.0.0-beta.
|
|
43
|
+
"@docusaurus/mdx-loader": "2.0.0-beta.22",
|
|
44
|
+
"@docusaurus/plugin-content-docs": "2.0.0-beta.22",
|
|
45
|
+
"@docusaurus/utils": "2.0.0-beta.22",
|
|
46
|
+
"@docusaurus/utils-validation": "2.0.0-beta.22",
|
|
47
47
|
"@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
|
|
48
48
|
"@paloaltonetworks/postman-collection": "^4.1.0",
|
|
49
49
|
"@redocly/openapi-core": "^1.0.0-beta.103",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"engines": {
|
|
68
68
|
"node": ">=14"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "a830bbb4f0c32d17aedebc9503750a6aae9957cd"
|
|
71
71
|
}
|