Skip to content

Commit 83cac31

Browse files
Add generateSchemas option
This works similar to showSchemas but it doesn't add the schemas to the sidebar. This is useful to generate the schemas and then embed them in other pages as needed.
1 parent 2bc5b31 commit 83cac31

File tree

6 files changed

+11
-1
lines changed

6 files changed

+11
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
174174
| `versions` | `object` | `null` | _Optional:_ Options for versioning configuration. See below for a list of supported options. |
175175
| `markdownGenerators` | `object` | `null` | _Optional:_ Customize MDX content via generator functions. See below for a list of supported options. |
176176
| `showSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates standalone schema pages and adds them to the sidebar. |
177+
| `generateSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates schema pages for all schemas referenced in the OpenAPI spec (not added in sidebar). |
177178

178179
### sidebarOptions
179180

demo/docs/intro.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
221221
| `versions` | `object` | `null` | _Optional:_ Options for versioning configuration. See below for a list of supported options. |
222222
| `markdownGenerators` | `object` | `null` | _Optional:_ Customize MDX content via generator functions. See below for a list of supported options. |
223223
| `showSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates standalone schema pages and adds them to the sidebar. |
224+
| `generateSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates schema pages for all schemas referenced in the OpenAPI spec (not added in sidebar). |
224225

225226
### sidebarOptions
226227

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ The `docusaurus-plugin-openapi-docs` plugin can be configured with the following
174174
| `versions` | `object` | `null` | _Optional:_ Options for versioning configuration. See below for a list of supported options. |
175175
| `markdownGenerators` | `object` | `null` | _Optional:_ Customize MDX content via generator functions. See below for a list of supported options. |
176176
| `showSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates standalone schema pages and adds them to the sidebar. |
177+
| `generateSchemas` | `boolean` | `null` | _Optional:_ If set to `true`, generates schema pages for all schemas referenced in the OpenAPI spec (not added in sidebar). |
177178

178179
### sidebarOptions
179180

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ function createItems(
423423

424424
if (
425425
options?.showSchemas === true ||
426+
options?.generateSchemas === true ||
426427
Object.entries(openapiData?.components?.schemas ?? {})
427428
.flatMap(([_, s]) => s["x-tags"])
428429
.filter((item) => !!item).length > 0
@@ -431,7 +432,11 @@ function createItems(
431432
for (let [schema, schemaObject] of Object.entries(
432433
openapiData?.components?.schemas ?? {}
433434
)) {
434-
if (options?.showSchemas === true || schemaObject["x-tags"]) {
435+
if (
436+
options?.showSchemas === true ||
437+
options?.generateSchemas === true ||
438+
schemaObject["x-tags"]
439+
) {
435440
const baseIdSpaces =
436441
schemaObject?.title?.replace(" ", "-").toLowerCase() ?? "";
437442
const baseId = kebabCase(baseIdSpaces);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const OptionsSchema = Joi.object({
4848
sidebarOptions: sidebarOptions,
4949
markdownGenerators: markdownGenerators,
5050
showSchemas: Joi.boolean(),
51+
generateSchemas: Joi.boolean(),
5152
disableCompression: Joi.boolean(),
5253
version: Joi.string().when("versions", {
5354
is: Joi.exist(),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface APIOptions {
5151
proxy?: string;
5252
markdownGenerators?: MarkdownGenerator;
5353
showSchemas?: boolean;
54+
generateSchemas?: boolean;
5455
disableCompression?: boolean;
5556
}
5657

0 commit comments

Comments
 (0)