docusaurus-plugin-openapi-docs 1.0.0 → 1.0.3
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 +8 -7
- package/lib/index.d.ts +1 -0
- package/lib/index.js +80 -9
- package/lib/markdown/createAuthentication.d.ts +2 -0
- package/lib/markdown/createAuthentication.js +139 -0
- package/lib/markdown/createContactInfo.d.ts +2 -0
- package/lib/markdown/createContactInfo.js +49 -0
- package/lib/markdown/createLicense.d.ts +2 -0
- package/lib/markdown/createLicense.js +33 -0
- package/lib/markdown/createSchemaDetails.js +4 -1
- package/lib/markdown/createStatusCodes.js +1 -1
- package/lib/markdown/createTermsOfService.d.ts +1 -0
- package/lib/markdown/createTermsOfService.js +32 -0
- package/lib/markdown/index.d.ts +3 -2
- package/lib/markdown/index.js +17 -3
- package/lib/openapi/createExample.js +59 -49
- package/lib/openapi/openapi.d.ts +5 -4
- package/lib/openapi/openapi.js +94 -50
- package/lib/openapi/openapi.test.js +0 -6
- package/lib/openapi/types.d.ts +5 -1
- 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/{markdown/createRequestBodyTable.js → openapi/utils/types.js} +0 -6
- package/lib/sidebars/index.d.ts +2 -1
- package/lib/sidebars/index.js +87 -30
- package/lib/types.d.ts +14 -3
- package/package.json +19 -11
- package/src/index.ts +108 -11
- package/src/markdown/createAuthentication.ts +160 -0
- package/src/markdown/createContactInfo.ts +52 -0
- package/src/markdown/createLicense.ts +34 -0
- package/src/markdown/createSchemaDetails.ts +6 -2
- package/src/markdown/createStatusCodes.ts +1 -1
- package/src/markdown/createTermsOfService.ts +30 -0
- package/src/markdown/index.ts +23 -3
- package/src/openapi/createExample.ts +59 -50
- package/src/openapi/openapi.test.ts +0 -6
- package/src/openapi/openapi.ts +115 -53
- package/src/openapi/types.ts +5 -1
- package/src/openapi/utils/loadAndBundleSpec.ts +62 -0
- package/src/openapi/utils/types.ts +303 -0
- package/src/{markdown/createRequestBodyTable.ts → postman-collection.d.ts} +2 -9
- package/src/sidebars/index.ts +108 -31
- package/src/types.ts +15 -3
- package/lib/markdown/createFullWidthTable.d.ts +0 -2
- package/lib/markdown/createFullWidthTable.js +0 -18
- package/lib/markdown/createParamsTable.d.ts +0 -7
- package/lib/markdown/createParamsTable.js +0 -80
- package/lib/markdown/createRequestBodyTable.d.ts +0 -6
- package/lib/markdown/createSchemaTable.d.ts +0 -14
- package/lib/markdown/createSchemaTable.js +0 -217
- package/src/markdown/createFullWidthTable.ts +0 -16
- package/src/markdown/createParamsTable.ts +0 -102
- package/src/markdown/createSchemaTable.ts +0 -275
- 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
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
|
2
|
+
export interface OpenAPISpec {
|
|
3
|
+
openapi: string;
|
|
4
|
+
info: OpenAPIInfo;
|
|
5
|
+
servers?: OpenAPIServer[];
|
|
6
|
+
paths: OpenAPIPaths;
|
|
7
|
+
components?: OpenAPIComponents;
|
|
8
|
+
security?: OpenAPISecurityRequirement[];
|
|
9
|
+
tags?: OpenAPITag[];
|
|
10
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
11
|
+
"x-webhooks"?: OpenAPIPaths;
|
|
12
|
+
webhooks?: OpenAPIPaths;
|
|
13
|
+
}
|
|
14
|
+
export interface OpenAPIInfo {
|
|
15
|
+
title: string;
|
|
16
|
+
version: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
summary?: string;
|
|
19
|
+
termsOfService?: string;
|
|
20
|
+
contact?: OpenAPIContact;
|
|
21
|
+
license?: OpenAPILicense;
|
|
22
|
+
}
|
|
23
|
+
export interface OpenAPIServer {
|
|
24
|
+
url: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
variables?: {
|
|
27
|
+
[name: string]: OpenAPIServerVariable;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface OpenAPIServerVariable {
|
|
31
|
+
enum?: string[];
|
|
32
|
+
default: string;
|
|
33
|
+
description?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface OpenAPIPaths {
|
|
36
|
+
[path: string]: OpenAPIPath;
|
|
37
|
+
}
|
|
38
|
+
export interface OpenAPIRef {
|
|
39
|
+
$ref: string;
|
|
40
|
+
}
|
|
41
|
+
export declare type Referenced<T> = OpenAPIRef | T;
|
|
42
|
+
export interface OpenAPIPath {
|
|
43
|
+
summary?: string;
|
|
44
|
+
description?: string;
|
|
45
|
+
get?: OpenAPIOperation;
|
|
46
|
+
put?: OpenAPIOperation;
|
|
47
|
+
post?: OpenAPIOperation;
|
|
48
|
+
delete?: OpenAPIOperation;
|
|
49
|
+
options?: OpenAPIOperation;
|
|
50
|
+
head?: OpenAPIOperation;
|
|
51
|
+
patch?: OpenAPIOperation;
|
|
52
|
+
trace?: OpenAPIOperation;
|
|
53
|
+
servers?: OpenAPIServer[];
|
|
54
|
+
parameters?: Array<Referenced<OpenAPIParameter>>;
|
|
55
|
+
$ref?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface OpenAPIXCodeSample {
|
|
58
|
+
lang: string;
|
|
59
|
+
label?: string;
|
|
60
|
+
source: string;
|
|
61
|
+
}
|
|
62
|
+
export interface OpenAPIOperation {
|
|
63
|
+
tags?: string[];
|
|
64
|
+
summary?: string;
|
|
65
|
+
description?: string;
|
|
66
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
67
|
+
operationId?: string;
|
|
68
|
+
parameters?: Array<Referenced<OpenAPIParameter>>;
|
|
69
|
+
requestBody?: Referenced<OpenAPIRequestBody>;
|
|
70
|
+
responses: OpenAPIResponses;
|
|
71
|
+
callbacks?: {
|
|
72
|
+
[name: string]: Referenced<OpenAPICallback>;
|
|
73
|
+
};
|
|
74
|
+
deprecated?: boolean;
|
|
75
|
+
security?: OpenAPISecurityRequirement[];
|
|
76
|
+
servers?: OpenAPIServer[];
|
|
77
|
+
"x-codeSamples"?: OpenAPIXCodeSample[];
|
|
78
|
+
"x-code-samples"?: OpenAPIXCodeSample[];
|
|
79
|
+
}
|
|
80
|
+
export interface OpenAPIParameter {
|
|
81
|
+
name: string;
|
|
82
|
+
in?: OpenAPIParameterLocation;
|
|
83
|
+
description?: string;
|
|
84
|
+
required?: boolean;
|
|
85
|
+
deprecated?: boolean;
|
|
86
|
+
allowEmptyValue?: boolean;
|
|
87
|
+
style?: OpenAPIParameterStyle;
|
|
88
|
+
explode?: boolean;
|
|
89
|
+
allowReserved?: boolean;
|
|
90
|
+
schema?: Referenced<OpenAPISchema>;
|
|
91
|
+
example?: any;
|
|
92
|
+
examples?: {
|
|
93
|
+
[media: string]: Referenced<OpenAPIExample>;
|
|
94
|
+
};
|
|
95
|
+
content?: {
|
|
96
|
+
[media: string]: OpenAPIMediaType;
|
|
97
|
+
};
|
|
98
|
+
encoding?: Record<string, OpenAPIEncoding>;
|
|
99
|
+
const?: any;
|
|
100
|
+
}
|
|
101
|
+
export interface OpenAPIExample {
|
|
102
|
+
value: any;
|
|
103
|
+
summary?: string;
|
|
104
|
+
description?: string;
|
|
105
|
+
externalValue?: string;
|
|
106
|
+
}
|
|
107
|
+
export interface OpenAPISchema {
|
|
108
|
+
$ref?: string;
|
|
109
|
+
type?: string | string[];
|
|
110
|
+
properties?: {
|
|
111
|
+
[name: string]: OpenAPISchema;
|
|
112
|
+
};
|
|
113
|
+
patternProperties?: {
|
|
114
|
+
[name: string]: OpenAPISchema;
|
|
115
|
+
};
|
|
116
|
+
additionalProperties?: boolean | OpenAPISchema;
|
|
117
|
+
unevaluatedProperties?: boolean | OpenAPISchema;
|
|
118
|
+
description?: string;
|
|
119
|
+
default?: any;
|
|
120
|
+
items?: OpenAPISchema | OpenAPISchema[] | boolean;
|
|
121
|
+
required?: string[];
|
|
122
|
+
readOnly?: boolean;
|
|
123
|
+
writeOnly?: boolean;
|
|
124
|
+
deprecated?: boolean;
|
|
125
|
+
format?: string;
|
|
126
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
127
|
+
discriminator?: OpenAPIDiscriminator;
|
|
128
|
+
nullable?: boolean;
|
|
129
|
+
oneOf?: OpenAPISchema[];
|
|
130
|
+
anyOf?: OpenAPISchema[];
|
|
131
|
+
allOf?: OpenAPISchema[];
|
|
132
|
+
not?: OpenAPISchema;
|
|
133
|
+
title?: string;
|
|
134
|
+
multipleOf?: number;
|
|
135
|
+
maximum?: number;
|
|
136
|
+
exclusiveMaximum?: boolean | number;
|
|
137
|
+
minimum?: number;
|
|
138
|
+
exclusiveMinimum?: boolean | number;
|
|
139
|
+
maxLength?: number;
|
|
140
|
+
minLength?: number;
|
|
141
|
+
pattern?: string;
|
|
142
|
+
maxItems?: number;
|
|
143
|
+
minItems?: number;
|
|
144
|
+
uniqueItems?: boolean;
|
|
145
|
+
maxProperties?: number;
|
|
146
|
+
minProperties?: number;
|
|
147
|
+
enum?: any[];
|
|
148
|
+
example?: any;
|
|
149
|
+
if?: OpenAPISchema;
|
|
150
|
+
else?: OpenAPISchema;
|
|
151
|
+
then?: OpenAPISchema;
|
|
152
|
+
examples?: any[];
|
|
153
|
+
const?: string;
|
|
154
|
+
contentEncoding?: string;
|
|
155
|
+
contentMediaType?: string;
|
|
156
|
+
prefixItems?: OpenAPISchema[];
|
|
157
|
+
additionalItems?: OpenAPISchema | boolean;
|
|
158
|
+
}
|
|
159
|
+
export interface OpenAPIDiscriminator {
|
|
160
|
+
propertyName: string;
|
|
161
|
+
mapping?: {
|
|
162
|
+
[name: string]: string;
|
|
163
|
+
};
|
|
164
|
+
"x-explicitMappingOnly"?: boolean;
|
|
165
|
+
}
|
|
166
|
+
export interface OpenAPIMediaType {
|
|
167
|
+
schema?: Referenced<OpenAPISchema>;
|
|
168
|
+
example?: any;
|
|
169
|
+
examples?: {
|
|
170
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
171
|
+
};
|
|
172
|
+
encoding?: {
|
|
173
|
+
[field: string]: OpenAPIEncoding;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
export interface OpenAPIEncoding {
|
|
177
|
+
contentType: string;
|
|
178
|
+
headers?: {
|
|
179
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
180
|
+
};
|
|
181
|
+
style: OpenAPIParameterStyle;
|
|
182
|
+
explode: boolean;
|
|
183
|
+
allowReserved: boolean;
|
|
184
|
+
}
|
|
185
|
+
export declare type OpenAPIParameterLocation = "query" | "header" | "path" | "cookie";
|
|
186
|
+
export declare type OpenAPIParameterStyle = "matrix" | "label" | "form" | "simple" | "spaceDelimited" | "pipeDelimited" | "deepObject";
|
|
187
|
+
export interface OpenAPIRequestBody {
|
|
188
|
+
description?: string;
|
|
189
|
+
required?: boolean;
|
|
190
|
+
content: {
|
|
191
|
+
[mime: string]: OpenAPIMediaType;
|
|
192
|
+
};
|
|
193
|
+
"x-examples"?: {
|
|
194
|
+
[mime: string]: {
|
|
195
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
"x-example"?: {
|
|
199
|
+
[mime: string]: any;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export interface OpenAPIResponses {
|
|
203
|
+
[code: string]: Referenced<OpenAPIResponse>;
|
|
204
|
+
}
|
|
205
|
+
export interface OpenAPIResponse extends Pick<OpenAPIRequestBody, "description" | "x-examples" | "x-example"> {
|
|
206
|
+
headers?: {
|
|
207
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
208
|
+
};
|
|
209
|
+
links?: {
|
|
210
|
+
[name: string]: Referenced<OpenAPILink>;
|
|
211
|
+
};
|
|
212
|
+
content?: {
|
|
213
|
+
[mime: string]: OpenAPIMediaType;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
export interface OpenAPILink {
|
|
217
|
+
$ref?: string;
|
|
218
|
+
}
|
|
219
|
+
export declare type OpenAPIHeader = Omit<OpenAPIParameter, "in" | "name">;
|
|
220
|
+
export interface OpenAPICallback {
|
|
221
|
+
[name: string]: OpenAPIPath;
|
|
222
|
+
}
|
|
223
|
+
export interface OpenAPIComponents {
|
|
224
|
+
schemas?: {
|
|
225
|
+
[name: string]: Referenced<OpenAPISchema>;
|
|
226
|
+
};
|
|
227
|
+
responses?: {
|
|
228
|
+
[name: string]: Referenced<OpenAPIResponse>;
|
|
229
|
+
};
|
|
230
|
+
parameters?: {
|
|
231
|
+
[name: string]: Referenced<OpenAPIParameter>;
|
|
232
|
+
};
|
|
233
|
+
examples?: {
|
|
234
|
+
[name: string]: Referenced<OpenAPIExample>;
|
|
235
|
+
};
|
|
236
|
+
requestBodies?: {
|
|
237
|
+
[name: string]: Referenced<OpenAPIRequestBody>;
|
|
238
|
+
};
|
|
239
|
+
headers?: {
|
|
240
|
+
[name: string]: Referenced<OpenAPIHeader>;
|
|
241
|
+
};
|
|
242
|
+
securitySchemes?: {
|
|
243
|
+
[name: string]: Referenced<OpenAPISecurityScheme>;
|
|
244
|
+
};
|
|
245
|
+
links?: {
|
|
246
|
+
[name: string]: Referenced<OpenAPILink>;
|
|
247
|
+
};
|
|
248
|
+
callbacks?: {
|
|
249
|
+
[name: string]: Referenced<OpenAPICallback>;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
export interface OpenAPISecurityRequirement {
|
|
253
|
+
[name: string]: string[];
|
|
254
|
+
}
|
|
255
|
+
export interface OpenAPISecurityScheme {
|
|
256
|
+
type: "apiKey" | "http" | "oauth2" | "openIdConnect";
|
|
257
|
+
description?: string;
|
|
258
|
+
name?: string;
|
|
259
|
+
in?: "query" | "header" | "cookie";
|
|
260
|
+
scheme?: string;
|
|
261
|
+
bearerFormat: string;
|
|
262
|
+
flows: {
|
|
263
|
+
implicit?: {
|
|
264
|
+
refreshUrl?: string;
|
|
265
|
+
scopes: Record<string, string>;
|
|
266
|
+
authorizationUrl: string;
|
|
267
|
+
};
|
|
268
|
+
password?: {
|
|
269
|
+
refreshUrl?: string;
|
|
270
|
+
scopes: Record<string, string>;
|
|
271
|
+
tokenUrl: string;
|
|
272
|
+
};
|
|
273
|
+
clientCredentials?: {
|
|
274
|
+
refreshUrl?: string;
|
|
275
|
+
scopes: Record<string, string>;
|
|
276
|
+
tokenUrl: string;
|
|
277
|
+
};
|
|
278
|
+
authorizationCode?: {
|
|
279
|
+
refreshUrl?: string;
|
|
280
|
+
scopes: Record<string, string>;
|
|
281
|
+
tokenUrl: string;
|
|
282
|
+
};
|
|
283
|
+
};
|
|
284
|
+
openIdConnectUrl?: string;
|
|
285
|
+
}
|
|
286
|
+
export interface OpenAPITag {
|
|
287
|
+
name: string;
|
|
288
|
+
description?: string;
|
|
289
|
+
externalDocs?: OpenAPIExternalDocumentation;
|
|
290
|
+
"x-displayName"?: string;
|
|
291
|
+
}
|
|
292
|
+
export interface OpenAPIExternalDocumentation {
|
|
293
|
+
description?: string;
|
|
294
|
+
url: string;
|
|
295
|
+
}
|
|
296
|
+
export interface OpenAPIContact {
|
|
297
|
+
name?: string;
|
|
298
|
+
url?: string;
|
|
299
|
+
email?: string;
|
|
300
|
+
}
|
|
301
|
+
export interface OpenAPILicense {
|
|
302
|
+
name: string;
|
|
303
|
+
url?: string;
|
|
304
|
+
identifier?: string;
|
|
305
|
+
}
|
|
306
|
+
export {};
|
|
@@ -6,9 +6,3 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
* ========================================================================== */
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.createRequestBodyTable = void 0;
|
|
10
|
-
const createSchemaTable_1 = require("./createSchemaTable");
|
|
11
|
-
function createRequestBodyTable({ title, body }) {
|
|
12
|
-
return (0, createSchemaTable_1.createSchemaTable)({ title, body });
|
|
13
|
-
}
|
|
14
|
-
exports.createRequestBodyTable = createRequestBodyTable;
|
package/lib/sidebars/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ProcessedSidebar } from "@docusaurus/plugin-content-docs/src/sidebars/types";
|
|
2
|
+
import { TagObject } from "../openapi/types";
|
|
2
3
|
import type { SidebarOptions, APIOptions, ApiMetadata } from "../types";
|
|
3
|
-
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[]): ProcessedSidebar;
|
|
4
|
+
export default function generateSidebarSlice(sidebarOptions: SidebarOptions, options: APIOptions, api: ApiMetadata[], tags: TagObject[]): ProcessedSidebar;
|
package/lib/sidebars/index.js
CHANGED
|
@@ -10,25 +10,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const clsx_1 = __importDefault(require("clsx"));
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
13
14
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
14
15
|
function isApiItem(item) {
|
|
15
16
|
return item.type === "api";
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// type: "link" as const,
|
|
22
|
-
// label: item.title,
|
|
23
|
-
// href: item.permalink,
|
|
24
|
-
// docId: item.id,
|
|
25
|
-
// };
|
|
26
|
-
// });
|
|
18
|
+
function isInfoItem(item) {
|
|
19
|
+
return item.type === "info";
|
|
20
|
+
}
|
|
21
|
+
function groupByTags(items, sidebarOptions, options, tags) {
|
|
27
22
|
const { outputDir } = options;
|
|
28
|
-
const { sidebarCollapsed, sidebarCollapsible, customProps } = sidebarOptions;
|
|
23
|
+
const { sidebarCollapsed, sidebarCollapsible, customProps, categoryLinkSource, } = sidebarOptions;
|
|
29
24
|
const apiItems = items.filter(isApiItem);
|
|
25
|
+
const infoItems = items.filter(isInfoItem);
|
|
26
|
+
const intros = infoItems.map((item) => {
|
|
27
|
+
return {
|
|
28
|
+
id: item.id,
|
|
29
|
+
title: item.title,
|
|
30
|
+
description: item.description,
|
|
31
|
+
tags: item.info.tags,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
30
34
|
// TODO: make sure we only take the first tag
|
|
31
|
-
const
|
|
35
|
+
const apiTags = (0, uniq_1.default)(apiItems
|
|
32
36
|
.flatMap((item) => item.api.tags)
|
|
33
37
|
.filter((item) => !!item));
|
|
34
38
|
// TODO: optimize this or make it a function
|
|
@@ -51,11 +55,54 @@ function groupByTags(items, sidebarOptions, options) {
|
|
|
51
55
|
}, item.api.method),
|
|
52
56
|
};
|
|
53
57
|
}
|
|
54
|
-
|
|
58
|
+
let rootIntroDoc = undefined;
|
|
59
|
+
if (infoItems.length === 1) {
|
|
60
|
+
const infoItem = infoItems[0];
|
|
61
|
+
const id = infoItem.id;
|
|
62
|
+
rootIntroDoc = {
|
|
63
|
+
type: "doc",
|
|
64
|
+
id: `${basePath}/${id}`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const tagged = apiTags
|
|
55
68
|
.map((tag) => {
|
|
69
|
+
// Map info object to tag
|
|
70
|
+
const taggedInfoObject = intros.find((i) => i.tags ? i.tags.includes(tag) : undefined);
|
|
71
|
+
const tagObject = tags.flat().find((t) => {
|
|
72
|
+
var _a;
|
|
73
|
+
return (_a = (tag === t.name || tag === t["x-displayName"])) !== null && _a !== void 0 ? _a : {
|
|
74
|
+
name: tag,
|
|
75
|
+
description: `${tag} Index`,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
// TODO: perhaps move this into a getLinkConfig() function
|
|
79
|
+
let linkConfig = undefined;
|
|
80
|
+
if (taggedInfoObject !== undefined && categoryLinkSource === "info") {
|
|
81
|
+
linkConfig = {
|
|
82
|
+
type: "doc",
|
|
83
|
+
id: `${basePath}/${taggedInfoObject.id}`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// TODO: perhaps move this into a getLinkConfig() function
|
|
87
|
+
if (tagObject !== undefined && categoryLinkSource === "tag") {
|
|
88
|
+
const tagId = (0, lodash_1.kebabCase)(tagObject.name);
|
|
89
|
+
linkConfig = {
|
|
90
|
+
type: "doc",
|
|
91
|
+
id: `${basePath}/${tagId}`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
// Default behavior
|
|
95
|
+
if (categoryLinkSource === undefined) {
|
|
96
|
+
linkConfig = {
|
|
97
|
+
type: "generated-index",
|
|
98
|
+
title: tag,
|
|
99
|
+
slug: "/category/" + (0, lodash_1.kebabCase)(tag),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
56
102
|
return {
|
|
57
103
|
type: "category",
|
|
58
104
|
label: tag,
|
|
105
|
+
link: linkConfig,
|
|
59
106
|
collapsible: sidebarCollapsible,
|
|
60
107
|
collapsed: sidebarCollapsed,
|
|
61
108
|
items: apiItems
|
|
@@ -64,25 +111,35 @@ function groupByTags(items, sidebarOptions, options) {
|
|
|
64
111
|
};
|
|
65
112
|
})
|
|
66
113
|
.filter((item) => item.items.length > 0); // Filter out any categories with no items.
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
114
|
+
// Handle items with no tag
|
|
115
|
+
const untaggedItems = apiItems
|
|
116
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
117
|
+
.map(createDocItem);
|
|
118
|
+
let untagged = [];
|
|
119
|
+
if (untaggedItems.length > 0) {
|
|
120
|
+
untagged = [
|
|
121
|
+
{
|
|
122
|
+
type: "category",
|
|
123
|
+
label: "UNTAGGED",
|
|
124
|
+
collapsible: sidebarCollapsible,
|
|
125
|
+
collapsed: sidebarCollapsed,
|
|
126
|
+
items: apiItems
|
|
127
|
+
.filter(({ api }) => api.tags === undefined || api.tags.length === 0)
|
|
128
|
+
.map(createDocItem),
|
|
129
|
+
},
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
// Shift root intro doc to top of sidebar
|
|
133
|
+
// TODO: Add input validation for categoryLinkSource options
|
|
134
|
+
if (rootIntroDoc && categoryLinkSource !== "info") {
|
|
135
|
+
tagged.unshift(rootIntroDoc);
|
|
136
|
+
}
|
|
137
|
+
return [...tagged, ...untagged];
|
|
81
138
|
}
|
|
82
|
-
function generateSidebarSlice(sidebarOptions, options, api) {
|
|
139
|
+
function generateSidebarSlice(sidebarOptions, options, api, tags) {
|
|
83
140
|
let sidebarSlice = [];
|
|
84
|
-
if (sidebarOptions.groupPathsBy === "
|
|
85
|
-
sidebarSlice = groupByTags(api, sidebarOptions, options);
|
|
141
|
+
if (sidebarOptions.groupPathsBy === "tag") {
|
|
142
|
+
sidebarSlice = groupByTags(api, sidebarOptions, options, tags);
|
|
86
143
|
}
|
|
87
144
|
return sidebarSlice;
|
|
88
145
|
}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { InfoObject, OperationObject, SecuritySchemeObject } from "./openapi/types";
|
|
1
|
+
import type Request from "@paloaltonetworks/postman-collection";
|
|
2
|
+
import { InfoObject, OperationObject, SecuritySchemeObject, TagObject } from "./openapi/types";
|
|
3
3
|
export type { PropSidebarItemCategory, SidebarItemLink, PropSidebar, PropSidebarItem, } from "@docusaurus/plugin-content-docs-types";
|
|
4
4
|
export interface PluginOptions {
|
|
5
5
|
id?: string;
|
|
@@ -16,13 +16,15 @@ export interface APIOptions {
|
|
|
16
16
|
export interface LoadedContent {
|
|
17
17
|
loadedApi: ApiMetadata[];
|
|
18
18
|
}
|
|
19
|
-
export declare type ApiMetadata = ApiPageMetadata | InfoPageMetadata;
|
|
19
|
+
export declare type ApiMetadata = ApiPageMetadata | InfoPageMetadata | TagPageMetadata;
|
|
20
20
|
export interface ApiMetadataBase {
|
|
21
21
|
sidebar?: string;
|
|
22
22
|
previous?: ApiNavLink;
|
|
23
23
|
next?: ApiNavLink;
|
|
24
24
|
id: string;
|
|
25
25
|
unversionedId: string;
|
|
26
|
+
infoId?: string;
|
|
27
|
+
infoPath?: string;
|
|
26
28
|
title: string;
|
|
27
29
|
description: string;
|
|
28
30
|
source: string;
|
|
@@ -52,6 +54,14 @@ export interface InfoPageMetadata extends ApiMetadataBase {
|
|
|
52
54
|
type: "info";
|
|
53
55
|
info: ApiInfo;
|
|
54
56
|
markdown?: string;
|
|
57
|
+
securitySchemes?: {
|
|
58
|
+
[key: string]: SecuritySchemeObject;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface TagPageMetadata extends ApiMetadataBase {
|
|
62
|
+
type: "tag";
|
|
63
|
+
tag: TagObject;
|
|
64
|
+
markdown?: string;
|
|
55
65
|
}
|
|
56
66
|
export declare type ApiInfo = InfoObject;
|
|
57
67
|
export interface ApiNavLink {
|
|
@@ -60,6 +70,7 @@ export interface ApiNavLink {
|
|
|
60
70
|
}
|
|
61
71
|
export interface SidebarOptions {
|
|
62
72
|
groupPathsBy?: string;
|
|
73
|
+
categoryLinkSource?: string;
|
|
63
74
|
customProps?: {
|
|
64
75
|
[key: string]: unknown;
|
|
65
76
|
};
|
package/package.json
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-plugin-openapi-docs",
|
|
3
3
|
"description": "OpenAPI plugin for Docusaurus.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"openapi",
|
|
8
|
+
"documentation",
|
|
9
|
+
"docusaurus",
|
|
10
|
+
"websites",
|
|
11
|
+
"plugin"
|
|
12
|
+
],
|
|
6
13
|
"publishConfig": {
|
|
7
14
|
"access": "public"
|
|
8
15
|
},
|
|
9
16
|
"repository": {
|
|
10
17
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/PaloAltoNetworks/docusaurus-openapi.git",
|
|
18
|
+
"url": "https://github.com/PaloAltoNetworks/docusaurus-openapi-docs.git",
|
|
12
19
|
"directory": "packages/docusaurus-plugin-openapi-docs"
|
|
13
20
|
},
|
|
14
21
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/PaloAltoNetworks/docusaurus-openapi/issues"
|
|
22
|
+
"url": "https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues"
|
|
16
23
|
},
|
|
17
24
|
"main": "lib/index.js",
|
|
18
25
|
"types": "src/plugin-openapi.d.ts",
|
|
@@ -21,21 +28,21 @@
|
|
|
21
28
|
"watch": "tsc --watch"
|
|
22
29
|
},
|
|
23
30
|
"devDependencies": {
|
|
24
|
-
"@docusaurus/module-type-aliases": "
|
|
25
|
-
"@docusaurus/types": "
|
|
31
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.21",
|
|
32
|
+
"@docusaurus/types": "2.0.0-beta.21",
|
|
26
33
|
"@types/fs-extra": "^9.0.13",
|
|
27
34
|
"@types/json-schema": "^7.0.9",
|
|
28
35
|
"@types/lodash": "^4.14.176",
|
|
29
|
-
"@types/postman-collection": "^3.5.7",
|
|
30
36
|
"utility-types": "^3.10.0"
|
|
31
37
|
},
|
|
32
38
|
"dependencies": {
|
|
33
|
-
"@docusaurus/mdx-loader": "
|
|
34
|
-
"@docusaurus/plugin-content-docs": "
|
|
35
|
-
"@docusaurus/utils": "
|
|
36
|
-
"@docusaurus/utils-validation": "
|
|
39
|
+
"@docusaurus/mdx-loader": "2.0.0-beta.21",
|
|
40
|
+
"@docusaurus/plugin-content-docs": "2.0.0-beta.21",
|
|
41
|
+
"@docusaurus/utils": "2.0.0-beta.21",
|
|
42
|
+
"@docusaurus/utils-validation": "2.0.0-beta.21",
|
|
37
43
|
"@paloaltonetworks/openapi-to-postmanv2": "3.1.0-hotfix.1",
|
|
38
44
|
"@paloaltonetworks/postman-collection": "^4.1.0",
|
|
45
|
+
"@redocly/openapi-core": "^1.0.0-beta.100",
|
|
39
46
|
"@types/js-yaml": "^4.0.5",
|
|
40
47
|
"@types/mustache": "^4.1.2",
|
|
41
48
|
"chalk": "^4.1.2",
|
|
@@ -46,6 +53,7 @@
|
|
|
46
53
|
"json-schema-merge-allof": "^0.8.1",
|
|
47
54
|
"lodash": "^4.17.20",
|
|
48
55
|
"mustache": "^4.2.0",
|
|
56
|
+
"swagger2openapi": "^7.0.8",
|
|
49
57
|
"webpack": "^5.61.0"
|
|
50
58
|
},
|
|
51
59
|
"peerDependencies": {
|
|
@@ -54,5 +62,5 @@
|
|
|
54
62
|
"engines": {
|
|
55
63
|
"node": ">=14"
|
|
56
64
|
},
|
|
57
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "618a438ec42148f525fb92cb11d291ce50d2ad06"
|
|
58
66
|
}
|