docusaurus-plugin-openapi-docs 1.0.4 → 1.1.0
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 +5 -4
- package/lib/index.js +3 -3
- package/lib/markdown/createSchemaDetails.js +325 -132
- package/lib/markdown/index.js +1 -0
- package/lib/markdown/schema.js +25 -9
- package/lib/markdown/utils.d.ts +1 -1
- package/lib/markdown/utils.js +4 -1
- package/lib/openapi/openapi.d.ts +5 -5
- package/lib/openapi/openapi.js +27 -23
- package/lib/openapi/openapi.test.js +1 -1
- package/lib/openapi/types.d.ts +2 -1
- package/lib/openapi/utils/loadAndResolveSpec.d.ts +2 -0
- package/lib/openapi/utils/loadAndResolveSpec.js +112 -0
- package/lib/openapi/utils/services/OpenAPIParser.d.ts +52 -0
- package/lib/openapi/utils/services/OpenAPIParser.js +342 -0
- package/lib/openapi/utils/services/RedocNormalizedOptions.d.ts +100 -0
- package/lib/openapi/utils/services/RedocNormalizedOptions.js +170 -0
- package/lib/openapi/utils/types/index.d.ts +2 -0
- package/lib/openapi/utils/types/index.js +23 -0
- package/lib/openapi/utils/types/open-api.d.ts +305 -0
- package/lib/openapi/utils/types/open-api.js +8 -0
- package/lib/openapi/utils/utils/JsonPointer.d.ts +51 -0
- package/lib/openapi/utils/utils/JsonPointer.js +95 -0
- package/lib/openapi/utils/utils/helpers.d.ts +43 -0
- package/lib/openapi/utils/utils/helpers.js +230 -0
- package/lib/openapi/utils/utils/index.d.ts +3 -0
- package/lib/openapi/utils/utils/index.js +25 -0
- package/lib/openapi/utils/utils/openapi.d.ts +40 -0
- package/lib/openapi/utils/utils/openapi.js +605 -0
- package/lib/options.js +1 -1
- package/lib/sidebars/index.js +9 -5
- package/lib/types.d.ts +1 -1
- package/package.json +16 -11
- package/src/index.ts +3 -3
- package/src/markdown/createSchemaDetails.ts +405 -159
- package/src/markdown/index.ts +1 -0
- package/src/markdown/schema.ts +28 -8
- package/src/markdown/utils.ts +5 -2
- package/src/openapi/openapi.test.ts +1 -1
- package/src/openapi/openapi.ts +39 -29
- package/src/openapi/types.ts +2 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +123 -0
- package/src/openapi/utils/services/OpenAPIParser.ts +433 -0
- package/src/openapi/utils/services/RedocNormalizedOptions.ts +330 -0
- package/src/openapi/utils/types/index.ts +10 -0
- package/src/openapi/utils/types/open-api.ts +303 -0
- package/src/openapi/utils/utils/JsonPointer.ts +99 -0
- package/src/openapi/utils/utils/helpers.ts +239 -0
- package/src/openapi/utils/utils/index.ts +11 -0
- package/src/openapi/utils/utils/openapi.ts +771 -0
- package/src/options.ts +1 -1
- package/src/sidebars/index.ts +11 -6
- package/src/types.ts +1 -1
- package/lib/openapi/utils/loadAndBundleSpec.d.ts +0 -3
- package/lib/openapi/utils/loadAndBundleSpec.js +0 -44
- package/src/openapi/utils/loadAndBundleSpec.ts +0 -62
package/src/options.ts
CHANGED
package/src/sidebars/index.ts
CHANGED
|
@@ -38,7 +38,7 @@ function groupByTags(
|
|
|
38
38
|
tags: TagObject[],
|
|
39
39
|
docPath: string
|
|
40
40
|
): ProcessedSidebar {
|
|
41
|
-
const { outputDir } = options;
|
|
41
|
+
const { outputDir, label } = options;
|
|
42
42
|
const {
|
|
43
43
|
sidebarCollapsed,
|
|
44
44
|
sidebarCollapsible,
|
|
@@ -67,7 +67,6 @@ function groupByTags(
|
|
|
67
67
|
const basePath = docPath
|
|
68
68
|
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
|
|
69
69
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
70
|
-
|
|
71
70
|
function createDocItem(item: ApiPageMetadata): SidebarItemDoc {
|
|
72
71
|
const sidebar_label = item.frontMatter.sidebar_label;
|
|
73
72
|
const title = item.title;
|
|
@@ -94,7 +93,7 @@ function groupByTags(
|
|
|
94
93
|
const id = infoItem.id;
|
|
95
94
|
rootIntroDoc = {
|
|
96
95
|
type: "doc" as const,
|
|
97
|
-
id: `${basePath}/${id}`,
|
|
96
|
+
id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
|
|
98
97
|
};
|
|
99
98
|
}
|
|
100
99
|
|
|
@@ -117,7 +116,10 @@ function groupByTags(
|
|
|
117
116
|
if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
|
|
118
117
|
linkConfig = {
|
|
119
118
|
type: "doc",
|
|
120
|
-
id:
|
|
119
|
+
id:
|
|
120
|
+
basePath === "" || undefined
|
|
121
|
+
? `${taggedInfoObject.id}`
|
|
122
|
+
: `${basePath}/${taggedInfoObject.id}`,
|
|
121
123
|
} as SidebarItemCategoryLinkConfig;
|
|
122
124
|
}
|
|
123
125
|
|
|
@@ -126,7 +128,8 @@ function groupByTags(
|
|
|
126
128
|
const tagId = kebabCase(tagObject.name);
|
|
127
129
|
linkConfig = {
|
|
128
130
|
type: "doc",
|
|
129
|
-
id:
|
|
131
|
+
id:
|
|
132
|
+
basePath === "" || undefined ? `${tagId}` : `${basePath}/${tagId}`,
|
|
130
133
|
} as SidebarItemCategoryLinkConfig;
|
|
131
134
|
}
|
|
132
135
|
|
|
@@ -135,7 +138,9 @@ function groupByTags(
|
|
|
135
138
|
linkConfig = {
|
|
136
139
|
type: "generated-index" as "generated-index",
|
|
137
140
|
title: tag,
|
|
138
|
-
slug:
|
|
141
|
+
slug: label
|
|
142
|
+
? "/category/" + kebabCase(label) + "/" + kebabCase(tag)
|
|
143
|
+
: "/category/" + kebabCase(tag),
|
|
139
144
|
} as SidebarItemCategoryLinkConfig;
|
|
140
145
|
}
|
|
141
146
|
|
package/src/types.ts
CHANGED
|
@@ -1,44 +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.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;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/* ============================================================================
|
|
2
|
-
* Copyright (c) Palo Alto Networks
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
* ========================================================================== */
|
|
7
|
-
|
|
8
|
-
// @ts-nocheck
|
|
9
|
-
|
|
10
|
-
import type { Source, Document } from "@redocly/openapi-core";
|
|
11
|
-
import { bundle } from "@redocly/openapi-core/lib/bundle";
|
|
12
|
-
import type { ResolvedConfig } from "@redocly/openapi-core/lib/config";
|
|
13
|
-
import { Config } from "@redocly/openapi-core/lib/config/config";
|
|
14
|
-
import { convertObj } from "swagger2openapi";
|
|
15
|
-
|
|
16
|
-
import { OpenAPISpec } from "./types";
|
|
17
|
-
|
|
18
|
-
export async function loadAndBundleSpec(
|
|
19
|
-
specUrlOrObject: object | string
|
|
20
|
-
): Promise<OpenAPISpec> {
|
|
21
|
-
const config = new Config({} as ResolvedConfig);
|
|
22
|
-
const bundleOpts = {
|
|
23
|
-
config,
|
|
24
|
-
base: process.cwd(),
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
if (typeof specUrlOrObject === "object" && specUrlOrObject !== null) {
|
|
28
|
-
bundleOpts["doc"] = {
|
|
29
|
-
source: { absoluteRef: "" } as Source,
|
|
30
|
-
parsed: specUrlOrObject,
|
|
31
|
-
} as Document;
|
|
32
|
-
} else {
|
|
33
|
-
bundleOpts["ref"] = specUrlOrObject;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Force dereference ?
|
|
37
|
-
// bundleOpts["dereference"] = true;
|
|
38
|
-
|
|
39
|
-
const {
|
|
40
|
-
bundle: { parsed },
|
|
41
|
-
} = await bundle(bundleOpts);
|
|
42
|
-
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec> {
|
|
46
|
-
console.warn(
|
|
47
|
-
"[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0"
|
|
48
|
-
);
|
|
49
|
-
return new Promise<OpenAPISpec>((resolve, reject) =>
|
|
50
|
-
convertObj(
|
|
51
|
-
spec,
|
|
52
|
-
{ patch: true, warnOnly: true, text: "{}", anchors: true },
|
|
53
|
-
(err, res) => {
|
|
54
|
-
// TODO: log any warnings
|
|
55
|
-
if (err) {
|
|
56
|
-
return reject(err);
|
|
57
|
-
}
|
|
58
|
-
resolve(res && (res.openapi as any));
|
|
59
|
-
}
|
|
60
|
-
)
|
|
61
|
-
);
|
|
62
|
-
}
|