docusaurus-plugin-openapi-docs 1.1.2 → 1.1.5
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/markdown/createLogo.d.ts +2 -0
- package/lib/markdown/createLogo.js +19 -0
- package/lib/markdown/createRequestBodyDetails.d.ts +9 -2
- package/lib/markdown/createRequestBodyDetails.js +2 -2
- package/lib/markdown/createRequestSchema.d.ts +21 -0
- package/lib/markdown/createRequestSchema.js +680 -0
- package/lib/markdown/{createSchemaDetails.d.ts → createResponseSchema.d.ts} +2 -2
- package/lib/markdown/{createSchemaDetails.js → createResponseSchema.js} +289 -48
- package/lib/markdown/createStatusCodes.js +117 -4
- package/lib/markdown/index.d.ts +1 -1
- package/lib/markdown/index.js +12 -3
- package/lib/markdown/schema.js +50 -14
- package/lib/markdown/schema.test.js +18 -18
- package/lib/openapi/createExample.js +27 -14
- package/lib/openapi/openapi.d.ts +1 -1
- package/lib/openapi/openapi.js +30 -19
- package/lib/openapi/types.d.ts +8 -1
- package/lib/openapi/utils/loadAndResolveSpec.js +13 -0
- package/lib/sidebars/index.d.ts +1 -1
- package/lib/sidebars/index.js +14 -5
- package/lib/types.d.ts +1 -1
- package/package.json +8 -8
- package/src/markdown/createLogo.ts +21 -0
- package/src/markdown/createRequestBodyDetails.ts +11 -4
- package/src/markdown/createRequestSchema.ts +848 -0
- package/src/markdown/{createSchemaDetails.ts → createResponseSchema.ts} +350 -54
- package/src/markdown/createStatusCodes.ts +149 -9
- package/src/markdown/index.ts +34 -3
- package/src/markdown/schema.test.ts +18 -18
- package/src/markdown/schema.ts +60 -14
- package/src/openapi/createExample.ts +31 -14
- package/src/openapi/openapi.ts +21 -13
- package/src/openapi/types.ts +9 -1
- package/src/openapi/utils/loadAndResolveSpec.ts +13 -0
- package/src/sidebars/index.ts +17 -7
- package/src/types.ts +1 -1
package/src/openapi/openapi.ts
CHANGED
|
@@ -13,7 +13,8 @@ import sdk from "@paloaltonetworks/postman-collection";
|
|
|
13
13
|
import Collection from "@paloaltonetworks/postman-collection";
|
|
14
14
|
import chalk from "chalk";
|
|
15
15
|
import fs from "fs-extra";
|
|
16
|
-
import
|
|
16
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
17
|
+
import kebabCase from "lodash/kebabCase";
|
|
17
18
|
|
|
18
19
|
import { isURL } from "../index";
|
|
19
20
|
import {
|
|
@@ -54,7 +55,7 @@ async function createPostmanCollection(
|
|
|
54
55
|
openapiData: OpenApiObject
|
|
55
56
|
): Promise<Collection> {
|
|
56
57
|
// Create copy of openapiData
|
|
57
|
-
const data =
|
|
58
|
+
const data = cloneDeep(openapiData) as OpenApiObject;
|
|
58
59
|
|
|
59
60
|
// Including `servers` breaks postman, so delete all of them.
|
|
60
61
|
delete data.servers;
|
|
@@ -102,7 +103,6 @@ function createItems(
|
|
|
102
103
|
unversionedId: tagId,
|
|
103
104
|
title: description ?? "",
|
|
104
105
|
description: description ?? "",
|
|
105
|
-
slug: "/" + tagId,
|
|
106
106
|
frontMatter: {},
|
|
107
107
|
tag: {
|
|
108
108
|
...tag,
|
|
@@ -120,15 +120,14 @@ function createItems(
|
|
|
120
120
|
unversionedId: infoId,
|
|
121
121
|
title: openapiData.info.title,
|
|
122
122
|
description: openapiData.info.description,
|
|
123
|
-
slug: "/" + infoId,
|
|
124
123
|
frontMatter: {},
|
|
125
124
|
securitySchemes: openapiData.components?.securitySchemes,
|
|
126
125
|
info: {
|
|
127
126
|
...openapiData.info,
|
|
128
|
-
tags: openapiData.tags
|
|
129
|
-
getTagDisplayName(tagName.name!, openapiData.tags ?? [])
|
|
130
|
-
),
|
|
127
|
+
tags: openapiData.tags,
|
|
131
128
|
title: openapiData.info.title ?? "Introduction",
|
|
129
|
+
logo: openapiData.info["x-logo"]! as any,
|
|
130
|
+
darkLogo: openapiData.info["x-dark-logo"]! as any,
|
|
132
131
|
},
|
|
133
132
|
};
|
|
134
133
|
items.push(infoPage);
|
|
@@ -174,6 +173,18 @@ function createItems(
|
|
|
174
173
|
jsonRequestBodyExample = sampleFromSchema(body.schema);
|
|
175
174
|
}
|
|
176
175
|
|
|
176
|
+
// Handle vendor JSON media types
|
|
177
|
+
const bodyContent = operationObject.requestBody?.content;
|
|
178
|
+
if (bodyContent) {
|
|
179
|
+
const firstBodyContentKey = Object.keys(bodyContent)[0];
|
|
180
|
+
if (firstBodyContentKey.endsWith("+json")) {
|
|
181
|
+
const firstBody = bodyContent[firstBodyContentKey];
|
|
182
|
+
if (firstBody?.schema) {
|
|
183
|
+
jsonRequestBodyExample = sampleFromSchema(firstBody.schema);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
177
188
|
// TODO: Don't include summary temporarilly
|
|
178
189
|
const { summary, ...defaults } = operationObject;
|
|
179
190
|
|
|
@@ -184,13 +195,10 @@ function createItems(
|
|
|
184
195
|
unversionedId: baseId,
|
|
185
196
|
title: title,
|
|
186
197
|
description: description ?? "",
|
|
187
|
-
slug: "/" + baseId,
|
|
188
198
|
frontMatter: {},
|
|
189
199
|
api: {
|
|
190
200
|
...defaults,
|
|
191
|
-
tags: operationObject.tags
|
|
192
|
-
getTagDisplayName(tagName, openapiData.tags ?? [])
|
|
193
|
-
),
|
|
201
|
+
tags: operationObject.tags,
|
|
194
202
|
method,
|
|
195
203
|
path,
|
|
196
204
|
servers,
|
|
@@ -291,7 +299,7 @@ export async function readOpenapiFiles(
|
|
|
291
299
|
export async function processOpenapiFiles(
|
|
292
300
|
files: OpenApiFiles[],
|
|
293
301
|
sidebarOptions: SidebarOptions
|
|
294
|
-
): Promise<[ApiMetadata[], TagObject[]]> {
|
|
302
|
+
): Promise<[ApiMetadata[], TagObject[][]]> {
|
|
295
303
|
const promises = files.map(async (file) => {
|
|
296
304
|
if (file.data !== undefined) {
|
|
297
305
|
const processedFile = await processOpenapiFile(file.data, sidebarOptions);
|
|
@@ -326,7 +334,7 @@ export async function processOpenapiFiles(
|
|
|
326
334
|
// Remove undefined tags due to transient parsing errors
|
|
327
335
|
return x !== undefined;
|
|
328
336
|
});
|
|
329
|
-
return [items as ApiMetadata[], tags as TagObject[]];
|
|
337
|
+
return [items as ApiMetadata[], tags as TagObject[][]];
|
|
330
338
|
}
|
|
331
339
|
|
|
332
340
|
export async function processOpenapiFile(
|
package/src/openapi/types.ts
CHANGED
|
@@ -41,7 +41,15 @@ export interface InfoObject {
|
|
|
41
41
|
contact?: ContactObject;
|
|
42
42
|
license?: LicenseObject;
|
|
43
43
|
version: string;
|
|
44
|
-
tags?:
|
|
44
|
+
tags?: TagObject[];
|
|
45
|
+
"x-logo"?: LogoObject;
|
|
46
|
+
"x-dark-logo"?: LogoObject;
|
|
47
|
+
logo?: LogoObject;
|
|
48
|
+
darkLogo?: LogoObject;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface LogoObject {
|
|
52
|
+
url?: string;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
export interface ContactObject {
|
|
@@ -14,6 +14,7 @@ import chalk from "chalk";
|
|
|
14
14
|
import { convertObj } from "swagger2openapi";
|
|
15
15
|
|
|
16
16
|
import { OpenApiObject } from "../types";
|
|
17
|
+
import { OpenAPIParser } from "./services/OpenAPIParser";
|
|
17
18
|
|
|
18
19
|
function serializer(replacer: any, cycleReplacer: any) {
|
|
19
20
|
var stack: any = [],
|
|
@@ -26,6 +27,18 @@ function serializer(replacer: any, cycleReplacer: any) {
|
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
return function (key: any, value: any) {
|
|
30
|
+
// Resolve discriminator ref pointers
|
|
31
|
+
if (value?.discriminator !== undefined) {
|
|
32
|
+
const parser = new OpenAPIParser(stack[0]);
|
|
33
|
+
for (let [k, v] of Object.entries(value.discriminator.mapping)) {
|
|
34
|
+
const discriminator = k as string;
|
|
35
|
+
if (typeof v === "string" && v.charAt(0) === "#") {
|
|
36
|
+
const ref = v as string;
|
|
37
|
+
const resolvedRef = parser.byRef(ref);
|
|
38
|
+
value.discriminator.mapping[discriminator] = resolvedRef;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
29
42
|
if (stack.length > 0) {
|
|
30
43
|
// @ts-ignore
|
|
31
44
|
var thisPos = stack.indexOf(this);
|
package/src/sidebars/index.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
+
import path from "path";
|
|
9
|
+
|
|
8
10
|
import {
|
|
9
11
|
ProcessedSidebar,
|
|
10
12
|
SidebarItemCategory,
|
|
@@ -35,7 +37,7 @@ function groupByTags(
|
|
|
35
37
|
items: ApiPageMetadata[],
|
|
36
38
|
sidebarOptions: SidebarOptions,
|
|
37
39
|
options: APIOptions,
|
|
38
|
-
tags: TagObject[],
|
|
40
|
+
tags: TagObject[][],
|
|
39
41
|
docPath: string
|
|
40
42
|
): ProcessedSidebar {
|
|
41
43
|
const { outputDir, label } = options;
|
|
@@ -58,12 +60,20 @@ function groupByTags(
|
|
|
58
60
|
});
|
|
59
61
|
|
|
60
62
|
// TODO: make sure we only take the first tag
|
|
61
|
-
const
|
|
63
|
+
const operationTags = uniq(
|
|
62
64
|
apiItems
|
|
63
65
|
.flatMap((item) => item.api.tags)
|
|
64
66
|
.filter((item): item is string => !!item)
|
|
65
67
|
);
|
|
66
68
|
|
|
69
|
+
// Only include operation tags that are globally defined
|
|
70
|
+
const apiTags: string[] = [];
|
|
71
|
+
tags.flat().forEach((tag) => {
|
|
72
|
+
if (operationTags.includes(tag.name!)) {
|
|
73
|
+
apiTags.push(tag.name!);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
67
77
|
const basePath = docPath
|
|
68
78
|
? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
|
|
69
79
|
: outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
|
|
@@ -105,7 +115,7 @@ function groupByTags(
|
|
|
105
115
|
);
|
|
106
116
|
const tagObject = tags.flat().find(
|
|
107
117
|
(t) =>
|
|
108
|
-
|
|
118
|
+
tag === t.name ?? {
|
|
109
119
|
name: tag,
|
|
110
120
|
description: `${tag} Index`,
|
|
111
121
|
}
|
|
@@ -139,14 +149,14 @@ function groupByTags(
|
|
|
139
149
|
type: "generated-index" as "generated-index",
|
|
140
150
|
title: tag,
|
|
141
151
|
slug: label
|
|
142
|
-
? "/category
|
|
143
|
-
: "/category
|
|
152
|
+
? path.join("/category", basePath, kebabCase(label), kebabCase(tag))
|
|
153
|
+
: path.join("/category", basePath, kebabCase(tag)),
|
|
144
154
|
} as SidebarItemCategoryLinkConfig;
|
|
145
155
|
}
|
|
146
156
|
|
|
147
157
|
return {
|
|
148
158
|
type: "category" as const,
|
|
149
|
-
label: tag,
|
|
159
|
+
label: tagObject?.["x-displayName"] ?? tag,
|
|
150
160
|
link: linkConfig,
|
|
151
161
|
collapsible: sidebarCollapsible,
|
|
152
162
|
collapsed: sidebarCollapsed,
|
|
@@ -189,7 +199,7 @@ export default function generateSidebarSlice(
|
|
|
189
199
|
sidebarOptions: SidebarOptions,
|
|
190
200
|
options: APIOptions,
|
|
191
201
|
api: ApiMetadata[],
|
|
192
|
-
tags: TagObject[],
|
|
202
|
+
tags: TagObject[][],
|
|
193
203
|
docPath: string
|
|
194
204
|
) {
|
|
195
205
|
let sidebarSlice: ProcessedSidebar = [];
|
package/src/types.ts
CHANGED
|
@@ -76,7 +76,7 @@ export interface ApiMetadataBase {
|
|
|
76
76
|
description: string;
|
|
77
77
|
source: string; // @site aliased source => "@site/docs/folder/subFolder/subSubFolder/myDoc.md"
|
|
78
78
|
sourceDirName: string; // relative to the versioned docs folder (can be ".") => "folder/subFolder/subSubFolder"
|
|
79
|
-
slug
|
|
79
|
+
slug?: string;
|
|
80
80
|
permalink: string;
|
|
81
81
|
sidebarPosition?: number;
|
|
82
82
|
frontMatter: Record<string, unknown>;
|