Skip to content

Commit ee9790c

Browse files
committed
Move createDocItem() into a sidebarGenerators object
1 parent cf354d0 commit ee9790c

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
181181
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
182182
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
183183
| `customProps` | `object` | `null` | Additional props for customizing a sidebar item. |
184-
| `createDocItem` | `function` | `null` | Optional: Returns a `SidebarItemDoc` object, which allows for customisation of sidebar items. For example, add a class name in certain conditions, or add `customProps` to provide custom rendering. |
184+
| `sidebarGenerators` | `object` | `null` | Optional: Customize sidebar rendering with callback functions. |
185+
| `createDocItem` | `function` | `null` | Optional: Returns a `SidebarItemDoc` object, which allows for customisation of sidebar items. For example, add a class name in certain conditions, or add `customProps` to provide custom rendering. See below for a list of supported operations. |
185186

186187
> You may optionally configure a `sidebarOptions`. In doing so, an individual `sidebar.js` slice with the configured options will be generated within the respective `outputDir`.
187188
@@ -208,6 +209,14 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
208209
| `createTagPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for tag pages.<br/><br/>**Function type:** `(pageData: TagPageMetadata) => string` |
209210
| `createSchemaPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for schema pages.<br/><br/>**Function type:** `(pageData: SchemaPageMetadata) => string` |
210211

212+
### sidebarGenerators
213+
214+
`sidebarGenerators` can be configured with the following options:
215+
216+
| Name | Type | Default | Description |
217+
| --------------- | ---------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
218+
| `createDocItem` | `function` | `null` | Optional: Returns a `SidebarItemDoc` object containing metadata for a sidebar item.<br/><br/>**Function type** `(item: ApiPageMetadata | SchemaPageMetadata, context: { sidebarOptions: SidebarOptions; basePath: string }) => SidebarItemDoc` |
219+
211220
## CLI Usage
212221

213222
```bash

packages/docusaurus-plugin-openapi-docs/README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,15 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
174174

175175
`sidebarOptions` can be configured with the following options:
176176

177-
| Name | Type | Default | Description |
178-
| -------------------- | --------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
179-
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by `tag` and `tagGroup`. |
180-
| `categoryLinkSource` | `string` | `null` | Defines what source to use for rendering category link pages when grouping paths by tag. <br/><br/>The supported options are as follows: <br/><br/> `tag`: Sets the category link config type to `generated-index` and uses the tag description as the link config description. <br/><br/>`info`: Sets the category link config type to `doc` and renders the `info` section as the category link (recommended only for multi/micro-spec scenarios). <br/><br/>`none`: Does not create pages for categories, only groups that can be expanded/collapsed. |
181-
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
182-
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
183-
| `customProps` | `object` | `null` | Additional props for customizing a sidebar item. |
177+
| Name | Type | Default | Description |
178+
| -------------------- | ---------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
179+
| `groupPathsBy` | `string` | `null` | Organize and group sidebar slice by specified option. Note: Currently, `groupPathsBy` only contains support for grouping by `tag` and `tagGroup`. |
180+
| `categoryLinkSource` | `string` | `null` | Defines what source to use for rendering category link pages when grouping paths by tag. <br/><br/>The supported options are as follows: <br/><br/> `tag`: Sets the category link config type to `generated-index` and uses the tag description as the link config description. <br/><br/>`info`: Sets the category link config type to `doc` and renders the `info` section as the category link (recommended only for multi/micro-spec scenarios). <br/><br/>`none`: Does not create pages for categories, only groups that can be expanded/collapsed. |
181+
| `sidebarCollapsible` | `boolean` | `true` | Whether sidebar categories are collapsible by default. |
182+
| `sidebarCollapsed` | `boolean` | `true` | Whether sidebar categories are collapsed by default. |
183+
| `customProps` | `object` | `null` | Additional props for customizing a sidebar item. |
184+
| `sidebarGenerators` | `object` | `null` | Optional: Customize sidebar rendering with callback functions. |
185+
| `createDocItem` | `function` | `null` | Optional: Returns a `SidebarItemDoc` object, which allows for customisation of sidebar items. For example, add a class name in certain conditions, or add `customProps` to provide custom rendering. See below for a list of supported operations. |
184186

185187
> You may optionally configure a `sidebarOptions`. In doing so, an individual `sidebar.js` slice with the configured options will be generated within the respective `outputDir`.
186188
@@ -206,6 +208,14 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
206208
| `createTagPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for tag pages.<br/><br/>**Function type:** `(pageData: TagPageMetadata) => string` |
207209
| `createSchemaPageMD` | `function` | `null` | _Optional:_ Returns a string of the raw markdown body for schema pages.<br/><br/>**Function type:** `(pageData: SchemaPageMetadata) => string` |
208210

211+
### sidebarGenerators
212+
213+
`sidebarGenerators` can be configured with the following options:
214+
215+
| Name | Type | Default | Description |
216+
| --------------- | ---------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
217+
| `createDocItem` | `function` | `null` | Optional: Returns a `SidebarItemDoc` object containing metadata for a sidebar item.<br/><br/>**Function type** `(item: ApiPageMetadata | SchemaPageMetadata, context: { sidebarOptions: SidebarOptions; basePath: string }) => SidebarItemDoc` |
218+
209219
## CLI Usage
210220

211221
```bash

packages/docusaurus-plugin-openapi-docs/src/options.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
import { Joi } from "@docusaurus/utils-validation";
99

10+
const sidebarGenerators = Joi.object({
11+
createDocItem: Joi.function(),
12+
});
13+
1014
const sidebarOptions = Joi.object({
1115
groupPathsBy: Joi.string().valid("tag", "tagGroup"),
1216
categoryLinkSource: Joi.string().valid("tag", "info", "auto"),
1317
customProps: Joi.object(),
1418
sidebarCollapsible: Joi.boolean(),
1519
sidebarCollapsed: Joi.boolean(),
16-
createDocItem: Joi.function(),
20+
sidebarGenerators: sidebarGenerators,
1721
});
1822

1923
const markdownGenerators = Joi.object({

packages/docusaurus-plugin-openapi-docs/src/sidebars/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ function groupByTags(
133133
sidebarOptions,
134134
basePath,
135135
};
136-
const createDocItemFn = sidebarOptions.createDocItem ?? createDocItem;
136+
const createDocItemFn =
137+
sidebarOptions.sidebarGenerators?.createDocItem ?? createDocItem;
137138

138139
let rootIntroDoc = undefined;
139140
if (infoItems.length === 1) {

packages/docusaurus-plugin-openapi-docs/src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@ export type ApiDocItemGenerator = (
6363
context: { sidebarOptions: SidebarOptions; basePath: string }
6464
) => SidebarItemDoc;
6565

66+
export interface SidebarGenerators {
67+
createDocItem?: ApiDocItemGenerator;
68+
}
69+
6670
export interface SidebarOptions {
6771
groupPathsBy?: string;
6872
categoryLinkSource?: "info" | "tag" | "auto";
6973
customProps?: { [key: string]: unknown };
7074
sidebarCollapsible?: boolean;
7175
sidebarCollapsed?: boolean;
72-
createDocItem?: ApiDocItemGenerator;
76+
sidebarGenerators?: SidebarGenerators;
7377
}
7478

7579
export interface APIVersionOptions {

0 commit comments

Comments
 (0)