docusaurus-plugin-openapi-docs 3.0.0-beta.5 → 3.0.0-beta.7

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/src/options.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  import { Joi } from "@docusaurus/utils-validation";
9
9
 
10
10
  const sidebarOptions = Joi.object({
11
- groupPathsBy: Joi.string().valid("tag"),
11
+ groupPathsBy: Joi.string().valid("tag", "tagGroup"),
12
12
  categoryLinkSource: Joi.string().valid("tag", "info", "auto"),
13
13
  customProps: Joi.object(),
14
14
  sidebarCollapsible: Joi.boolean(),
@@ -37,6 +37,7 @@ export const OptionsSchema = Joi.object({
37
37
  showExtensions: Joi.boolean(),
38
38
  sidebarOptions: sidebarOptions,
39
39
  markdownGenerators: markdownGenerators,
40
+ showSchemas: Joi.boolean(),
40
41
  version: Joi.string().when("versions", {
41
42
  is: Joi.exist(),
42
43
  then: Joi.required(),
@@ -7,6 +7,7 @@
7
7
 
8
8
  import path from "path";
9
9
 
10
+ import { ProcessedSidebarItem } from "@docusaurus/plugin-content-docs/lib/sidebars/types";
10
11
  import {
11
12
  ProcessedSidebar,
12
13
  SidebarItemCategory,
@@ -18,12 +19,13 @@ import clsx from "clsx";
18
19
  import { kebabCase } from "lodash";
19
20
  import uniq from "lodash/uniq";
20
21
 
21
- import { TagObject } from "../openapi/types";
22
+ import { TagGroupObject, TagObject } from "../openapi/types";
22
23
  import type {
23
24
  SidebarOptions,
24
25
  APIOptions,
25
26
  ApiPageMetadata,
26
27
  ApiMetadata,
28
+ SchemaPageMetadata,
27
29
  } from "../types";
28
30
 
29
31
  function isApiItem(item: ApiMetadata): item is ApiMetadata {
@@ -34,6 +36,10 @@ function isInfoItem(item: ApiMetadata): item is ApiMetadata {
34
36
  return item.type === "info";
35
37
  }
36
38
 
39
+ function isSchemaItem(item: ApiMetadata): item is ApiMetadata {
40
+ return item.type === "schema";
41
+ }
42
+
37
43
  function groupByTags(
38
44
  items: ApiPageMetadata[],
39
45
  sidebarOptions: SidebarOptions,
@@ -55,6 +61,7 @@ function groupByTags(
55
61
 
56
62
  const apiItems = items.filter(isApiItem);
57
63
  const infoItems = items.filter(isInfoItem);
64
+ const schemaItems = items.filter(isSchemaItem);
58
65
  const intros = infoItems.map((item: any) => {
59
66
  return {
60
67
  id: item.id,
@@ -80,28 +87,35 @@ function groupByTags(
80
87
  apiTags.push(tag.name!);
81
88
  }
82
89
  });
83
- apiTags = uniq(apiTags.concat(operationTags));
90
+ // apiTags = uniq(apiTags.concat(operationTags));
84
91
 
85
92
  const basePath = docPath
86
93
  ? outputDir.split(docPath!)[1].replace(/^\/+/g, "")
87
94
  : outputDir.slice(outputDir.indexOf("/", 1)).replace(/^\/+/g, "");
88
- function createDocItem(item: ApiPageMetadata): SidebarItemDoc {
95
+ function createDocItem(
96
+ item: ApiPageMetadata | SchemaPageMetadata
97
+ ): SidebarItemDoc {
89
98
  const sidebar_label = item.frontMatter.sidebar_label;
90
99
  const title = item.title;
91
- const id = item.id;
100
+ const id = item.type === "schema" ? `schemas/${item.id}` : item.id;
101
+ const className =
102
+ item.type === "api"
103
+ ? clsx(
104
+ {
105
+ "menu__list-item--deprecated": item.api.deprecated,
106
+ "api-method": !!item.api.method,
107
+ },
108
+ item.api.method
109
+ )
110
+ : clsx({
111
+ "menu__list-item--deprecated": item.schema.deprecated,
112
+ });
92
113
  return {
93
114
  type: "doc" as const,
94
- id:
95
- basePath === "" || undefined ? `${item.id}` : `${basePath}/${item.id}`,
115
+ id: basePath === "" || undefined ? `${id}` : `${basePath}/${id}`,
96
116
  label: (sidebar_label as string) ?? title ?? id,
97
117
  customProps: customProps,
98
- className: clsx(
99
- {
100
- "menu__list-item--deprecated": item.api.deprecated,
101
- "api-method": !!item.api.method,
102
- },
103
- item.api.method
104
- ),
118
+ className: className ? className : undefined,
105
119
  };
106
120
  }
107
121
 
@@ -201,13 +215,26 @@ function groupByTags(
201
215
  ];
202
216
  }
203
217
 
218
+ let schemas: SidebarItemCategory[] = [];
219
+ if (schemaItems.length > 0) {
220
+ schemas = [
221
+ {
222
+ type: "category" as const,
223
+ label: "Schemas",
224
+ collapsible: sidebarCollapsible!,
225
+ collapsed: sidebarCollapsed!,
226
+ items: schemaItems.map(createDocItem),
227
+ },
228
+ ];
229
+ }
230
+
204
231
  // Shift root intro doc to top of sidebar
205
232
  // TODO: Add input validation for categoryLinkSource options
206
233
  if (rootIntroDoc && categoryLinkSource !== "info") {
207
234
  tagged.unshift(rootIntroDoc as any);
208
235
  }
209
236
 
210
- return [...tagged, ...untagged];
237
+ return [...tagged, ...untagged, ...schemas];
211
238
  }
212
239
 
213
240
  export default function generateSidebarSlice(
@@ -215,11 +242,38 @@ export default function generateSidebarSlice(
215
242
  options: APIOptions,
216
243
  api: ApiMetadata[],
217
244
  tags: TagObject[][],
218
- docPath: string
245
+ docPath: string,
246
+ tagGroups?: TagGroupObject[]
219
247
  ) {
220
248
  let sidebarSlice: ProcessedSidebar = [];
221
249
 
222
- if (sidebarOptions.groupPathsBy === "tag") {
250
+ if (sidebarOptions.groupPathsBy === "tagGroup") {
251
+ tagGroups?.forEach((tagGroup) => {
252
+ //filter tags only included in group
253
+ const filteredTags: TagObject[] = [];
254
+ tags[0].forEach((tag) => {
255
+ if (tagGroup.tags.includes(tag.name as string)) {
256
+ filteredTags.push(tag);
257
+ }
258
+ });
259
+
260
+ const groupCategory = {
261
+ type: "category" as const,
262
+ label: tagGroup.name,
263
+ collapsible: true,
264
+ collapsed: true,
265
+ items: groupByTags(
266
+ api as ApiPageMetadata[],
267
+ sidebarOptions,
268
+ options,
269
+ [filteredTags],
270
+ docPath
271
+ ),
272
+ } as ProcessedSidebarItem;
273
+
274
+ sidebarSlice.push(groupCategory);
275
+ });
276
+ } else if (sidebarOptions.groupPathsBy === "tag") {
223
277
  sidebarSlice = groupByTags(
224
278
  api as ApiPageMetadata[],
225
279
  sidebarOptions,
package/src/types.ts CHANGED
@@ -10,6 +10,7 @@ import type Request from "@paloaltonetworks/postman-collection";
10
10
  import {
11
11
  InfoObject,
12
12
  OperationObject,
13
+ SchemaObject,
13
14
  SecuritySchemeObject,
14
15
  TagObject,
15
16
  } from "./openapi/types";
@@ -44,12 +45,14 @@ export interface APIOptions {
44
45
  };
45
46
  proxy?: string;
46
47
  markdownGenerators?: MarkdownGenerator;
48
+ showSchemas?: boolean;
47
49
  }
48
50
 
49
51
  export interface MarkdownGenerator {
50
52
  createApiPageMD?: (pageData: ApiPageMetadata) => string;
51
53
  createInfoPageMD?: (pageData: InfoPageMetadata) => string;
52
54
  createTagPageMD?: (pageData: TagPageMetadata) => string;
55
+ createSchemaPageMD?: (pageData: SchemaPageMetadata) => string;
53
56
  }
54
57
 
55
58
  export interface SidebarOptions {
@@ -72,7 +75,11 @@ export interface LoadedContent {
72
75
  // loadedDocs: DocPageMetadata[]; TODO: cleanup
73
76
  }
74
77
 
75
- export type ApiMetadata = ApiPageMetadata | InfoPageMetadata | TagPageMetadata;
78
+ export type ApiMetadata =
79
+ | ApiPageMetadata
80
+ | InfoPageMetadata
81
+ | TagPageMetadata
82
+ | SchemaPageMetadata;
76
83
 
77
84
  export interface ApiMetadataBase {
78
85
  sidebar?: string;
@@ -131,6 +138,19 @@ export interface TagPageMetadata extends ApiMetadataBase {
131
138
  markdown?: string;
132
139
  }
133
140
 
141
+ export interface SchemaPageMetadata extends ApiMetadataBase {
142
+ type: "schema";
143
+ schema: SchemaObject;
144
+ markdown?: string;
145
+ }
146
+
147
+ export interface TagGroupPageMetadata extends ApiMetadataBase {
148
+ type: "tagGroup";
149
+ name: string;
150
+ tags: TagObject[];
151
+ markdown?: string;
152
+ }
153
+
134
154
  export type ApiInfo = InfoObject;
135
155
 
136
156
  export interface ApiNavLink {