docusaurus-plugin-openapi-docs 0.0.0-399 → 0.0.0-402

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.
@@ -0,0 +1 @@
1
+ export declare function createAnyOneOf(anyOneOf: any[], type: string): string | undefined;
@@ -0,0 +1,57 @@
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;
@@ -0,0 +1,3 @@
1
+ import { OpenAPISpec } from "./types";
2
+ export declare function loadAndBundleSpec(specUrlOrObject: object | string, parseJsonRefs: boolean | undefined): Promise<OpenAPISpec>;
3
+ export declare function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec>;
@@ -0,0 +1,79 @@
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;
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-399",
4
+ "version": "0.0.0-402",
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.22",
32
- "@docusaurus/types": "2.0.0-beta.22",
31
+ "@docusaurus/module-type-aliases": "2.0.0-rc.1",
32
+ "@docusaurus/types": "2.0.0-rc.1",
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.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",
43
+ "@docusaurus/mdx-loader": "2.0.0-rc.1",
44
+ "@docusaurus/plugin-content-docs": "2.0.0-rc.1",
45
+ "@docusaurus/utils": "2.0.0-rc.1",
46
+ "@docusaurus/utils-validation": "2.0.0-rc.1",
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": "b42f88176b921b8871b87b95c08e5444e17b76b9"
70
+ "gitHead": "0ad47c91138db5b9d06e329fe459b3a04c51c54d"
71
71
  }