docusaurus-plugin-openapi-docs 2.1.2 → 2.2.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.
@@ -25,6 +25,7 @@ import type {
25
25
  APIOptions,
26
26
  ApiPageMetadata,
27
27
  ApiMetadata,
28
+ InfoPageMetadata,
28
29
  SchemaPageMetadata,
29
30
  } from "../types";
30
31
 
@@ -41,13 +42,13 @@ function isSchemaItem(item: ApiMetadata): item is ApiMetadata {
41
42
  }
42
43
 
43
44
  function groupByTags(
44
- items: ApiPageMetadata[],
45
+ items: ApiMetadata[],
45
46
  sidebarOptions: SidebarOptions,
46
47
  options: APIOptions,
47
48
  tags: TagObject[][],
48
49
  docPath: string
49
50
  ): ProcessedSidebar {
50
- let { outputDir, label } = options;
51
+ let { outputDir, label, showSchemas } = options;
51
52
 
52
53
  // Remove trailing slash before proceeding
53
54
  outputDir = outputDir.replace(/\/$/, "");
@@ -59,9 +60,9 @@ function groupByTags(
59
60
  categoryLinkSource,
60
61
  } = sidebarOptions;
61
62
 
62
- const apiItems = items.filter(isApiItem);
63
- const infoItems = items.filter(isInfoItem);
64
- const schemaItems = items.filter(isSchemaItem);
63
+ const apiItems = items.filter(isApiItem) as ApiPageMetadata[];
64
+ const infoItems = items.filter(isInfoItem) as InfoPageMetadata[];
65
+ const schemaItems = items.filter(isSchemaItem) as SchemaPageMetadata[];
65
66
  const intros = infoItems.map((item: any) => {
66
67
  return {
67
68
  id: item.id,
@@ -77,17 +78,25 @@ function groupByTags(
77
78
  .flatMap((item) => item.api.tags)
78
79
  .filter((item): item is string => !!item)
79
80
  );
81
+ const schemaTags = uniq(
82
+ schemaItems
83
+ .flatMap((item) => item.schema["x-tags"])
84
+ .filter((item): item is string => !!item)
85
+ );
80
86
 
81
- // Combine globally defined tags with operation tags
82
- // Only include global tag if referenced in operation tags
87
+ // Combine globally defined tags with operation and schema tags
88
+ // Only include global tag if referenced in operation/schema tags
83
89
  let apiTags: string[] = [];
84
90
  tags.flat().forEach((tag) => {
85
91
  // Should we also check x-displayName?
86
- if (operationTags.includes(tag.name!)) {
92
+ if (operationTags.includes(tag.name!) || schemaTags.includes(tag.name!)) {
87
93
  apiTags.push(tag.name!);
88
94
  }
89
95
  });
90
- apiTags = uniq(apiTags.concat(operationTags));
96
+
97
+ if (sidebarOptions.groupPathsBy !== "tagGroup") {
98
+ apiTags = uniq(apiTags.concat(operationTags, schemaTags));
99
+ }
91
100
 
92
101
  const basePath = docPath
93
102
  ? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
@@ -107,9 +116,12 @@ function groupByTags(
107
116
  },
108
117
  item.api.method
109
118
  )
110
- : clsx({
111
- "menu__list-item--deprecated": item.schema.deprecated,
112
- });
119
+ : clsx(
120
+ {
121
+ "menu__list-item--deprecated": item.schema.deprecated,
122
+ },
123
+ "schema"
124
+ );
113
125
  return {
114
126
  type: "doc" as const,
115
127
  id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
@@ -183,15 +195,20 @@ function groupByTags(
183
195
  } as SidebarItemCategoryLinkConfig;
184
196
  }
185
197
 
198
+ const taggedApiItems = apiItems.filter(
199
+ (item) => !!item.api.tags?.includes(tag)
200
+ );
201
+ const taggedSchemaItems = schemaItems.filter(
202
+ (item) => !!item.schema["x-tags"]?.includes(tag)
203
+ );
204
+
186
205
  return {
187
206
  type: "category" as const,
188
207
  label: tagObject?.["x-displayName"] ?? tag,
189
208
  link: linkConfig,
190
209
  collapsible: sidebarCollapsible,
191
210
  collapsed: sidebarCollapsed,
192
- items: apiItems
193
- .filter((item) => !!item.api.tags?.includes(tag))
194
- .map(createDocItem),
211
+ items: [...taggedSchemaItems, ...taggedApiItems].map(createDocItem),
195
212
  };
196
213
  })
197
214
  .filter((item) => item.items.length > 0); // Filter out any categories with no items.
@@ -216,14 +233,16 @@ function groupByTags(
216
233
  }
217
234
 
218
235
  let schemas: SidebarItemCategory[] = [];
219
- if (schemaItems.length > 0) {
236
+ if (showSchemas && schemaItems.length > 0) {
220
237
  schemas = [
221
238
  {
222
239
  type: "category" as const,
223
240
  label: "Schemas",
224
241
  collapsible: sidebarCollapsible!,
225
242
  collapsed: sidebarCollapsed!,
226
- items: schemaItems.map(createDocItem),
243
+ items: schemaItems
244
+ .filter(({ schema }) => !schema["x-tags"])
245
+ .map(createDocItem),
227
246
  },
228
247
  ];
229
248
  }
@@ -248,6 +267,7 @@ export default function generateSidebarSlice(
248
267
  let sidebarSlice: ProcessedSidebar = [];
249
268
 
250
269
  if (sidebarOptions.groupPathsBy === "tagGroup") {
270
+ let schemasGroup: ProcessedSidebar = [];
251
271
  tagGroups?.forEach((tagGroup) => {
252
272
  //filter tags only included in group
253
273
  const filteredTags: TagObject[] = [];
@@ -263,24 +283,32 @@ export default function generateSidebarSlice(
263
283
  collapsible: true,
264
284
  collapsed: true,
265
285
  items: groupByTags(
266
- api as ApiPageMetadata[],
286
+ api,
267
287
  sidebarOptions,
268
288
  options,
269
289
  [filteredTags],
270
290
  docPath
271
291
  ),
272
- } as ProcessedSidebarItem;
292
+ };
273
293
 
274
- sidebarSlice.push(groupCategory);
294
+ if (options.showSchemas) {
295
+ // For the first tagGroup, save the generated "Schemas" category for later.
296
+ if (schemasGroup.length === 0) {
297
+ schemasGroup = groupCategory.items?.filter(
298
+ (item) => item.type === "category" && item.label === "Schemas"
299
+ );
300
+ }
301
+ // Remove the "Schemas" category from every `groupCategory`.
302
+ groupCategory.items = groupCategory.items.filter((item) =>
303
+ "label" in item ? item.label !== "Schemas" : true
304
+ );
305
+ }
306
+ sidebarSlice.push(groupCategory as ProcessedSidebarItem);
275
307
  });
308
+ // Add `schemasGroup` to the end of the sidebar.
309
+ sidebarSlice.push(...schemasGroup);
276
310
  } else if (sidebarOptions.groupPathsBy === "tag") {
277
- sidebarSlice = groupByTags(
278
- api as ApiPageMetadata[],
279
- sidebarOptions,
280
- options,
281
- tags,
282
- docPath
283
- );
311
+ sidebarSlice = groupByTags(api, sidebarOptions, options, tags, docPath);
284
312
  }
285
313
 
286
314
  return sidebarSlice;
package/src/types.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import type Request from "@paloaltonetworks/postman-collection";
8
+ import type Request from "postman-collection";
9
9
 
10
10
  import {
11
11
  InfoObject,
@@ -23,6 +23,7 @@ export type {
23
23
  } from "@docusaurus/plugin-content-docs-types";
24
24
  export interface PluginOptions {
25
25
  id?: string;
26
+ docsPlugin?: string;
26
27
  docsPluginId: string;
27
28
  config: {
28
29
  [key: string]: APIOptions;
@@ -46,6 +47,7 @@ export interface APIOptions {
46
47
  proxy?: string;
47
48
  markdownGenerators?: MarkdownGenerator;
48
49
  showSchemas?: boolean;
50
+ disableCompression?: boolean;
49
51
  }
50
52
 
51
53
  export interface MarkdownGenerator {
@@ -68,6 +70,7 @@ export interface APIVersionOptions {
68
70
  outputDir: string;
69
71
  label: string;
70
72
  baseUrl: string;
73
+ downloadUrl?: string;
71
74
  }
72
75
 
73
76
  export interface LoadedContent {