docusaurus-plugin-openapi-docs 0.0.0-402 → 0.0.0-405
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 +1 -1
- package/lib/openapi/openapi.js +5 -2
- package/package.json +2 -2
- package/src/openapi/openapi.ts +5 -2
- package/lib/markdown/createAnyOneOf.d.ts +0 -1
- package/lib/markdown/createAnyOneOf.js +0 -57
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
- package/lib/openapi/utils/loadAndBundleSpec.js +0 -79
- package/yarn-error.log +0 -15830
package/README.md
CHANGED
|
@@ -246,7 +246,7 @@ yarn docusaurus gen-api-docs:version petstore:all
|
|
|
246
246
|
Run the following to bootstrap a Docsaurus v2 site (classic theme) with `docusaurus-openapi-docs`:
|
|
247
247
|
|
|
248
248
|
```bash
|
|
249
|
-
npx create-docusaurus@2.0.0-
|
|
249
|
+
npx create-docusaurus@2.0.0-rc.1 my-website --package-manager yarn
|
|
250
250
|
```
|
|
251
251
|
|
|
252
252
|
> When prompted to select a template choose `Git repository`.
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -40,7 +40,8 @@ function jsonToCollection(data) {
|
|
|
40
40
|
*/
|
|
41
41
|
async function createPostmanCollection(openapiData) {
|
|
42
42
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
|
-
|
|
43
|
+
// Create copy of openapiData
|
|
44
|
+
const data = Object.assign({}, openapiData);
|
|
44
45
|
// Including `servers` breaks postman, so delete all of them.
|
|
45
46
|
delete data.servers;
|
|
46
47
|
for (let pathItemObject of Object.values(data.paths)) {
|
|
@@ -114,7 +115,9 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
114
115
|
operationObject.description =
|
|
115
116
|
(_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
|
|
116
117
|
}
|
|
117
|
-
const baseId =
|
|
118
|
+
const baseId = operationObject.operationId
|
|
119
|
+
? (0, lodash_1.kebabCase)(operationObject.operationId)
|
|
120
|
+
: (0, lodash_1.kebabCase)(operationObject.summary);
|
|
118
121
|
const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
|
|
119
122
|
const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
|
|
120
123
|
// Add security schemes so we know how to handle security.
|
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-405",
|
|
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": "f87ea96605b968d06659143fc7bcf8628e9508b1"
|
|
71
71
|
}
|
package/src/openapi/openapi.ts
CHANGED
|
@@ -53,7 +53,8 @@ function jsonToCollection(data: OpenApiObject): Promise<Collection> {
|
|
|
53
53
|
async function createPostmanCollection(
|
|
54
54
|
openapiData: OpenApiObject
|
|
55
55
|
): Promise<Collection> {
|
|
56
|
-
|
|
56
|
+
// Create copy of openapiData
|
|
57
|
+
const data = Object.assign({}, openapiData) as OpenApiObject;
|
|
57
58
|
|
|
58
59
|
// Including `servers` breaks postman, so delete all of them.
|
|
59
60
|
delete data.servers;
|
|
@@ -146,7 +147,9 @@ function createItems(
|
|
|
146
147
|
operationObject.summary ?? operationObject.operationId ?? "";
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
const baseId =
|
|
150
|
+
const baseId = operationObject.operationId
|
|
151
|
+
? kebabCase(operationObject.operationId)
|
|
152
|
+
: kebabCase(operationObject.summary);
|
|
150
153
|
|
|
151
154
|
const servers =
|
|
152
155
|
operationObject.servers ?? pathObject.servers ?? openapiData.servers;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createAnyOneOf(anyOneOf: any[], type: string): string | undefined;
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
function createAnyOneOf(anyOneOf, type) {
|
|
13
|
-
if (anyOneOf === undefined) {
|
|
14
|
-
return undefined;
|
|
15
|
-
}
|
|
16
|
-
if (anyOneOf.length === 0) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
return (0, utils_1.create)("div", {
|
|
20
|
-
children: [
|
|
21
|
-
(0, utils_1.create)("span", {
|
|
22
|
-
className: "badge badge--info",
|
|
23
|
-
children: type,
|
|
24
|
-
}),
|
|
25
|
-
(0, utils_1.create)("SchemaTabs", {
|
|
26
|
-
children: anyOneOf.map((schema, index) => {
|
|
27
|
-
const label = schema.title ? schema.title : `MOD${index + 1}`;
|
|
28
|
-
if (schema.properties !== undefined) {
|
|
29
|
-
return (0, utils_1.create)("TabItem", {
|
|
30
|
-
label: label,
|
|
31
|
-
value: `${index}-properties`,
|
|
32
|
-
children: [(0, createSchemaDetails_1.createNodes)(schema)],
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
if (schema.allOf !== undefined) {
|
|
36
|
-
return (0, utils_1.create)("TabItem", {
|
|
37
|
-
label: label,
|
|
38
|
-
value: `${index}-allOf`,
|
|
39
|
-
children: [(0, createSchemaDetails_1.createNodes)(schema)],
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
if (schema.items !== undefined) {
|
|
43
|
-
if (schema.items.properties !== undefined) {
|
|
44
|
-
return (0, utils_1.create)("TabItem", {
|
|
45
|
-
label: label,
|
|
46
|
-
value: `${index}-item-properties`,
|
|
47
|
-
children: [(0, createSchemaDetails_1.createNodes)(schema.items)],
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return undefined;
|
|
52
|
-
}),
|
|
53
|
-
}),
|
|
54
|
-
],
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
exports.createAnyOneOf = createAnyOneOf;
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.convertSwagger2OpenAPI = exports.loadAndBundleSpec = void 0;
|
|
13
|
-
// @ts-nocheck
|
|
14
|
-
const json_schema_ref_parser_1 = __importDefault(require("@apidevtools/json-schema-ref-parser"));
|
|
15
|
-
const bundle_1 = require("@redocly/openapi-core/lib/bundle");
|
|
16
|
-
const config_1 = require("@redocly/openapi-core/lib/config/config");
|
|
17
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
18
|
-
const swagger2openapi_1 = require("swagger2openapi");
|
|
19
|
-
async function resolveJsonRefs(specUrlOrObject) {
|
|
20
|
-
var _a, _b;
|
|
21
|
-
try {
|
|
22
|
-
let schema = await json_schema_ref_parser_1.default.dereference(specUrlOrObject, {
|
|
23
|
-
continueOnError: true,
|
|
24
|
-
resolve: {
|
|
25
|
-
http: {
|
|
26
|
-
timeout: 15000, // 15 sec timeout
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
dereference: {
|
|
30
|
-
circular: "ignore",
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
return schema;
|
|
34
|
-
}
|
|
35
|
-
catch (err) {
|
|
36
|
-
console.error(chalk_1.default.yellow((_b = (_a = err.errors[0]) === null || _a === void 0 ? void 0 : _a.message) !== null && _b !== void 0 ? _b : err));
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
async function loadAndBundleSpec(specUrlOrObject, parseJsonRefs) {
|
|
41
|
-
const config = new config_1.Config({});
|
|
42
|
-
const bundleOpts = {
|
|
43
|
-
config,
|
|
44
|
-
base: process.cwd(),
|
|
45
|
-
};
|
|
46
|
-
if (typeof specUrlOrObject === "object" && specUrlOrObject !== null) {
|
|
47
|
-
bundleOpts["doc"] = {
|
|
48
|
-
source: { absoluteRef: "" },
|
|
49
|
-
parsed: specUrlOrObject,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
bundleOpts["ref"] = specUrlOrObject;
|
|
54
|
-
}
|
|
55
|
-
// Force dereference ?
|
|
56
|
-
// bundleOpts["dereference"] = true;
|
|
57
|
-
const { bundle: { parsed }, } = await (0, bundle_1.bundle)(bundleOpts);
|
|
58
|
-
if (parseJsonRefs) {
|
|
59
|
-
const resolved = await resolveJsonRefs(parsed);
|
|
60
|
-
return typeof resolved === Object
|
|
61
|
-
? resolved.swagger !== undefined
|
|
62
|
-
? convertSwagger2OpenAPI(resolved)
|
|
63
|
-
: resolved
|
|
64
|
-
: parsed;
|
|
65
|
-
}
|
|
66
|
-
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
|
|
67
|
-
}
|
|
68
|
-
exports.loadAndBundleSpec = loadAndBundleSpec;
|
|
69
|
-
function convertSwagger2OpenAPI(spec) {
|
|
70
|
-
console.warn("[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0");
|
|
71
|
-
return new Promise((resolve, reject) => (0, swagger2openapi_1.convertObj)(spec, { patch: true, warnOnly: true, text: "{}", anchors: true }, (err, res) => {
|
|
72
|
-
// TODO: log any warnings
|
|
73
|
-
if (err) {
|
|
74
|
-
return reject(err);
|
|
75
|
-
}
|
|
76
|
-
resolve(res && res.openapi);
|
|
77
|
-
}));
|
|
78
|
-
}
|
|
79
|
-
exports.convertSwagger2OpenAPI = convertSwagger2OpenAPI;
|