docusaurus-plugin-openapi-docs 0.0.0-361 → 0.0.0-366
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/index.js +5 -0
- package/lib/markdown/createAuthentication.d.ts +2 -0
- package/lib/markdown/createAuthentication.js +139 -0
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/index.js +5 -1
- package/lib/openapi/openapi.js +17 -16
- package/lib/openapi/openapi.test.js +0 -6
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +3 -0
- package/lib/openapi/utils/loadAndBundleSpec.js +44 -0
- package/lib/openapi/utils/types.d.ts +306 -0
- package/lib/openapi/utils/types.js +8 -0
- package/lib/types.d.ts +5 -0
- package/package.json +10 -8
- package/src/index.ts +5 -0
- package/src/markdown/createAuthentication.ts +160 -0
- package/src/markdown/index.ts +10 -1
- package/src/openapi/openapi.test.ts +0 -6
- package/src/openapi/openapi.ts +9 -6
- package/src/openapi/utils/loadAndBundleSpec.ts +62 -0
- package/src/openapi/utils/types.ts +303 -0
- package/src/types.ts +5 -0
- package/src/openapi/__fixtures__/examples/yogurtstore/_category_.json +0 -4
- package/src/openapi/__fixtures__/examples/yogurtstore/froyo.yaml +0 -13
- package/src/openapi/__fixtures__/examples/yogurtstore/nested/nested.yaml +0 -13
package/lib/index.js
CHANGED
|
@@ -78,6 +78,9 @@ api: {{{json}}}
|
|
|
78
78
|
{{#api.method}}
|
|
79
79
|
sidebar_class_name: "{{{api.method}}} api-method"
|
|
80
80
|
{{/api.method}}
|
|
81
|
+
{{#infoPath}}
|
|
82
|
+
info_path: {{{infoPath}}}
|
|
83
|
+
{{/infoPath}}
|
|
81
84
|
---
|
|
82
85
|
|
|
83
86
|
{{{markdown}}}
|
|
@@ -125,6 +128,8 @@ import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
|
125
128
|
item.markdown = markdown;
|
|
126
129
|
if (item.type === "api") {
|
|
127
130
|
item.json = JSON.stringify(item.api);
|
|
131
|
+
if (item.infoId)
|
|
132
|
+
item.infoPath = `${outputDir}/${item.infoId}`;
|
|
128
133
|
}
|
|
129
134
|
const view = (0, mustache_1.render)(mdTemplate, item);
|
|
130
135
|
const utils = (0, mustache_1.render)(infoMdTemplate, item);
|
|
@@ -0,0 +1,139 @@
|
|
|
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.createAuthentication = void 0;
|
|
10
|
+
const createDescription_1 = require("./createDescription");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
function createAuthentication(securitySchemes) {
|
|
13
|
+
if (!securitySchemes || !Object.keys(securitySchemes).length)
|
|
14
|
+
return "";
|
|
15
|
+
const createAuthenticationTable = (securityScheme) => {
|
|
16
|
+
const { bearerFormat, flows, name, scheme, type } = securityScheme;
|
|
17
|
+
const createSecuritySchemeTypeRow = () => (0, utils_1.create)("tr", {
|
|
18
|
+
children: [
|
|
19
|
+
(0, utils_1.create)("th", { children: "Security Scheme Type:" }),
|
|
20
|
+
(0, utils_1.create)("td", { children: type }),
|
|
21
|
+
],
|
|
22
|
+
});
|
|
23
|
+
const createOAuthFlowRows = () => {
|
|
24
|
+
const flowRows = Object.entries(flows).map(([flowType, flowObj]) => {
|
|
25
|
+
const { authorizationUrl, tokenUrl, refreshUrl, scopes } = flowObj;
|
|
26
|
+
return (0, utils_1.create)("tr", {
|
|
27
|
+
children: [
|
|
28
|
+
(0, utils_1.create)("th", { children: `${flowType} OAuth Flow:` }),
|
|
29
|
+
(0, utils_1.create)("td", {
|
|
30
|
+
children: [
|
|
31
|
+
(0, utils_1.guard)(tokenUrl, () => (0, utils_1.create)("p", { children: `Token URL: ${tokenUrl}` })),
|
|
32
|
+
(0, utils_1.guard)(authorizationUrl, () => (0, utils_1.create)("p", {
|
|
33
|
+
children: `Authorization URL: ${authorizationUrl}`,
|
|
34
|
+
})),
|
|
35
|
+
(0, utils_1.guard)(refreshUrl, () => (0, utils_1.create)("p", { children: `Refresh URL: ${refreshUrl}` })),
|
|
36
|
+
(0, utils_1.create)("span", { children: "Scopes:" }),
|
|
37
|
+
(0, utils_1.create)("ul", {
|
|
38
|
+
children: Object.entries(scopes).map(([scope, description]) => (0, utils_1.create)("li", { children: `${scope}: ${description}` })),
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
}),
|
|
42
|
+
],
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
return flowRows.join("");
|
|
46
|
+
};
|
|
47
|
+
switch (type) {
|
|
48
|
+
case "apiKey":
|
|
49
|
+
return (0, utils_1.create)("div", {
|
|
50
|
+
children: [
|
|
51
|
+
(0, utils_1.create)("table", {
|
|
52
|
+
children: (0, utils_1.create)("tbody", {
|
|
53
|
+
children: [
|
|
54
|
+
createSecuritySchemeTypeRow(),
|
|
55
|
+
(0, utils_1.create)("tr", {
|
|
56
|
+
children: [
|
|
57
|
+
(0, utils_1.create)("th", { children: "Header parameter name:" }),
|
|
58
|
+
(0, utils_1.create)("td", { children: name }),
|
|
59
|
+
],
|
|
60
|
+
}),
|
|
61
|
+
],
|
|
62
|
+
}),
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
case "http":
|
|
67
|
+
return (0, utils_1.create)("div", {
|
|
68
|
+
children: [
|
|
69
|
+
(0, utils_1.create)("table", {
|
|
70
|
+
children: (0, utils_1.create)("tbody", {
|
|
71
|
+
children: [
|
|
72
|
+
createSecuritySchemeTypeRow(),
|
|
73
|
+
(0, utils_1.create)("tr", {
|
|
74
|
+
children: [
|
|
75
|
+
(0, utils_1.create)("th", { children: "HTTP Authorization Scheme:" }),
|
|
76
|
+
(0, utils_1.create)("td", { children: scheme }),
|
|
77
|
+
],
|
|
78
|
+
}),
|
|
79
|
+
(0, utils_1.create)("tr", {
|
|
80
|
+
children: [
|
|
81
|
+
(0, utils_1.create)("th", { children: "Bearer format:" }),
|
|
82
|
+
(0, utils_1.create)("td", { children: bearerFormat }),
|
|
83
|
+
],
|
|
84
|
+
}),
|
|
85
|
+
],
|
|
86
|
+
}),
|
|
87
|
+
}),
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
case "oauth2":
|
|
91
|
+
return (0, utils_1.create)("div", {
|
|
92
|
+
children: [
|
|
93
|
+
(0, utils_1.create)("table", {
|
|
94
|
+
children: (0, utils_1.create)("tbody", {
|
|
95
|
+
children: [
|
|
96
|
+
createSecuritySchemeTypeRow(),
|
|
97
|
+
createOAuthFlowRows(),
|
|
98
|
+
],
|
|
99
|
+
}),
|
|
100
|
+
}),
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
default:
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const formatTabLabel = (str) => {
|
|
108
|
+
const formattedLabel = str
|
|
109
|
+
.replace(/(_|-)/g, " ")
|
|
110
|
+
.trim()
|
|
111
|
+
.replace(/\w\S*/g, (str) => str.charAt(0).toUpperCase() + str.substr(1))
|
|
112
|
+
.replace(/([a-z])([A-Z])/g, "$1 $2")
|
|
113
|
+
.replace(/([A-Z])([A-Z][a-z])/g, "$1 $2");
|
|
114
|
+
const isOAuth = formattedLabel.toLowerCase().includes("oauth2");
|
|
115
|
+
const isApiKey = formattedLabel.toLowerCase().includes("api");
|
|
116
|
+
return isOAuth ? "OAuth 2.0" : isApiKey ? "API Key" : formattedLabel;
|
|
117
|
+
};
|
|
118
|
+
return (0, utils_1.create)("div", {
|
|
119
|
+
children: [
|
|
120
|
+
(0, utils_1.create)("h2", {
|
|
121
|
+
children: "Authentication",
|
|
122
|
+
id: "authentication",
|
|
123
|
+
style: { marginBottom: "1rem" },
|
|
124
|
+
}),
|
|
125
|
+
(0, utils_1.create)("Tabs", {
|
|
126
|
+
children: Object.entries(securitySchemes).map(([schemeType, schemeObj]) => (0, utils_1.create)("TabItem", {
|
|
127
|
+
label: formatTabLabel(schemeType),
|
|
128
|
+
value: `${schemeType}`,
|
|
129
|
+
children: [
|
|
130
|
+
(0, createDescription_1.createDescription)(schemeObj.description),
|
|
131
|
+
createAuthenticationTable(schemeObj),
|
|
132
|
+
],
|
|
133
|
+
})),
|
|
134
|
+
}),
|
|
135
|
+
],
|
|
136
|
+
style: { marginBottom: "2rem" },
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
exports.createAuthentication = createAuthentication;
|
package/lib/markdown/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ApiPageMetadata, InfoPageMetadata, TagPageMetadata } from "../types";
|
|
2
2
|
export declare function createApiPageMD({ title, api: { deprecated, "x-deprecated-description": deprecatedDescription, description, parameters, requestBody, responses, }, }: ApiPageMetadata): string;
|
|
3
|
-
export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, }: InfoPageMetadata): string;
|
|
3
|
+
export declare function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, securitySchemes, }: InfoPageMetadata): string;
|
|
4
4
|
export declare function createTagPageMD({ tag: { description } }: TagPageMetadata): string;
|
package/lib/markdown/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.createTagPageMD = exports.createInfoPageMD = exports.createApiPageMD = void 0;
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
|
+
const createAuthentication_1 = require("./createAuthentication");
|
|
11
12
|
const createContactInfo_1 = require("./createContactInfo");
|
|
12
13
|
const createDeprecationNotice_1 = require("./createDeprecationNotice");
|
|
13
14
|
const createDescription_1 = require("./createDescription");
|
|
@@ -36,11 +37,14 @@ function createApiPageMD({ title, api: { deprecated, "x-deprecated-description":
|
|
|
36
37
|
]);
|
|
37
38
|
}
|
|
38
39
|
exports.createApiPageMD = createApiPageMD;
|
|
39
|
-
function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, }) {
|
|
40
|
+
function createInfoPageMD({ info: { title, version, description, contact, license, termsOfService }, securitySchemes, }) {
|
|
40
41
|
return (0, utils_1.render)([
|
|
42
|
+
`import Tabs from "@theme/Tabs";\n`,
|
|
43
|
+
`import TabItem from "@theme/TabItem";\n`,
|
|
41
44
|
(0, createVersionBadge_1.createVersionBadge)(version),
|
|
42
45
|
`# ${(0, lodash_1.escape)(title)}\n\n`,
|
|
43
46
|
(0, createDescription_1.createDescription)(description),
|
|
47
|
+
(0, createAuthentication_1.createAuthentication)(securitySchemes),
|
|
44
48
|
(0, createContactInfo_1.createContactInfo)(contact),
|
|
45
49
|
(0, createTermsOfService_1.createTermsOfService)(termsOfService),
|
|
46
50
|
(0, createLicense_1.createLicense)(license),
|
package/lib/openapi/openapi.js
CHANGED
|
@@ -16,10 +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 js_yaml_1 = __importDefault(require("js-yaml"));
|
|
20
19
|
const json_refs_1 = __importDefault(require("json-refs"));
|
|
21
20
|
const lodash_1 = require("lodash");
|
|
22
21
|
const createExample_1 = require("./createExample");
|
|
22
|
+
const loadAndBundleSpec_1 = require("./utils/loadAndBundleSpec");
|
|
23
23
|
/**
|
|
24
24
|
* Finds any reference objects in the OpenAPI definition and resolves them to a finalized value.
|
|
25
25
|
*/
|
|
@@ -64,9 +64,10 @@ async function createPostmanCollection(openapiData) {
|
|
|
64
64
|
return await jsonToCollection(data);
|
|
65
65
|
}
|
|
66
66
|
function createItems(openapiData, sidebarOptions) {
|
|
67
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
67
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
68
68
|
// TODO: Find a better way to handle this
|
|
69
69
|
let items = [];
|
|
70
|
+
const infoId = (0, lodash_1.kebabCase)(openapiData.info.title);
|
|
70
71
|
if ((sidebarOptions === null || sidebarOptions === void 0 ? void 0 : sidebarOptions.categoryLinkSource) === "tag") {
|
|
71
72
|
// Only create an tag pages if categoryLinkSource set to tag.
|
|
72
73
|
const tags = (_a = openapiData.tags) !== null && _a !== void 0 ? _a : [];
|
|
@@ -95,7 +96,6 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
95
96
|
}
|
|
96
97
|
if (openapiData.info.description) {
|
|
97
98
|
// Only create an info page if we have a description.
|
|
98
|
-
const infoId = (0, lodash_1.kebabCase)(openapiData.info.title);
|
|
99
99
|
const infoPage = {
|
|
100
100
|
type: "info",
|
|
101
101
|
id: infoId,
|
|
@@ -104,10 +104,11 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
104
104
|
description: openapiData.info.description,
|
|
105
105
|
slug: "/" + infoId,
|
|
106
106
|
frontMatter: {},
|
|
107
|
+
securitySchemes: (_b = openapiData.components) === null || _b === void 0 ? void 0 : _b.securitySchemes,
|
|
107
108
|
info: {
|
|
108
109
|
...openapiData.info,
|
|
109
|
-
tags: (
|
|
110
|
-
title: (
|
|
110
|
+
tags: (_c = openapiData.tags) === null || _c === void 0 ? void 0 : _c.map((tagName) => { var _a; return getTagDisplayName(tagName.name, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
|
|
111
|
+
title: (_d = openapiData.info.title) !== null && _d !== void 0 ? _d : "Introduction",
|
|
111
112
|
},
|
|
112
113
|
};
|
|
113
114
|
items.push(infoPage);
|
|
@@ -115,16 +116,16 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
115
116
|
for (let [path, pathObject] of Object.entries(openapiData.paths)) {
|
|
116
117
|
const { $ref, description, parameters, servers, summary, ...rest } = pathObject;
|
|
117
118
|
for (let [method, operationObject] of Object.entries({ ...rest })) {
|
|
118
|
-
const title = (
|
|
119
|
+
const title = (_f = (_e = operationObject.summary) !== null && _e !== void 0 ? _e : operationObject.operationId) !== null && _f !== void 0 ? _f : "Missing summary";
|
|
119
120
|
if (operationObject.description === undefined) {
|
|
120
121
|
operationObject.description =
|
|
121
|
-
(
|
|
122
|
+
(_h = (_g = operationObject.summary) !== null && _g !== void 0 ? _g : operationObject.operationId) !== null && _h !== void 0 ? _h : "";
|
|
122
123
|
}
|
|
123
124
|
const baseId = (0, lodash_1.kebabCase)(title);
|
|
124
|
-
const servers = (
|
|
125
|
-
const security = (
|
|
125
|
+
const servers = (_k = (_j = operationObject.servers) !== null && _j !== void 0 ? _j : pathObject.servers) !== null && _k !== void 0 ? _k : openapiData.servers;
|
|
126
|
+
const security = (_l = operationObject.security) !== null && _l !== void 0 ? _l : openapiData.security;
|
|
126
127
|
// Add security schemes so we know how to handle security.
|
|
127
|
-
const securitySchemes = (
|
|
128
|
+
const securitySchemes = (_m = openapiData.components) === null || _m === void 0 ? void 0 : _m.securitySchemes;
|
|
128
129
|
// Make sure schemes are lowercase. See: https://github.com/cloud-annotations/docusaurus-plugin-openapi/issues/79
|
|
129
130
|
if (securitySchemes) {
|
|
130
131
|
for (let securityScheme of Object.values(securitySchemes)) {
|
|
@@ -134,7 +135,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
let jsonRequestBodyExample;
|
|
137
|
-
const body = (
|
|
138
|
+
const body = (_p = (_o = operationObject.requestBody) === null || _o === void 0 ? void 0 : _o.content) === null || _p === void 0 ? void 0 : _p["application/json"];
|
|
138
139
|
if (body === null || body === void 0 ? void 0 : body.schema) {
|
|
139
140
|
jsonRequestBodyExample = (0, createExample_1.sampleFromSchema)(body.schema);
|
|
140
141
|
}
|
|
@@ -143,6 +144,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
143
144
|
const apiPage = {
|
|
144
145
|
type: "api",
|
|
145
146
|
id: baseId,
|
|
147
|
+
infoId: infoId !== null && infoId !== void 0 ? infoId : "",
|
|
146
148
|
unversionedId: baseId,
|
|
147
149
|
title: title,
|
|
148
150
|
description: description !== null && description !== void 0 ? description : "",
|
|
@@ -150,7 +152,7 @@ function createItems(openapiData, sidebarOptions) {
|
|
|
150
152
|
frontMatter: {},
|
|
151
153
|
api: {
|
|
152
154
|
...defaults,
|
|
153
|
-
tags: (
|
|
155
|
+
tags: (_q = operationObject.tags) === null || _q === void 0 ? void 0 : _q.map((tagName) => { var _a; return getTagDisplayName(tagName, (_a = openapiData.tags) !== null && _a !== void 0 ? _a : []); }),
|
|
154
156
|
method,
|
|
155
157
|
path,
|
|
156
158
|
servers,
|
|
@@ -193,13 +195,13 @@ async function readOpenapiFiles(openapiPath, _options) {
|
|
|
193
195
|
const allFiles = await (0, utils_1.Globby)(["**/*.{json,yaml,yml}"], {
|
|
194
196
|
cwd: openapiPath,
|
|
195
197
|
ignore: utils_1.GlobExcludeDefault,
|
|
198
|
+
deep: 1,
|
|
196
199
|
});
|
|
197
200
|
const sources = allFiles.filter((x) => !x.includes("_category_")); // todo: regex exclude?
|
|
198
201
|
return Promise.all(sources.map(async (source) => {
|
|
199
202
|
// TODO: make a function for this
|
|
200
203
|
const fullPath = path_1.default.join(openapiPath, source);
|
|
201
|
-
const
|
|
202
|
-
const data = js_yaml_1.default.load(openapiString);
|
|
204
|
+
const data = (await (0, loadAndBundleSpec_1.loadAndBundleSpec)(fullPath));
|
|
203
205
|
return {
|
|
204
206
|
source: fullPath,
|
|
205
207
|
sourceDirName: path_1.default.dirname(source),
|
|
@@ -207,8 +209,7 @@ async function readOpenapiFiles(openapiPath, _options) {
|
|
|
207
209
|
};
|
|
208
210
|
}));
|
|
209
211
|
}
|
|
210
|
-
const
|
|
211
|
-
const data = js_yaml_1.default.load(openapiString);
|
|
212
|
+
const data = (await (0, loadAndBundleSpec_1.loadAndBundleSpec)(openapiPath));
|
|
212
213
|
return [
|
|
213
214
|
{
|
|
214
215
|
source: openapiPath,
|
|
@@ -22,12 +22,6 @@ describe("openapi", () => {
|
|
|
22
22
|
const yaml = results.find((x) => x.source.endsWith("openapi.yaml"));
|
|
23
23
|
expect(yaml).toBeTruthy();
|
|
24
24
|
expect(yaml === null || yaml === void 0 ? void 0 : yaml.sourceDirName).toBe(".");
|
|
25
|
-
const froyo = results.find((x) => x.source.endsWith("froyo.yaml"));
|
|
26
|
-
expect(froyo).toBeTruthy();
|
|
27
|
-
expect(froyo === null || froyo === void 0 ? void 0 : froyo.sourceDirName).toBe("yogurtstore");
|
|
28
|
-
const nested = results.find((x) => x.source.endsWith("nested.yaml"));
|
|
29
|
-
expect(nested).toBeTruthy();
|
|
30
|
-
expect(nested === null || nested === void 0 ? void 0 : nested.sourceDirName).toBe("yogurtstore/nested");
|
|
31
25
|
});
|
|
32
26
|
});
|
|
33
27
|
});
|
|
@@ -0,0 +1,44 @@
|
|
|
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.convertSwagger2OpenAPI = exports.loadAndBundleSpec = void 0;
|
|
10
|
+
const bundle_1 = require("@redocly/openapi-core/lib/bundle");
|
|
11
|
+
const config_1 = require("@redocly/openapi-core/lib/config/config");
|
|
12
|
+
const swagger2openapi_1 = require("swagger2openapi");
|
|
13
|
+
async function loadAndBundleSpec(specUrlOrObject) {
|
|
14
|
+
const config = new config_1.Config({});
|
|
15
|
+
const bundleOpts = {
|
|
16
|
+
config,
|
|
17
|
+
base: process.cwd(),
|
|
18
|
+
};
|
|
19
|
+
if (typeof specUrlOrObject === "object" && specUrlOrObject !== null) {
|
|
20
|
+
bundleOpts["doc"] = {
|
|
21
|
+
source: { absoluteRef: "" },
|
|
22
|
+
parsed: specUrlOrObject,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
bundleOpts["ref"] = specUrlOrObject;
|
|
27
|
+
}
|
|
28
|
+
// Force dereference ?
|
|
29
|
+
// bundleOpts["dereference"] = true;
|
|
30
|
+
const { bundle: { parsed }, } = await (0, bundle_1.bundle)(bundleOpts);
|
|
31
|
+
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
|
|
32
|
+
}
|
|
33
|
+
exports.loadAndBundleSpec = loadAndBundleSpec;
|
|
34
|
+
function convertSwagger2OpenAPI(spec) {
|
|
35
|
+
console.warn("[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0");
|
|
36
|
+
return new Promise((resolve, reject) => (0, swagger2openapi_1.convertObj)(spec, { patch: true, warnOnly: true, text: "{}", anchors: true }, (err, res) => {
|
|
37
|
+
// TODO: log any warnings
|
|
38
|
+
if (err) {
|
|
39
|
+
return reject(err);
|
|
40
|
+
}
|
|
41
|
+
resolve(res && res.openapi);
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
exports.convertSwagger2OpenAPI = convertSwagger2OpenAPI;
|